styled-components / styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
https://styled-components.com
MIT License
40.11k stars 2.48k forks source link

Custom property names are changed to kebab case #4250

Closed Tharon-C closed 4 months ago

Tharon-C commented 4 months ago

Environment

npx envinfo --system --binaries --npmPackages styled-components,babel-plugin-styled-components --markdown

System:

Proposal

Don't change valid custom property names.

this:

  ":root": {
    "--component-ComponentName-backroundColor": "gold"
   }

should render this:

:root {
   --conponent-ComponentName-backgroundColor: gold;
}

not this:

:root {
   --component-component-name-background-color: gold;
}

Use Case

Dynamically generating properties from a design token in storybook and using hyphens and underscores as a convention to communicate the scoping of the property. Can't use theme objects because of organizational constraints.

Workaround

Steps to reproduce

Set global styles using GlobalStyles

const variables = { 
 " :root": {
    "--component-ComponentName-backroundColor": "gold"
   }
}
const GlobalStyles = createGlobalStyle(variables);

Inspect variables in browser

Expected Behavior

Variables are rendered as:

:root {
   --conponent-ComponentName-backgroundColor: gold;
}

Actual Behavior

Variables are rendered as:

:root {
   --component-component-name-background-color: gold;
}