Skip to content

Commit

Permalink
Allow hyphens inside css classes (#1254)
Browse files Browse the repository at this point in the history
Co-authored-by: Remus Mate <3297808+mrm007@users.noreply.github.com>
  • Loading branch information
EvgenNoskov and mrm007 committed Jan 27, 2024
1 parent d2d1ddd commit f373d7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .changeset/strong-ducks-dream.md
@@ -0,0 +1,10 @@
---
'@vanilla-extract/css': patch
'@vanilla-extract/esbuild-plugin': patch
'@vanilla-extract/next-plugin': patch
'@vanilla-extract/rollup-plugin': patch
'@vanilla-extract/vite-plugin': patch
'@vanilla-extract/webpack-plugin': patch
---

Allow hyphens in class names when using a custom identifier
9 changes: 9 additions & 0 deletions packages/css/src/identifier.test.ts
Expand Up @@ -91,6 +91,15 @@ describe('identifier', () => {
);
});

it('should allow hyphens in a class name', () => {
expect(generateIdentifier('a-b')).toMatchInlineSnapshot(
`"abc_a-b_s0xkdr1_packagetest_file"`,
);
expect(generateIdentifier('a-b-c')).toMatchInlineSnapshot(
`"abc_a-b-c_s0xkdr2_packagetest_file"`,
);
});

it('rejects invalid identifiers', () => {
// getIdentOption() does not remove spaces from the debug info so the
// resulting identifier should be invalid here.
Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/identifier.ts
Expand Up @@ -75,7 +75,7 @@ export function generateIdentifier(
packageName,
});

if (!identifier.match(/^[A-Z_][0-9A-Z_]+$/i)) {
if (!identifier.match(/^[A-Z_][0-9A-Z_-]+$/i)) {
throw new Error(
`Identifier function returned invalid indentifier: "${identifier}"`,
);
Expand Down
2 changes: 1 addition & 1 deletion site/docs/integrations/webpack.md
Expand Up @@ -94,7 +94,7 @@ Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc)
- A custom identifier function takes an object parameter with properties `hash`, `filePath`, `debugId`, and `packageName`, and returns a customized identifier. e.g.

```ts
VanillaExtractPlugin({
new VanillaExtractPlugin({
identifiers: ({ hash }) => `prefix_${hash}`
});
```
Expand Down

0 comments on commit f373d7f

Please sign in to comment.