All files / src/theme/v2 Provider.tsx

78.57% Statements 11/14
71.42% Branches 5/7
50% Functions 3/6
78.57% Lines 11/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                547x           547x                         3740x   3740x 2802x                     3740x   3740x                 547x 365850x   365835x     547x  
import { PaletteMode, ThemeProvider, styled as styledd } from "@mui/material";
import React, { ReactNode, useMemo, useState } from "react";
import { CustomTheme } from "./palette.interface";
import { useTheme } from "@emotion/react";
import { CreateMUIStyled } from "@mui/material";
import { ThemeMode } from "@theme/v2/types";
import useCombineThemes from "@theme/v2/hooks/useCombineThemes";
 
export const ColorModeContext = React.createContext({
  toggleColorMode: (mode: "light" | "dark") => {
    return;
  },
});
 
export const ThemeWrapper = ({
  children,
  defaultMode = "light",
  isFeatureFlagBound = false,
  isNewThemeOnly = false,
  combineThemesIOC,
}: {
  children: ReactNode;
  defaultMode?: ThemeMode;
  isFeatureFlagBound?: boolean;
  isNewThemeOnly?: boolean;
  combineThemesIOC?: any;
}) => {
  const [mode, setMode] = useState<PaletteMode>(defaultMode);
 
  const colorMode = useMemo(
    () => ({
      // The dark mode switch would invoke this method
      toggleColorMode: () => {
        setMode((prevMode: PaletteMode) =>
          prevMode === "light" ? "dark" : "light",
        );
      },
    }),
    [],
  );
 
  const combineThemes = useCombineThemes(mode, isNewThemeOnly);
 
  return (
    <ColorModeContext.Provider value={colorMode}>
      <ThemeProvider theme={combineThemesIOC ?? combineThemes}>
        {children}
      </ThemeProvider>
    </ColorModeContext.Provider>
  );
};
 
export const useAppTheme = (): CustomTheme => {
  const theme = useTheme();
 
  return theme as CustomTheme;
};
 
export const styled: CreateMUIStyled<CustomTheme> = styledd;