Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing the theme #293

Closed
rsaccon opened this issue Aug 2, 2017 · 2 comments
Closed

accessing the theme #293

rsaccon opened this issue Aug 2, 2017 · 2 comments

Comments

@rsaccon
Copy link

rsaccon commented Aug 2, 2017

Just getting started with rebass. How can I access the theme from anywhere ? Does rebass provide any helper for that ?

my use case: I am extending a component:

const Item = styled(Container)`
    &:hover {
      background-color: #eee;
      cursor: pointer;
    }
  `;

so I would like to use a color key from the theme instead of hardwiring the color as I did above

@jxnblk
Copy link
Member

jxnblk commented Aug 2, 2017

The Rebass.Provider component is a wrapper around styled-components' ThemeProvider (https://www.styled-components.com/docs/advanced#theming). If you're using the theme provider, you should be able to access the theme from props, e.g. props.theme.colors.blue.

To use the theme outside of a React app, you can also manually import the theme import { theme } from 'rebass'

@rsaccon
Copy link
Author

rsaccon commented Aug 2, 2017

Thanks, found the styled-components withTheme helper, which does what I was looking for. Works great now.

@rsaccon rsaccon closed this as completed Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants