UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 3.04 kB
{"version":3,"file":"merge-mantine-theme.cjs","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":["deepMerge"],"mappings":";;;;;;;AAGO,MAAM,2BACX,GAAA;AAEK,MAAM,2BACX,GAAA;AAEF,SAAS,oBAA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