String interpolation inside tw macro doesn't work
See original GitHub issueHi!
I have a problem with string interpolation in tw macro. For example I need to customize border color, so I’m trying to do it like this:
export const PrimaryButton = styled(Button)`
${({ color }) => tw`hover:border-${color ?? 'blue'}`};
`;
But I get the following error:
✕ Class “hover:border-” shouldn’t have a trailing dash.
It also doesn’t work without variables:
export const PrimaryButton = styled(Button)`
${({ color }) => tw`hover:border-${'blue'}`};
`;
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:23 (11 by maintainers)
Top Results From Across the Web
Props, TailwindCSS & Twin.Macro - Stack Overflow
I am trying to get the following component to work properly with Twin.Macro: import ...
Read more >Expressions - Apache FreeMarker Manual
When you supply values for interpolations or directive parameters you can use variables or more complex expressions.
Read more >FAQs - styled-components
In general, always use the css helper when composing styling partials to be interpolated into a styled component.. import styled, { keyframes }...
Read more >Introduction into Macro Programming - ImageJ Wiki
Variables. The most important concept when starting to program macros are variables. A variable is a placeholder for a changing entity.
Read more >Bel Curcio on Twitter: "If I do string interpolation within ...
If I do string interpolation within classnames Tailwinds won't notice it. Any advice on how to force those styles to land the final...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Edit: Check out the discussion on this topic.
You could try a style map to reuse the styleMap object:
You could also separate the styles and import them from another file:
This is especially useful when using padding in the tailwind macro - eg:
gap
.I’m not sure whats the best workaround currently.