All files / src/theme/v2/hooks useCombineThemes.ts

100% Statements 8/8
54.54% Branches 6/11
100% Functions 3/3
100% Lines 6/6

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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82        547x 4696x   4696x 7480x   7262x                                                                                                                       7262x                      
import { useMemo } from "react";
import { createThemeBuilder } from "@theme/v2/theme.builders";
import { ThemeMode } from "@theme/v2/types";
 
const useCombineThemes = (mode: ThemeMode, isNewThemeOnly = false) => {
  const theme: any = useMemo(() => createThemeBuilder(mode), [mode]);
 
  return (outerTheme: any) => {
    if (isNewThemeOnly) return theme;
 
    const components = {
      ...outerTheme.components,
      ...theme.components,
      MuiButton: {
        ...outerTheme.components.MuiButton,
        variants: [
          ...outerTheme.components.MuiButton.variants,
          ...(theme?.components?.MuiButton?.variants || []),
        ],
      },
      MuiIconButton: {
        ...outerTheme.components.MuiIconButton,
        styleOverrides: {
          root: {
            variants: [
              ...outerTheme.components.MuiIconButton.styleOverrides.root
                .variants,
              ...(theme.components?.MuiIconButton?.styleOverrides?.root
                ?.variants || []),
            ],
          },
        },
      },
      MuiTextField: {
        ...outerTheme.components.MuiTextField,
        styleOverrides: {
          root: {
            variants: [
              ...outerTheme.components.MuiTextField.styleOverrides.root
                .variants,
              ...(theme.components?.MuiTextField?.styleOverrides?.root
                ?.variants || {}),
            ],
          },
        },
      },
      MuiCheckbox: {
        ...outerTheme.components.MuiCheckbox,
        styleOverrides: {
          root: {
            variants: [
              ...outerTheme.components.MuiCheckbox.styleOverrides.root.variants,
              ...(theme.components?.MuiCheckbox?.styleOverrides?.root
                ?.variants || {}),
            ],
          },
        },
      },
      MuiTypography: {
        defaultProps: {
          ...outerTheme.components.MuiTypography.defaultProps,
          variantMapping: {
            ...outerTheme.components.MuiTypography.defaultProps.variantMapping,
            ...theme.components.MuiTypography.defaultProps.variantMapping,
          },
        },
        styleOverrides: theme.components.MuiTypography.styleOverrides,
      },
    };
 
    return {
      ...outerTheme,
      ...theme,
      components,
      breakpoints: { ...outerTheme.breakpoints, ...theme.breakpoints },
      palette: { ...outerTheme.palette, ...theme.palette },
    };
  };
};
 
export default useCombineThemes;