Skip to content

Commit 610b9d5

Browse files
committed
Move on with the translation to the MUI theme
1 parent 999918f commit 610b9d5

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

src/lib/mui.tsx

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
import React, { useMemo } from "react";
22
import type { ReactNode } from "react";
3-
4-
//import { createTheme as createMuiTheme } from "@mui/material/styles";
3+
import { breakpointValues, breakpointValuesUnit } from "./generatedFromCss/breakpoints";
4+
import { createTheme as createMuiTheme } from "@mui/material/styles";
55
import type { Theme as MuiTheme } from "@mui/material/styles";
6-
import { Theme } from "./useTheme";
76
import { ThemeProvider as MuiThemeProvider } from "@mui/material/styles";
87
import { useTheme } from "./useTheme";
8+
import type { PaletteOptions as MuiPaletteOptions } from "@mui/material/styles/createPalette";
9+
import { getColorDecisions } from "./generatedFromCss/getColorDecisions";
10+
import { getColorOptions } from "./generatedFromCss/getColorOptions";
11+
import { useIsDark } from "./useColorScheme";
12+
13+
function createMuiDsfrThemeFromTheme(params: { isDark: boolean }): MuiTheme {
14+
const { isDark } = params;
915

10-
function createMuiDsfrThemeFromTheme(params: { theme: Theme }): MuiTheme {
11-
const { theme } = params;
16+
const palette = useMemo(() => createMuiPaletteOptions({ isDark }), [isDark]);
17+
18+
const muiTheme = createMuiTheme({
19+
"shape": {
20+
"borderRadius": 0
21+
},
22+
"breakpoints": {
23+
"unit": breakpointValuesUnit,
24+
"values": breakpointValues
25+
},
26+
palette
27+
});
1228

1329
/*
1430
const muiTheme = createMuiTheme({
@@ -44,7 +60,36 @@ function createMuiDsfrThemeFromTheme(params: { theme: Theme }): MuiTheme {
4460
});
4561
*/
4662

47-
return theme as any;
63+
return muiTheme;
64+
}
65+
66+
function createMuiPaletteOptions(params: { isDark: boolean }): MuiPaletteOptions {
67+
const { isDark } = params;
68+
69+
const colorOptions = getColorOptions({ isDark });
70+
const colorDecisions = getColorDecisions({ colorOptions });
71+
72+
return {
73+
"mode": isDark ? "dark" : "light",
74+
"primary": {
75+
"main": colorDecisions.background.actionHigh.blueFrance.default,
76+
"light": colorDecisions.background.actionLow.blueFrance.default
77+
},
78+
"secondary": {
79+
"main": colorDecisions.background.actionHigh.redMarianne.default,
80+
"light": colorDecisions.background.actionLow.redMarianne.default
81+
}
82+
/*
83+
"primary": {
84+
"900": colorOptions.blueFrance._925_125.default,
85+
"800": colorOptions.blueFrance._850_200.default,
86+
},
87+
"secondary": {
88+
"main": colorDecisions.background.actionHigh.redMarianne.default,
89+
"light": colorDecisions.background.actionLow.redMarianne.default,
90+
},
91+
*/
92+
} as const;
4893
}
4994

5095
export type MuiDsfrThemeProviderProps = {
@@ -56,7 +101,9 @@ export function MuiDsfrThemeProvider(props: MuiDsfrThemeProviderProps) {
56101

57102
const theme = useTheme();
58103

59-
const muiTheme = useMemo(() => createMuiDsfrThemeFromTheme({ theme }), [theme]);
104+
const { isDark } = useIsDark();
105+
106+
const muiTheme = useMemo(() => createMuiDsfrThemeFromTheme({ isDark }), [theme]);
60107

61108
return <MuiThemeProvider theme={muiTheme}>{children}</MuiThemeProvider>;
62109
}

0 commit comments

Comments
 (0)