@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
42 lines (39 loc) • 1.72 kB
JavaScript
import { deepMerge } from '../../utils/deep-merge/deep-merge.mjs';
import 'react';
import 'react/jsx-runtime';
import '@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(currentTheme, themeOverride);
if (themeOverride.fontFamily && !themeOverride.headings?.fontFamily) {
result.headings.fontFamily = themeOverride.fontFamily;
}
validateMantineTheme(result);
return result;
}
export { INVALID_PRIMARY_COLOR_ERROR, INVALID_PRIMARY_SHADE_ERROR, mergeMantineTheme, validateMantineTheme };
//# sourceMappingURL=merge-mantine-theme.mjs.map