Skip to content

Commit

Permalink
Merge pull request #242 from codegouvfr/fix/css-classnames-parsing
Browse files Browse the repository at this point in the history
#226 edited regex to handle CSS selectors containing @ char
  • Loading branch information
garronej committed Mar 7, 2024
2 parents 50e0e0d + fe8541d commit a555ddd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions scripts/build/cssToTs/classNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ export const parseClassNames = memoize((rawCssCode: string): string[] => {

objectKeys(rulesByBreakpoint).forEach(breakpoint => {
const rules = rulesByBreakpoint[breakpoint];

rules.forEach(({ selectors }) => {
selectors.forEach(selector => {
const matchArr = selector.match(/\.fr-[a-zA-Z0-9_-]+/g);

const matchArr = selector.match(/\.fr-[a-zA-Z0-9_-]+(?:@[a-zA-Z0-9_-]+)?/g);
if (matchArr === null) {
return;
}
Expand All @@ -24,7 +22,6 @@ export const parseClassNames = memoize((rawCssCode: string): string[] => {
});
});
});

return Array.from(classNames);
});

Expand Down
2 changes: 1 addition & 1 deletion src/mui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export function createMuiDsfrTheme(
...args: object[]
): MuiTheme {
const muiTheme = createTheme(getMuiDsfrThemeOptions(params), ...args);

return muiTheme;
}

Expand Down
8 changes: 7 additions & 1 deletion test/runtime/scripts/classNames/parseClassNames.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint no-useless-escape: 0 */
import { it, expect } from "vitest";
import { parseClassNames } from "../../../../scripts/build/cssToTs/classNames";

Expand All @@ -24,6 +25,11 @@ it("Parsing of fr classnames", () => {
color: #3a3a3a;
}
.fr-tile--vertical\@md {
display: flex;
flex-direction: column;
}
@supports (aspect-ratio: 16/9) {
.fr-ratio-32x9 {
aspect-ratio: 3.5555555556 !important;
Expand All @@ -34,7 +40,6 @@ it("Parsing of fr classnames", () => {
}
}
@media (min-width: 36em) { }
@media (min-width: 48em) { }
@media (min-width: 62em) { }
Expand All @@ -50,6 +55,7 @@ it("Parsing of fr classnames", () => {
"fr-col",
"fr-header__navbar",
"fr-btn--menu",
"fr-tile--vertical@md",
"fr-ratio-32x9",
"fr-ratio-16x9"
];
Expand Down

0 comments on commit a555ddd

Please sign in to comment.