Skip to content

Commit f373d7f

Browse files
EvgenNoskovmrm007
andauthored
Allow hyphens inside css classes (#1254)
Co-authored-by: Remus Mate <[email protected]>
1 parent d2d1ddd commit f373d7f

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

.changeset/strong-ducks-dream.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
'@vanilla-extract/esbuild-plugin': patch
4+
'@vanilla-extract/next-plugin': patch
5+
'@vanilla-extract/rollup-plugin': patch
6+
'@vanilla-extract/vite-plugin': patch
7+
'@vanilla-extract/webpack-plugin': patch
8+
---
9+
10+
Allow hyphens in class names when using a custom identifier

packages/css/src/identifier.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ describe('identifier', () => {
9191
);
9292
});
9393

94+
it('should allow hyphens in a class name', () => {
95+
expect(generateIdentifier('a-b')).toMatchInlineSnapshot(
96+
`"abc_a-b_s0xkdr1_packagetest_file"`,
97+
);
98+
expect(generateIdentifier('a-b-c')).toMatchInlineSnapshot(
99+
`"abc_a-b-c_s0xkdr2_packagetest_file"`,
100+
);
101+
});
102+
94103
it('rejects invalid identifiers', () => {
95104
// getIdentOption() does not remove spaces from the debug info so the
96105
// resulting identifier should be invalid here.

packages/css/src/identifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function generateIdentifier(
7575
packageName,
7676
});
7777

78-
if (!identifier.match(/^[A-Z_][0-9A-Z_]+$/i)) {
78+
if (!identifier.match(/^[A-Z_][0-9A-Z_-]+$/i)) {
7979
throw new Error(
8080
`Identifier function returned invalid indentifier: "${identifier}"`,
8181
);

site/docs/integrations/webpack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc)
9494
- A custom identifier function takes an object parameter with properties `hash`, `filePath`, `debugId`, and `packageName`, and returns a customized identifier. e.g.
9595

9696
```ts
97-
VanillaExtractPlugin({
97+
new VanillaExtractPlugin({
9898
identifiers: ({ hash }) => `prefix_${hash}`
9999
});
100100
```

0 commit comments

Comments
 (0)