Skip to content

Commit ff65940

Browse files
committed
Add missing files
1 parent aaad2ed commit ff65940

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ This module is a wrapper/compatibility layer for [@gouvfr/dsfr](https://github.c
4040
- [x] Always in up to date with latest the DSFR evolutions.
4141
Code and Types generated from [`@gouvfr/dsfr`](https://www.npmjs.com/package/@gouvfr/dsfr)`/dist/dsfr.css`.
4242
- [x] Exactly the same look and feel than with [@gouvfr/dsfr](https://www.npmjs.com/package/@gouvfr/dsfr).
43-
- [x] No [white flash when reloading in SSR setup](https://github.com/codegouvfr/@codegouvfr/react-dsfr/issues/2#issuecomment-1257263480).
44-
- [x] Most components are server component ready. The others are labeled with `"use client";`
43+
- [x] No [white flash when reloading in SSR setup](https://github.com/codegouvfr/@codegouvfr/react-dsfr/issues/2#issuecomment-1257263480).
44+
- [x] Most components are server component ready. The others are labeled with `"use client";`
4545
- [x] [Perfect integration with all major React framework: Next.js (PagesDir and AppDir), Create React App, Vue](https://react-dsfr.etalab.studio/).
4646
- [ ] All [the components](https://www.systeme-de-design.gouv.fr/elements-d-interface) are implemented (14/42, [see details](COMPONENTS.md))
4747
- [x] Three shakable distribution, cherry pick the components you import. (It's not all in a big .js bundle)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import marianneLightWoff2Url from "../dsfr/fonts/Marianne-Light.woff2";
2+
import marianneItalicWoff2Url from "../dsfr/fonts/Marianne-Light_Italic.woff2";
3+
import marianneRegularWoff2Url from "../dsfr/fonts/Marianne-Regular.woff2";
4+
import marianneRegularItalicWoff2Url from "../dsfr/fonts/Marianne-Regular_Italic.woff2";
5+
import marianneMediumWoff2Url from "../dsfr/fonts/Marianne-Medium.woff2";
6+
import marianneMediumItalicWoff2Url from "../dsfr/fonts/Marianne-Medium_Italic.woff2";
7+
import marianneBoldWoff2Url from "../dsfr/fonts/Marianne-Bold.woff2";
8+
import marianneBoldItalicWoff2Url from "../dsfr/fonts/Marianne-Bold_Italic.woff2";
9+
import spectralRegularWoff2Url from "../dsfr/fonts/Spectral-Regular.woff2";
10+
import spectralExtraBoldWoff2Url from "../dsfr/fonts/Spectral-ExtraBold.woff2";
11+
12+
export const fontUrlByFileBasename = {
13+
"Marianne-Light": marianneLightWoff2Url,
14+
"Marianne-Light_Italic": marianneItalicWoff2Url,
15+
"Marianne-Regular": marianneRegularWoff2Url,
16+
"Marianne-Regular_Italic": marianneRegularItalicWoff2Url,
17+
"Marianne-Medium": marianneMediumWoff2Url,
18+
"Marianne-Medium_Italic": marianneMediumItalicWoff2Url,
19+
"Marianne-Bold": marianneBoldWoff2Url,
20+
"Marianne-Bold_Italic": marianneBoldItalicWoff2Url,
21+
"Spectral-Regular": spectralRegularWoff2Url,
22+
"Spectral-ExtraBold": spectralExtraBoldWoff2Url
23+
} as const;

src/useIsDark/scriptToRunAsap.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import type { ColorScheme } from "./client";
2+
import { data_fr_scheme, data_fr_theme, rootColorSchemeStyleTagId } from "./constants";
3+
import { getColors } from "../fr/colors";
4+
5+
export const getScriptToRunAsap = (defaultColorScheme: ColorScheme | "system") => `
6+
{
7+
8+
window.ssrWasPerformedWithIsDark = "${defaultColorScheme}" === "dark";
9+
10+
const isDark = (() => {
11+
12+
const isDarkExplicitlyProvidedAsParameter = (() => {
13+
if ("${defaultColorScheme}" === "system") {
14+
return undefined;
15+
}
16+
17+
switch ("${defaultColorScheme}") {
18+
case "dark": return true;
19+
case "light": return false;
20+
}
21+
})();
22+
23+
const isDarkFromLocalStorage = (() => {
24+
const colorSchemeReadFromLocalStorage = localStorage.getItem("scheme");
25+
26+
if (colorSchemeReadFromLocalStorage === null) {
27+
return undefined;
28+
}
29+
30+
if (colorSchemeReadFromLocalStorage === "system") {
31+
return undefined;
32+
}
33+
34+
switch (colorSchemeReadFromLocalStorage) {
35+
case "dark":
36+
return true;
37+
case "light":
38+
return false;
39+
}
40+
})();
41+
42+
const isDarkFromOsPreference = (() => {
43+
if (!window.matchMedia) {
44+
return undefined;
45+
}
46+
47+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
48+
})();
49+
50+
const isDarkFallback = false;
51+
52+
return (
53+
isDarkFromLocalStorage ??
54+
isDarkExplicitlyProvidedAsParameter ??
55+
isDarkFromOsPreference ??
56+
isDarkFallback
57+
);
58+
59+
})();
60+
61+
["${data_fr_scheme}", "${data_fr_theme}"].forEach(attr => document.documentElement.setAttribute(attr, isDark ? "dark" : "light"));
62+
63+
{
64+
65+
const element = document.createElement("style");
66+
67+
element.id = "${rootColorSchemeStyleTagId}";
68+
69+
element.innerHTML = \`:root { color-scheme: \${isDark ? "dark" : "light"}; }\`;
70+
71+
document.head.appendChild(element);
72+
73+
}
74+
75+
{
76+
77+
const element = document.createElement("meta");
78+
79+
element.name = "theme-color";
80+
81+
element.content = isDark ? "${
82+
getColors(true).decisions.background.default.grey.default
83+
}" : "${getColors(false).decisions.background.default.grey.default}";
84+
85+
document.head.appendChild(element);
86+
87+
}
88+
89+
}
90+
`;

0 commit comments

Comments
 (0)