Skip to content

Commit 962d64f

Browse files
authored
Allow camel-case CSS var names instead of converting to snake-case (#168)
1 parent 156e585 commit 962d64f

File tree

5 files changed

+62
-61
lines changed

5 files changed

+62
-61
lines changed

.changeset/wet-eggs-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
---
4+
5+
Allow camel-case CSS var names instead of converting to snake-case

fixtures/themed/src/styles.css.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ export const button = [
7474
shadow,
7575
];
7676

77-
const undefinedVar1 = createVar();
78-
const undefinedVar2 = createVar();
77+
const blankVar1 = createVar();
78+
const blankVar2 = createVar();
7979

8080
export const opacity = styleVariants(
8181
{
82-
'1/2': fallbackVar(undefinedVar1, '0.5'),
83-
'1/4': fallbackVar(undefinedVar1, undefinedVar2, '0.25'),
82+
'1/2': fallbackVar(blankVar1, '0.5'),
83+
'1/4': fallbackVar(blankVar1, blankVar2, '0.25'),
8484
},
8585
(value) => ({
8686
selectors: { 'html &': { opacity: value } },

packages/css/src/vars.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ export function createVar(debugId?: string): CSSVarFunction {
2323
? `${debugId}__${fileScopeHash}${refCount}`
2424
: `${fileScopeHash}${refCount}`;
2525

26-
// Dashify CSS var names to replicate postcss-js behaviour
27-
// See https://github.com/postcss/postcss-js/blob/d5127d4278c133f333f1c66f990f3552a907128e/parser.js#L30
2826
const cssVarName = cssesc(varName.match(/^[0-9]/) ? `_${varName}` : varName, {
2927
isIdentifier: true,
30-
})
31-
.replace(/([A-Z])/g, '-$1')
32-
.toLowerCase();
28+
});
3329

3430
return `var(--${cssVarName})` as const;
3531
}

0 commit comments

Comments
 (0)