Skip to content

Commit 7651e36

Browse files
committed
Follow up on #134
1 parent a337f35 commit 7651e36

File tree

21 files changed

+823
-545
lines changed

21 files changed

+823
-545
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
"@emotion/react": "^11.10.4",
6868
"@emotion/styled": "^11.10.4",
6969
"@gouvfr/dsfr": "1.9.3",
70-
"@mui/icons-material": "^5.11.0",
71-
"@mui/material": "^5.11.0",
70+
"@mui/icons-material": "^5.11.16",
71+
"@mui/material": "^5.13.3",
7272
"@storybook/addon-a11y": "^6.5.16",
7373
"@storybook/addon-actions": "^6.5.13",
7474
"@storybook/addon-essentials": "^6.5.13",
@@ -97,7 +97,7 @@
9797
"husky": "^4.3.8",
9898
"lint-staged": "^11.0.0",
9999
"memoizee": "^0.4.15",
100-
"next": "13.3.0",
100+
"next": "13.4.4",
101101
"oppa": "^0.4.0",
102102
"parse-numeric-range": "^1.3.0",
103103
"powerhooks": "^0.22.0",
@@ -107,7 +107,7 @@
107107
"remixicon": "^3.2.0",
108108
"storybook-dark-mode": "^1.1.2",
109109
"ts-node": "^10.9.1",
110-
"tss-react": "^4.8.4",
110+
"tss-react": "^4.8.6",
111111
"type-route": "^1.0.1",
112112
"typescript": "^4.9.1-beta",
113113
"vitest": "^0.24.3"

src/assets/dsfr_plus_icons.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
@import url('../dsfr/utility/icons/icons.min.css');
3+
@import url('../dsfr/dsfr.min.css');

src/bin/only-include-used-icons.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,73 @@ async function main() {
336336
writeFile(filePath, rawIconCssCodeBuffer);
337337
});
338338
});
339+
340+
// Make sure icon css is imported before main css.
341+
// In the doc prior to first of june 2023, we instructed to import first the main css and then the icon css.
342+
// Since @gouvfr/dsfr@1.9.ish it has to be the opposite.
343+
// We auto correct the order here.
344+
reorder_css_imports: {
345+
const indexHtmlFilePath = (() => {
346+
let out = pathJoin(cwd, "public", "index.html");
347+
348+
if (fs.existsSync(out)) {
349+
return out;
350+
}
351+
352+
out = pathJoin(cwd, "index.html");
353+
354+
if (fs.existsSync(out)) {
355+
return out;
356+
}
357+
358+
return undefined;
359+
})();
360+
361+
if (indexHtmlFilePath === undefined) {
362+
break reorder_css_imports;
363+
}
364+
365+
const indexHtml = fs.readFileSync(indexHtmlFilePath).toString("utf8");
366+
367+
const lines = indexHtml.split("\n");
368+
369+
const importDsfrIndexLine = lines.findIndex(line =>
370+
/<link\s+rel="stylesheet"\s+href="(.*?%PUBLIC_URL%)?\/dsfr\/dsfr.min.css"\s*\/>/.test(
371+
line
372+
)
373+
);
374+
375+
if (importDsfrIndexLine === -1) {
376+
break reorder_css_imports;
377+
}
378+
379+
if (
380+
!/<link\s+rel="stylesheet"\s+href="(%PUBLIC_URL%)?\/dsfr\/utility\/icons\/icons\.min\.css"\s*\/>/.test(
381+
lines[importDsfrIndexLine + 1]
382+
)
383+
) {
384+
break reorder_css_imports;
385+
}
386+
387+
fs.writeFileSync(
388+
indexHtmlFilePath,
389+
Buffer.from(
390+
lines
391+
.map((line, i) => {
392+
switch (i) {
393+
case importDsfrIndexLine:
394+
return lines[importDsfrIndexLine + 1];
395+
case importDsfrIndexLine + 1:
396+
return lines[importDsfrIndexLine];
397+
default:
398+
return line;
399+
}
400+
})
401+
.join("\n"),
402+
"utf8"
403+
)
404+
);
405+
}
339406
}
340407

341408
if (require.main === module) {

src/next-appdir/DsfrHead.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import FaviconSvg from "../dsfr/favicon/favicon.svg";
77
import FaviconIco from "../dsfr/favicon/favicon.ico";
88
import { getScriptToRunAsap } from "../useIsDark/scriptToRunAsap";
99
import { fontUrlByFileBasename } from "./fontUrlByFileBasename";
10-
import "../dsfr/utility/icons/icons.css";
11-
import "../dsfr/dsfr.css";
10+
import "../assets/dsfr_plus_icons.css";
1211

1312
export type DsfrHeadProps = {
1413
defaultColorScheme: ColorScheme | "system";

src/next-pagesdir.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import { setLink } from "./link";
2222
import { setUseLang } from "./i18n";
2323
import Script from "next/script";
2424
import { assert } from "tsafe/assert";
25-
import "./dsfr/utility/icons/icons.css";
26-
import "./dsfr/dsfr.css";
2725
import { GdprStoreProvider } from "./gdpr/GdprStore";
26+
import "./assets/dsfr_plus_icons.css";
2827

2928
export type { RegisterLink, RegisteredLinkProps };
3029

stories/Header.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const HeaderWithQuickAccessItems = getStory({
129129
}
130130
},
131131
{
132-
"iconId": "fr-icon-account-line",
132+
"iconId": "ri-account-circle-line",
133133
"text": "S’enregistrer",
134134
"linkProps": {
135135
"href": "#"

test/integration/cra/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
<link rel="preload" href="%PUBLIC_URL%/dsfr/fonts/<%=name%>.woff2" as="font" crossorigin="anonymous" />
2828
<% }); %>
2929

30-
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/dsfr.min.css" />
3130
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/utility/icons/icons.min.css" />
31+
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/dsfr.min.css" />
3232

3333
<!--
3434
Notice the use of %PUBLIC_URL% in the tags above.

test/integration/cra/src/index.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,16 @@ function Root() {
5050
<Header
5151
brandTop={<>INTITULE<br />OFFICIEL</>}
5252
serviceTitle="Nom du site / service"
53-
quickAccessItems={[headerFooterDisplayItem,
53+
quickAccessItems={[
54+
headerFooterDisplayItem,
5455
{
55-
iconId: "ri-chat-3-line",
56-
linkProps: {
57-
href: "#",
58-
target: "_self",
59-
},
60-
text: "Soumettre mes retours",
61-
},
62-
{
6356
iconId: "ri-mail-line",
6457
linkProps: {
65-
href: `mailto:${"joseph.garrone@code.gouv.fr"}`,
58+
href: `mailto:${"joseph.garrone@code.gouv.fr"}`,
6659
},
6760
text: "Nous contacter",
68-
},
69-
]}
61+
}
62+
]}
7063
homeLinkProps={{ ...routes.home().link, "title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)" }}
7164
navigation={[
7265
{

test/integration/next-appdir/app/layout.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,16 @@ export default function RootLayout({ children }: { children: JSX.Element; }) {
6666
brandTop={brandTop}
6767
serviceTitle="Nom du site / service"
6868
homeLinkProps={homeLinkPops}
69-
quickAccessItems={[headerFooterDisplayItem]}
69+
quickAccessItems={[
70+
headerFooterDisplayItem,
71+
{
72+
iconId: "ri-mail-line",
73+
linkProps: {
74+
href: `mailto:${"joseph.garrone@code.gouv.fr"}`,
75+
},
76+
text: "Nous contacter",
77+
}
78+
]}
7079
navigation={<Navigation />}
7180
/>
7281
<div style={{

test/integration/next-appdir/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"@emotion/react": "11.10.5",
1616
"@emotion/server": "11.10.0",
1717
"@emotion/styled": "11.10.5",
18-
"@mui/icons-material": "^5.8.4",
19-
"@mui/material": "5.11.1",
20-
"next": "13.3.0",
18+
"@mui/icons-material": "^5.11.16",
19+
"@mui/material": "^5.13.3",
20+
"next": "13.4.4",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
23-
"tss-react": "^4.7.0",
23+
"tss-react": "^4.8.6",
2424
"tsafe": "^1.4.1",
2525
"@mui/x-date-pickers": "^5.0.12",
2626
"dayjs": "^1.11.7",

0 commit comments

Comments
 (0)