UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

30 lines (29 loc) 1.7 kB
const require_deep_merge = require("../../utils/deep-merge/deep-merge.cjs"); //#region packages/@mantine/core/src/core/MantineProvider/merge-mantine-theme/merge-mantine-theme.ts const INVALID_PRIMARY_COLOR_ERROR = "[@mantine/core] MantineProvider: Invalid theme.primaryColor, it accepts only key of theme.colors, learn more – https://mantine.dev/theming/colors/#primary-color"; const INVALID_PRIMARY_SHADE_ERROR = "[@mantine/core] MantineProvider: Invalid theme.primaryShade, it accepts only 0-9 integers or an object { light: 0-9, dark: 0-9 }"; function isValidPrimaryShade(shade) { if (shade < 0 || shade > 9) return false; return parseInt(shade.toString(), 10) === shade; } function validateMantineTheme(theme) { if (!(theme.primaryColor in theme.colors)) throw new Error(INVALID_PRIMARY_COLOR_ERROR); if (typeof theme.primaryShade === "object") { if (!isValidPrimaryShade(theme.primaryShade.dark) || !isValidPrimaryShade(theme.primaryShade.light)) throw new Error(INVALID_PRIMARY_SHADE_ERROR); } if (typeof theme.primaryShade === "number" && !isValidPrimaryShade(theme.primaryShade)) throw new Error(INVALID_PRIMARY_SHADE_ERROR); } function mergeMantineTheme(currentTheme, themeOverride) { if (!themeOverride) { validateMantineTheme(currentTheme); return currentTheme; } const result = require_deep_merge.deepMerge(currentTheme, themeOverride); if (themeOverride.fontFamily && !themeOverride.headings?.fontFamily) result.headings.fontFamily = themeOverride.fontFamily; validateMantineTheme(result); return result; } //#endregion exports.mergeMantineTheme = mergeMantineTheme; exports.validateMantineTheme = validateMantineTheme; //# sourceMappingURL=merge-mantine-theme.cjs.map