1 | "use client";
|
2 |
|
3 | import { useIsDark } from "./useIsDark";
|
4 | import { fr, type ColorOptions, type ColorDecisions } from "./fr";
|
5 |
|
6 | export type ColorTheme = {
|
7 | isDark: boolean;
|
8 | options: ColorOptions<"css var">;
|
9 | decisions: ColorDecisions<"css var">;
|
10 | };
|
11 |
|
12 | /**
|
13 | * A hook is no longer required to get the colors, this will soon be deprecated
|
14 | * when the documentation is updated to reflect the new way of getting the colors.
|
15 | *
|
16 | * Before you would do:
|
17 | * ```ts
|
18 | * import { useColors } from "@codegouvfr/react-dsfr/useColors";
|
19 | * // ...
|
20 | * const theme = useColors();
|
21 | * // ...
|
22 | * theme.decisions.background.default.grey.default
|
23 | * ```
|
24 | * Now you should do:
|
25 | * ```ts
|
26 | * import { fr } from "@codegouvfr/react-dsfr";
|
27 | * // ...
|
28 | * fr.colors.decisions.background.default.grey.default
|
29 | * ```
|
30 | * We don't need a hook anymore as the the colors are expressed as CSS variables and thus don't need to be
|
31 | * switched at runtime when the user changes the dark mode.
|
32 | *
|
33 | * If however you need the colors in the HEX format you can do:
|
34 | *
|
35 | * ```ts
|
36 | * import { fr } from "@codegouvfr/react-dsfr";
|
37 | * import { useIsDark } from "@codegouvfr/react-dsfr/useIsDark";
|
38 | * // ...
|
39 | * const { isDark } = useIsDark();
|
40 | * const theme = fr.colors.getHex({ isDark });
|
41 | * // ...
|
42 | * theme.decisions.background.default.grey.default
|
43 | * ```
|
44 | **/
|
45 | export function useColors(): ColorTheme {
|
46 | const { isDark } = useIsDark();
|
47 |
|
48 | return {
|
49 | isDark,
|
50 | "options": fr.colors.options,
|
51 | "decisions": fr.colors.decisions
|
52 | };
|
53 | }
|