Interpolation into template literals #393
Unanswered
ben-rogerson
asked this question in
Q&A
Replies: 2 comments 8 replies
-
export const StyledActionButton = styled(Button)<{ active: boolean }>`
${tw`text-left md:text-center`}
${tw`px-3 py-2 rounded-md text-sm font-medium`}
${({active}) => (active ? 'bg-gray-900 text-white' : 'bg-gray-300 hover:bg-gray-700 hover:text-white')}
` |
Beta Was this translation helpful? Give feedback.
6 replies
-
Hey @ben-rogerson , I want to pass the entire classname as props to a common component. I am planning to make the child component as a reusable component and dynamically pass tailwind classes as props from the parent component so that I do not have to touch the reusable component and just handle everything from the parent itself. Something just like this: Is there any way I can get it done? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Due to Babel limitations, tailwind classes and short css values can’t have any part of them dynamically created.
This is because babel doesn’t know the values of the variables and so twin can’t make a conversion to css.
So interpolated values like this won’t work:
Here are some examples to use as workarounds to the issue:
Prop styling
Define the classes in objects and grab them using props:
Or combine vanilla css with twins
theme
import:Or we can always fall back to vanilla css, which can interpolate anything:
Styled components
Define the classes in objects and grab them using props:
Or combine vanilla css with twins
theme
import:Or you can always fall back to “vanilla css” which can interpolate anything:
Beta Was this translation helpful? Give feedback.
All reactions