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

Dynamic styles in styled() components #730

Open
jmoore34 opened this issue Nov 17, 2021 · 3 comments
Open

Dynamic styles in styled() components #730

jmoore34 opened this issue Nov 17, 2021 · 3 comments

Comments

@jmoore34
Copy link

Hi. This is more of a question. I wasn't quite able to tell from the docs; is it possible to do something like the following:

const Text = styled("span")<{color: string}>`
   color: ${props => props.color};
`

Thanks

@dpashkevich
Copy link

Don't believe that's possible. The main way astroturf is different from the Styled Components library is that it has zero runtime, which means all the styles are generated at the build step and not dynamically injected in the DOM during the execution.

@jquense
Copy link
Contributor

jquense commented Nov 29, 2021

yeah it's not possible right now. It could actually be possible, if we compile the values to css custom properties (like with the css props) but honestly i'm not inclined to make the styled API more robust, i tend to think that it's an inferior API compared to defining your own components with a css prop.

@dpashkevich
Copy link

Good callout @jquense, you can get dynamic styles natively if you use CSS Custom properties, e.g.

const Text = styled("span")`
   color: var(--color-text);
`

That's one appropriate way to do theming in your app, for instance.

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

3 participants