-
Notifications
You must be signed in to change notification settings - Fork 56
/
Display.tsx
164 lines (150 loc) · 6.78 KB
/
Display.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React, { useId } from "react";
import { fr } from "../fr";
import { symToStr } from "tsafe/symToStr";
import { createComponentI18nApi } from "../i18n";
import ArtworkLightSvg from "../dsfr/artwork/light.svg";
import ArtworkDarkSvg from "../dsfr/artwork/dark.svg";
import ArtworkSystemSvg from "../dsfr/artwork/system.svg";
import { getAssetUrl } from "../tools/getAssetUrl";
import type { HeaderProps } from "../Header";
import type { FooterProps } from "../Footer";
import { createModal } from "../Modal";
const modal = createModal({
"isOpenedByDefault": false,
"id": "fr-theme-modal"
});
export const headerFooterDisplayItem: HeaderProps.QuickAccessItem.Button &
FooterProps.BottomItem.Button = {
"buttonProps": modal.buttonProps,
"iconId": "fr-icon-theme-fill",
"text": (() => {
function Text() {
const { t } = useTranslation();
return <>{t("display settings")}</>;
}
return <Text />;
})()
};
/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-display> */
export function Display() {
const { t } = useTranslation();
const { getInputId } = (function useClosure() {
const id = useId();
function getInputId(theme: "light" | "dark" | "system") {
return `${id}-${theme}`;
}
return { getInputId };
})();
return (
<modal.Component title={t("display settings")} size="small">
<div /*id="fr-display"*/ className="fr-display">
<div className={fr.cx("fr-form-group" as any)}>
<fieldset className={fr.cx("fr-fieldset")}>
<legend
className={fr.cx("fr-fieldset__legend", "fr-text--regular")}
//id="-legend"
>
{t("pick a theme")}
</legend>
<div className={fr.cx("fr-fieldset__content")}>
{(["light", "dark", "system"] as const).map(theme => (
<div
key={theme}
className={fr.cx("fr-radio-group", "fr-radio-rich")}
>
<input
value={theme}
type="radio"
id={getInputId(theme)}
name="fr-radios-theme"
/>
<label className="fr-label" htmlFor={getInputId(theme)}>
{t(`${theme} theme`)}
{theme === "system" && (
<span className={fr.cx("fr-hint-text")}>
{t("system theme hint")}
</span>
)}
</label>
<div className={fr.cx("fr-radio-rich__img")}>
<svg
xmlns="http://www.w3.org/2000/svg"
//className={fr.cx("fr-artwork")}
width="80px"
height="80px"
viewBox="0 0 80 80"
>
{(
[
"artwork-decorative",
"artwork-minor",
"artwork-major"
] as const
).map(label => (
<use
key={label}
className={fr.cx(`fr-${label}`)}
xlinkHref={`${getAssetUrl(
(() => {
switch (theme) {
case "dark":
return ArtworkDarkSvg;
case "light":
return ArtworkLightSvg;
case "system":
return ArtworkSystemSvg;
}
})()
)}#${label}`}
/>
))}
</svg>
</div>
</div>
))}
</div>
</fieldset>
</div>
</div>
</modal.Component>
);
}
Display.displayName = symToStr({ Display });
export default Display;
const { useTranslation, addDisplayTranslations } = createComponentI18nApi({
"componentName": symToStr({ Display }),
"frMessages": {
/* spell-checker: disable */
"display settings": "Paramètres d'affichage",
"close": "Fermer",
"pick a theme": `Choisissez un thème pour personnaliser l'apparence du site.`,
"light theme": `Thème clair`,
"dark theme": `Thème sombre`,
"system theme": `Système.`,
"system theme hint": `Utilise les paramètres système.`
/* spell-checker: enable */
}
});
addDisplayTranslations({
"lang": "en",
"messages": {
"display settings": "Display settings",
"close": "Close",
"pick a theme": `Pick a theme to customize the website's look.`,
"light theme": `Light theme`,
"dark theme": "Dark theme",
"system theme": `System.`,
"system theme hint": "Use system preference"
}
});
addDisplayTranslations({
"lang": "es",
"messages": {
/* spell-checker: disable */
"display settings": "Parámetro de visualización",
"close": "Cerrar",
"pick a theme": `Elija un tema para personalizar el aspecto del sitio.`
/* spell-checker: enable */
}
});
export { addDisplayTranslations };