UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 3.18 kB
{"version":3,"file":"merge-mantine-theme.mjs","sources":["../../../../src/core/MantineProvider/merge-mantine-theme/merge-mantine-theme.ts"],"sourcesContent":["import { deepMerge } from '../../utils';\nimport type { MantineTheme, MantineThemeOverride } from '../theme.types';\n\nexport const INVALID_PRIMARY_COLOR_ERROR =\n '[@mantine/core] MantineProvider: Invalid theme.primaryColor, it accepts only key of theme.colors, learn more – https://mantine.dev/theming/colors/#primary-color';\n\nexport const INVALID_PRIMARY_SHADE_ERROR =\n '[@mantine/core] MantineProvider: Invalid theme.primaryShade, it accepts only 0-9 integers or an object { light: 0-9, dark: 0-9 }';\n\nfunction isValidPrimaryShade(shade: number) {\n if (shade < 0 || shade > 9) {\n return false;\n }\n\n return parseInt(shade.toString(), 10) === shade;\n}\n\nexport function validateMantineTheme(theme: MantineTheme): asserts theme is MantineTheme {\n if (!(theme.primaryColor in theme.colors)) {\n throw new Error(INVALID_PRIMARY_COLOR_ERROR);\n }\n\n if (typeof theme.primaryShade === 'object') {\n if (\n !isValidPrimaryShade(theme.primaryShade.dark) ||\n !isValidPrimaryShade(theme.primaryShade.light)\n ) {\n throw new Error(INVALID_PRIMARY_SHADE_ERROR);\n }\n }\n\n if (typeof theme.primaryShade === 'number' && !isValidPrimaryShade(theme.primaryShade)) {\n throw new Error(INVALID_PRIMARY_SHADE_ERROR);\n }\n}\n\nexport function mergeMantineTheme(\n currentTheme: MantineTheme,\n themeOverride?: MantineThemeOverride\n) {\n if (!themeOverride) {\n validateMantineTheme(currentTheme);\n return currentTheme;\n }\n\n const result = deepMerge(currentTheme, themeOverride);\n\n if (themeOverride.fontFamily && !themeOverride.headings?.fontFamily) {\n result.headings.fontFamily = themeOverride.fontFamily;\n }\n\n validateMantineTheme(result);\n return result;\n}\n"],"names":[],"mappings":";;;;;AAEY,MAAC,2BAA2B,GAAG,wKAAwK;AACvM,MAAC,2BAA2B,GAAG,mIAAmI;AAC9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