Buckets:
| ; | |
| Object.defineProperty(exports, "__esModule", { | |
| value: true | |
| }); | |
| exports.default = applyStyles; | |
| /** | |
| * A universal utility to style components with multiple color modes. Always use it from the theme object. | |
| * It works with: | |
| * - [Basic theme](https://mui.com/material-ui/customization/dark-mode/) | |
| * - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/) | |
| * - Zero-runtime engine | |
| * | |
| * Tips: Use an array over object spread and place `theme.applyStyles()` last. | |
| * | |
| * With the styled function: | |
| * โ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })] | |
| * ๐ซ { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })} | |
| * | |
| * With the sx prop: | |
| * โ [{ background: '#e5e5e5' }, theme => theme.applyStyles('dark', { background: '#1c1c1c' })] | |
| * ๐ซ { background: '#e5e5e5', ...theme => theme.applyStyles('dark', { background: '#1c1c1c' })} | |
| * | |
| * @example | |
| * 1. using with `styled`: | |
| * ```jsx | |
| * const Component = styled('div')(({ theme }) => [ | |
| * { background: '#e5e5e5' }, | |
| * theme.applyStyles('dark', { | |
| * background: '#1c1c1c', | |
| * color: '#fff', | |
| * }), | |
| * ]); | |
| * ``` | |
| * | |
| * @example | |
| * 2. using with `sx` prop: | |
| * ```jsx | |
| * <Box sx={[ | |
| * { background: '#e5e5e5' }, | |
| * theme => theme.applyStyles('dark', { | |
| * background: '#1c1c1c', | |
| * color: '#fff', | |
| * }), | |
| * ]} | |
| * /> | |
| * ``` | |
| * | |
| * @example | |
| * 3. theming a component: | |
| * ```jsx | |
| * extendTheme({ | |
| * components: { | |
| * MuiButton: { | |
| * styleOverrides: { | |
| * root: ({ theme }) => [ | |
| * { background: '#e5e5e5' }, | |
| * theme.applyStyles('dark', { | |
| * background: '#1c1c1c', | |
| * color: '#fff', | |
| * }), | |
| * ], | |
| * }, | |
| * } | |
| * } | |
| * }) | |
| *``` | |
| */ | |
| function applyStyles(key, styles) { | |
| // @ts-expect-error this is 'any' type | |
| const theme = this; | |
| if (theme.vars) { | |
| if (!theme.colorSchemes?.[key] || typeof theme.getColorSchemeSelector !== 'function') { | |
| return {}; | |
| } | |
| // If CssVarsProvider is used as a provider, returns '*:where({selector}) &' | |
| let selector = theme.getColorSchemeSelector(key); | |
| if (selector === '&') { | |
| return styles; | |
| } | |
| if (selector.includes('data-') || selector.includes('.')) { | |
| // '*' is required as a workaround for Emotion issue (https://github.com/emotion-js/emotion/issues/2836) | |
| selector = `*:where(${selector.replace(/\s*&$/, '')}) &`; | |
| } | |
| return { | |
| [selector]: styles | |
| }; | |
| } | |
| if (theme.palette.mode === key) { | |
| return styles; | |
| } | |
| return {}; | |
| } |
Xet Storage Details
- Size:
- 2.67 kB
- Xet hash:
- ddad8659e37d87ef83d62e71e0d4e392d4f4417e24915c45b2b13ca49f769588
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.