@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
47 lines (43 loc) • 1.87 kB
JavaScript
var deepMerge = require('../../utils/deep-merge/deep-merge.cjs');
require('react');
require('react/jsx-runtime');
require('@mantine/hooks');
const INVALID_PRIMARY_COLOR_ERROR = "[@mantine/core] MantineProvider: Invalid theme.primaryColor, it accepts only key of theme.colors, learn more \u2013 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 = deepMerge.deepMerge(currentTheme, themeOverride);
if (themeOverride.fontFamily && !themeOverride.headings?.fontFamily) {
result.headings.fontFamily = themeOverride.fontFamily;
}
validateMantineTheme(result);
return result;
}
exports.INVALID_PRIMARY_COLOR_ERROR = INVALID_PRIMARY_COLOR_ERROR;
exports.INVALID_PRIMARY_SHADE_ERROR = INVALID_PRIMARY_SHADE_ERROR;
exports.mergeMantineTheme = mergeMantineTheme;
exports.validateMantineTheme = validateMantineTheme;
//# sourceMappingURL=merge-mantine-theme.cjs.map
;