Skip to content

Commit a555ddd

Browse files
authored
Merge pull request #242 from codegouvfr/fix/css-classnames-parsing
#226 edited regex to handle CSS selectors containing @ char
2 parents 50e0e0d + fe8541d commit a555ddd

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

scripts/build/cssToTs/classNames.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ export const parseClassNames = memoize((rawCssCode: string): string[] => {
99

1010
objectKeys(rulesByBreakpoint).forEach(breakpoint => {
1111
const rules = rulesByBreakpoint[breakpoint];
12-
1312
rules.forEach(({ selectors }) => {
1413
selectors.forEach(selector => {
15-
const matchArr = selector.match(/\.fr-[a-zA-Z0-9_-]+/g);
16-
14+
const matchArr = selector.match(/\.fr-[a-zA-Z0-9_-]+(?:@[a-zA-Z0-9_-]+)?/g);
1715
if (matchArr === null) {
1816
return;
1917
}
@@ -24,7 +22,6 @@ export const parseClassNames = memoize((rawCssCode: string): string[] => {
2422
});
2523
});
2624
});
27-
2825
return Array.from(classNames);
2926
});
3027

src/mui.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export function createMuiDsfrTheme(
338338
...args: object[]
339339
): MuiTheme {
340340
const muiTheme = createTheme(getMuiDsfrThemeOptions(params), ...args);
341-
341+
342342
return muiTheme;
343343
}
344344

test/runtime/scripts/classNames/parseClassNames.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint no-useless-escape: 0 */
12
import { it, expect } from "vitest";
23
import { parseClassNames } from "../../../../scripts/build/cssToTs/classNames";
34

@@ -24,6 +25,11 @@ it("Parsing of fr classnames", () => {
2425
color: #3a3a3a;
2526
}
2627
28+
.fr-tile--vertical\@md {
29+
display: flex;
30+
flex-direction: column;
31+
}
32+
2733
@supports (aspect-ratio: 16/9) {
2834
.fr-ratio-32x9 {
2935
aspect-ratio: 3.5555555556 !important;
@@ -34,7 +40,6 @@ it("Parsing of fr classnames", () => {
3440
}
3541
}
3642
37-
3843
@media (min-width: 36em) { }
3944
@media (min-width: 48em) { }
4045
@media (min-width: 62em) { }
@@ -50,6 +55,7 @@ it("Parsing of fr classnames", () => {
5055
"fr-col",
5156
"fr-header__navbar",
5257
"fr-btn--menu",
58+
"fr-tile--vertical@md",
5359
"fr-ratio-32x9",
5460
"fr-ratio-16x9"
5561
];

0 commit comments

Comments
 (0)