@@ -4,11 +4,21 @@ import type { ReactNode } from "react";
44import { breakpointValues , breakpointValuesUnit } from "./lib/generatedFromCss/breakpoints" ;
55import type { Theme as MuiTheme } from "@mui/material/styles" ;
66import { createTheme , ThemeProvider as MuiThemeProvider } from "@mui/material/styles" ;
7- import { getColorDecisions } from "./lib/generatedFromCss/getColorDecisions" ;
8- import { getColorOptions } from "./lib/generatedFromCss/getColorOptions" ;
7+ import { getColors } from "./lib/colors" ;
98import { useIsDark } from "./lib/darkMode" ;
109import { typography } from "./lib/generatedFromCss/typography" ;
1110import { spacingTokenByValue } from "./lib/generatedFromCss/spacing" ;
11+ import type { ColorTheme } from "./lib/colors" ;
12+ //import type { Components } from "@mui/material/styles";
13+
14+ /*
15+ type NonAugmentedBaseMuiTheme = NonNullable<MuiTheme["components"]> extends Components<infer BaseMuiTheme> ? BaseMuiTheme : undefined;
16+
17+
18+ export type NonAugmentedMuiTheme = NonAugmentedBaseMuiTheme & {
19+ components?: Components<NonAugmentedBaseMuiTheme>;
20+ };
21+ */
1222
1323function createMuiDsfrTheme ( params : { isDark : boolean } ) : MuiTheme {
1424 const { isDark } = params ;
@@ -22,18 +32,17 @@ function createMuiDsfrTheme(params: { isDark: boolean }): MuiTheme {
2232 "values" : breakpointValues
2333 } ,
2434 "palette" : ( ( ) => {
25- const colorOptions = getColorOptions ( { isDark } ) ;
26- const colorDecisions = getColorDecisions ( { colorOptions } ) ;
35+ const { decisions } = getColors ( isDark ) ;
2736
2837 return {
2938 "mode" : isDark ? "dark" : "light" ,
3039 "primary" : {
31- "main" : colorDecisions . background . actionHigh . blueFrance . default ,
32- "light" : colorDecisions . background . actionLow . blueFrance . default
40+ "main" : decisions . background . actionHigh . blueFrance . default ,
41+ "light" : decisions . background . actionLow . blueFrance . default
3342 } ,
3443 "secondary" : {
35- "main" : colorDecisions . background . actionHigh . redMarianne . default ,
36- "light" : colorDecisions . background . actionLow . redMarianne . default
44+ "main" : decisions . background . actionHigh . redMarianne . default ,
45+ "light" : decisions . background . actionLow . redMarianne . default
3746 }
3847 /*
3948 "primary": {
@@ -82,18 +91,36 @@ function createMuiDsfrTheme(params: { isDark: boolean }): MuiTheme {
8291 return muiTheme ;
8392}
8493
94+ export type NonAugmentedMuiTheme = MuiTheme ;
95+
8596export type MuiDsfrThemeProviderProps = {
8697 children : ReactNode ;
98+ /** If you have implemented theme augmentation */
99+ augmentMuiTheme ?: ( params : {
100+ nonAugmentedMuiTheme : NonAugmentedMuiTheme ;
101+ frColorTheme : ColorTheme ;
102+ } ) => MuiTheme ;
87103} ;
88104
89105export function MuiDsfrThemeProvider ( props : MuiDsfrThemeProviderProps ) {
90- const { children } = props ;
106+ const { children, augmentMuiTheme } = props ;
91107
92108 const { isDark } = useIsDark ( ) ;
93109
94- const muiTheme = useMemo ( ( ) => createMuiDsfrTheme ( { isDark } ) , [ isDark ] ) ;
110+ const augmentedMuiTheme = useMemo ( ( ) => {
111+ const muiTheme = createMuiDsfrTheme ( { isDark } ) ;
112+
113+ if ( augmentMuiTheme === undefined ) {
114+ return muiTheme ;
115+ }
116+
117+ return augmentMuiTheme ( {
118+ "frColorTheme" : getColors ( isDark ) ,
119+ "nonAugmentedMuiTheme" : muiTheme
120+ } ) ;
121+ } , [ isDark , augmentMuiTheme ] ) ;
95122
96- return < MuiThemeProvider theme = { muiTheme } > { children } </ MuiThemeProvider > ;
123+ return < MuiThemeProvider theme = { augmentedMuiTheme } > { children } </ MuiThemeProvider > ;
97124}
98125
99126/*
0 commit comments