diff --git a/lib/cjs/helpers/materialUI.d.ts b/lib/cjs/helpers/materialUI.d.ts index 575178e0..bb44ef9e 100644 --- a/lib/cjs/helpers/materialUI.d.ts +++ b/lib/cjs/helpers/materialUI.d.ts @@ -5,7 +5,7 @@ export declare function insertDividerBetweenElements({ elements, dividerProps }: elements: React.ReactElement[]; dividerProps?: DividerProps; }): React.ReactElement[]; -export declare function getStyleOverrides(ownerState: Record, componentKey: keyof NonNullable, muiClassName?: string, components?: ThemeOptions['components']): object; +export declare function getStyleOverrides(ownerState: CommonProps, componentKey: keyof NonNullable, muiClassName?: string, components?: ThemeOptions['components']): object; export declare function getClassNames(props: CommonProps): string[]; export declare function includesClassNames(propsOrClassNames: CommonProps | string[], includes: string[]): boolean; export declare function matchClassNames(propsOrClassNames: CommonProps | string[], pattern: string | RegExp): RegExpMatchArray[]; diff --git a/lib/cjs/theme/ThemedBox.js b/lib/cjs/theme/ThemedBox.js index 89b2c734..df534bee 100644 --- a/lib/cjs/theme/ThemedBox.js +++ b/lib/cjs/theme/ThemedBox.js @@ -63,23 +63,23 @@ var ThemedBox = function (_a) { color: bgcolor.contrastText, textDecorationColor: bgcolor.contrastText }; - function getStyleOverrides(ownerState, componentKey, muiClassName) { + function overrideStyles(ownerState, styleOverrides, componentKey, muiClassName) { if (muiClassName === void 0) { muiClassName = 'root'; } - return (0, helpers_1.getStyleOverrides)(ownerState, componentKey, muiClassName, options.components); + return __assign(__assign({}, (0, helpers_1.getStyleOverrides)(ownerState, componentKey, muiClassName, options.components)), (!(0, helpers_1.includesClassNames)(ownerState, ['no-override']) && styleOverrides)); } var theme = (0, material_1.responsiveFontSizes)((0, material_1.createTheme)(__assign(__assign({}, options), { components: __assign(__assign({}, options.components), { MuiTypography: __assign(__assign({}, (_b = options.components) === null || _b === void 0 ? void 0 : _b.MuiTypography), { styleOverrides: __assign(__assign({}, (_d = (_c = options.components) === null || _c === void 0 ? void 0 : _c.MuiTypography) === null || _d === void 0 ? void 0 : _d.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiTypography')), fontStyleOverrides)); + return overrideStyles(ownerState, __assign({}, fontStyleOverrides), 'MuiTypography'); } }) }), MuiFormHelperText: __assign(__assign({}, (_e = options.components) === null || _e === void 0 ? void 0 : _e.MuiFormHelperText), { styleOverrides: __assign(__assign({}, (_g = (_f = options.components) === null || _f === void 0 ? void 0 : _f.MuiFormHelperText) === null || _g === void 0 ? void 0 : _g.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiFormHelperText')), fontStyleOverrides)); + return overrideStyles(ownerState, __assign({}, fontStyleOverrides), 'MuiFormHelperText'); } }) }), MuiLink: __assign(__assign({}, (_h = options.components) === null || _h === void 0 ? void 0 : _h.MuiLink), { styleOverrides: __assign(__assign({}, (_k = (_j = options.components) === null || _j === void 0 ? void 0 : _j.MuiLink) === null || _k === void 0 ? void 0 : _k.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiLink')), fontStyleOverrides)); + return overrideStyles(ownerState, __assign({}, fontStyleOverrides), 'MuiLink'); } }) }), MuiButton: __assign(__assign({}, (_l = options.components) === null || _l === void 0 ? void 0 : _l.MuiButton), { styleOverrides: __assign(__assign({}, (_o = (_m = options.components) === null || _m === void 0 ? void 0 : _m.MuiButton) === null || _o === void 0 ? void 0 : _o.styleOverrides), { contained: function (_a) { var _b; var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiButton', 'contained')), (userType === 'independent' && (_b = { + return overrideStyles(ownerState, __assign({}, (userType === 'independent' && (_b = { backgroundColor: 'white', '&:hover': { backgroundColor: '#f6f5f5', @@ -94,22 +94,26 @@ var ThemedBox = function (_a) { backgroundColor: 'white', color: bgcolor.contrastText }, - _b)))); + _b))), 'MuiButton', 'contained'); }, outlined: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign(__assign({}, getStyleOverrides(ownerState, 'MuiButton', 'outlined')), fontStyleOverrides), { border: "2px solid ".concat(bgcolor.contrastText), '&:hover': { + return overrideStyles(ownerState, __assign(__assign({}, fontStyleOverrides), { border: "2px solid ".concat(bgcolor.contrastText), '&:hover': { border: "2px solid ".concat(bgcolor.contrastText), backgroundColor: 'transparent', textDecoration: 'underline' - } })); + } }), 'MuiButton', 'outlined'); } }) }), MuiCheckbox: __assign(__assign({}, (_p = options.components) === null || _p === void 0 ? void 0 : _p.MuiCheckbox), { styleOverrides: __assign(__assign({}, (_r = (_q = options.components) === null || _q === void 0 ? void 0 : _q.MuiCheckbox) === null || _r === void 0 ? void 0 : _r.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiCheckbox')), { color: "".concat(bgcolor.contrastText, " !important") })); + return overrideStyles(ownerState, { + color: "".concat(bgcolor.contrastText, " !important") + }, 'MuiCheckbox'); } }) }), MuiSvgIcon: __assign(__assign({}, (_s = options.components) === null || _s === void 0 ? void 0 : _s.MuiSvgIcon), { styleOverrides: __assign(__assign({}, (_u = (_t = options.components) === null || _t === void 0 ? void 0 : _t.MuiSvgIcon) === null || _u === void 0 ? void 0 : _u.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiSvgIcon')), { '&.checkbox-error': { + return overrideStyles(ownerState, { + '&.checkbox-error': { color: "".concat(bgcolor.contrastText, " !important") - } })); + } + }, 'MuiSvgIcon'); } }) }) }) }))); return (react_1.default.createElement(material_1.ThemeProvider, { theme: theme }, react_1.default.createElement(material_1.Box, __assign({ sx: __assign(__assign(__assign({}, sx), (withShapes && { diff --git a/lib/esm/helpers/materialUI.d.ts b/lib/esm/helpers/materialUI.d.ts index 575178e0..bb44ef9e 100644 --- a/lib/esm/helpers/materialUI.d.ts +++ b/lib/esm/helpers/materialUI.d.ts @@ -5,7 +5,7 @@ export declare function insertDividerBetweenElements({ elements, dividerProps }: elements: React.ReactElement[]; dividerProps?: DividerProps; }): React.ReactElement[]; -export declare function getStyleOverrides(ownerState: Record, componentKey: keyof NonNullable, muiClassName?: string, components?: ThemeOptions['components']): object; +export declare function getStyleOverrides(ownerState: CommonProps, componentKey: keyof NonNullable, muiClassName?: string, components?: ThemeOptions['components']): object; export declare function getClassNames(props: CommonProps): string[]; export declare function includesClassNames(propsOrClassNames: CommonProps | string[], includes: string[]): boolean; export declare function matchClassNames(propsOrClassNames: CommonProps | string[], pattern: string | RegExp): RegExpMatchArray[]; diff --git a/lib/esm/theme/ThemedBox.js b/lib/esm/theme/ThemedBox.js index 8d76b298..dc478d2e 100644 --- a/lib/esm/theme/ThemedBox.js +++ b/lib/esm/theme/ThemedBox.js @@ -25,7 +25,7 @@ import { Box, ThemeProvider, buttonClasses, responsiveFontSizes, createTheme } f import { Circle as CircleIcon, Hexagon as HexagonIcon } from '@mui/icons-material'; import { themeOptions } from '.'; import palette from './palette'; -import { getStyleOverrides as _getStyleOverrides } from '../helpers'; +import { getStyleOverrides, includesClassNames } from '../helpers'; var ThemedBox = function (_a) { var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; var _v = _a.options, options = _v === void 0 ? themeOptions : _v, _w = _a.withShapes, withShapes = _w === void 0 ? false : _w, userType = _a.userType, children = _a.children, sx = _a.sx, otherBoxProps = __rest(_a, ["options", "withShapes", "userType", "children", "sx"]); @@ -58,23 +58,23 @@ var ThemedBox = function (_a) { color: bgcolor.contrastText, textDecorationColor: bgcolor.contrastText }; - function getStyleOverrides(ownerState, componentKey, muiClassName) { + function overrideStyles(ownerState, styleOverrides, componentKey, muiClassName) { if (muiClassName === void 0) { muiClassName = 'root'; } - return _getStyleOverrides(ownerState, componentKey, muiClassName, options.components); + return __assign(__assign({}, getStyleOverrides(ownerState, componentKey, muiClassName, options.components)), (!includesClassNames(ownerState, ['no-override']) && styleOverrides)); } var theme = responsiveFontSizes(createTheme(__assign(__assign({}, options), { components: __assign(__assign({}, options.components), { MuiTypography: __assign(__assign({}, (_b = options.components) === null || _b === void 0 ? void 0 : _b.MuiTypography), { styleOverrides: __assign(__assign({}, (_d = (_c = options.components) === null || _c === void 0 ? void 0 : _c.MuiTypography) === null || _d === void 0 ? void 0 : _d.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiTypography')), fontStyleOverrides)); + return overrideStyles(ownerState, __assign({}, fontStyleOverrides), 'MuiTypography'); } }) }), MuiFormHelperText: __assign(__assign({}, (_e = options.components) === null || _e === void 0 ? void 0 : _e.MuiFormHelperText), { styleOverrides: __assign(__assign({}, (_g = (_f = options.components) === null || _f === void 0 ? void 0 : _f.MuiFormHelperText) === null || _g === void 0 ? void 0 : _g.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiFormHelperText')), fontStyleOverrides)); + return overrideStyles(ownerState, __assign({}, fontStyleOverrides), 'MuiFormHelperText'); } }) }), MuiLink: __assign(__assign({}, (_h = options.components) === null || _h === void 0 ? void 0 : _h.MuiLink), { styleOverrides: __assign(__assign({}, (_k = (_j = options.components) === null || _j === void 0 ? void 0 : _j.MuiLink) === null || _k === void 0 ? void 0 : _k.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiLink')), fontStyleOverrides)); + return overrideStyles(ownerState, __assign({}, fontStyleOverrides), 'MuiLink'); } }) }), MuiButton: __assign(__assign({}, (_l = options.components) === null || _l === void 0 ? void 0 : _l.MuiButton), { styleOverrides: __assign(__assign({}, (_o = (_m = options.components) === null || _m === void 0 ? void 0 : _m.MuiButton) === null || _o === void 0 ? void 0 : _o.styleOverrides), { contained: function (_a) { var _b; var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiButton', 'contained')), (userType === 'independent' && (_b = { + return overrideStyles(ownerState, __assign({}, (userType === 'independent' && (_b = { backgroundColor: 'white', '&:hover': { backgroundColor: '#f6f5f5', @@ -89,22 +89,26 @@ var ThemedBox = function (_a) { backgroundColor: 'white', color: bgcolor.contrastText }, - _b)))); + _b))), 'MuiButton', 'contained'); }, outlined: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign(__assign({}, getStyleOverrides(ownerState, 'MuiButton', 'outlined')), fontStyleOverrides), { border: "2px solid ".concat(bgcolor.contrastText), '&:hover': { + return overrideStyles(ownerState, __assign(__assign({}, fontStyleOverrides), { border: "2px solid ".concat(bgcolor.contrastText), '&:hover': { border: "2px solid ".concat(bgcolor.contrastText), backgroundColor: 'transparent', textDecoration: 'underline' - } })); + } }), 'MuiButton', 'outlined'); } }) }), MuiCheckbox: __assign(__assign({}, (_p = options.components) === null || _p === void 0 ? void 0 : _p.MuiCheckbox), { styleOverrides: __assign(__assign({}, (_r = (_q = options.components) === null || _q === void 0 ? void 0 : _q.MuiCheckbox) === null || _r === void 0 ? void 0 : _r.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiCheckbox')), { color: "".concat(bgcolor.contrastText, " !important") })); + return overrideStyles(ownerState, { + color: "".concat(bgcolor.contrastText, " !important") + }, 'MuiCheckbox'); } }) }), MuiSvgIcon: __assign(__assign({}, (_s = options.components) === null || _s === void 0 ? void 0 : _s.MuiSvgIcon), { styleOverrides: __assign(__assign({}, (_u = (_t = options.components) === null || _t === void 0 ? void 0 : _t.MuiSvgIcon) === null || _u === void 0 ? void 0 : _u.styleOverrides), { root: function (_a) { var ownerState = _a.ownerState; - return (__assign(__assign({}, getStyleOverrides(ownerState, 'MuiSvgIcon')), { '&.checkbox-error': { + return overrideStyles(ownerState, { + '&.checkbox-error': { color: "".concat(bgcolor.contrastText, " !important") - } })); + } + }, 'MuiSvgIcon'); } }) }) }) }))); return (React.createElement(ThemeProvider, { theme: theme }, React.createElement(Box, __assign({ sx: __assign(__assign(__assign({}, sx), (withShapes && {