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