1
1
import React , { useMemo } from "react" ;
2
2
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" ;
5
5
import type { Theme as MuiTheme } from "@mui/material/styles" ;
6
- import { Theme } from "./useTheme" ;
7
6
import { ThemeProvider as MuiThemeProvider } from "@mui/material/styles" ;
8
7
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 ;
9
15
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
+ } ) ;
12
28
13
29
/*
14
30
const muiTheme = createMuiTheme({
@@ -44,7 +60,36 @@ function createMuiDsfrThemeFromTheme(params: { theme: Theme }): MuiTheme {
44
60
});
45
61
*/
46
62
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 ;
48
93
}
49
94
50
95
export type MuiDsfrThemeProviderProps = {
@@ -56,7 +101,9 @@ export function MuiDsfrThemeProvider(props: MuiDsfrThemeProviderProps) {
56
101
57
102
const theme = useTheme ( ) ;
58
103
59
- const muiTheme = useMemo ( ( ) => createMuiDsfrThemeFromTheme ( { theme } ) , [ theme ] ) ;
104
+ const { isDark } = useIsDark ( ) ;
105
+
106
+ const muiTheme = useMemo ( ( ) => createMuiDsfrThemeFromTheme ( { isDark } ) , [ theme ] ) ;
60
107
61
108
return < MuiThemeProvider theme = { muiTheme } > { children } </ MuiThemeProvider > ;
62
109
}
0 commit comments