typescript-styled-plugin icon indicating copy to clipboard operation
typescript-styled-plugin copied to clipboard

Support for CSS variable declarations with dynamic property names and values

Open jantimon opened this issue 1 year ago • 1 comments

When using CSS custom properties (CSS variables) with styled-components, there are cases where we need both the property name and value to be dynamic expressions. Currently, the plugin throws a syntax error for this use case.

Works:

const StyledComponent = styled.div`
  ${prop}: red;           // Dynamic property name works
  color: ${value};        // Dynamic value works
  ${varName}: blue;     // Dynamic CSS variable name works
  color: var(--${name});  // Dynamic CSS variable reference works
`

Fails with } expected error:

const StyledComponent = styled.div`
  ${varName}: ${value};  // Error when both property name and value are dynamic
`

Could you please add support for cases where both the property name and value are template expressions?

I can submit a PR with the implementation if this helps

jantimon avatar Oct 30 '24 10:10 jantimon

I'd love to see a PR with implementation for this, I get this error a lot in my code.

nightpool avatar Nov 05 '25 15:11 nightpool