UNPKG

2.48 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = adaptV4Theme;
7var _system = require("@mui/system");
8function adaptV4Theme(inputTheme) {
9 if (process.env.NODE_ENV !== 'production') {
10 console.warn(['MUI: adaptV4Theme() is deprecated.', 'Follow the upgrade guide on https://mui.com/r/migration-v4#theme.'].join('\n'));
11 }
12 const {
13 defaultProps = {},
14 mixins = {},
15 overrides = {},
16 palette = {},
17 props = {},
18 styleOverrides = {},
19 ...other
20 } = inputTheme;
21 const theme = {
22 ...other,
23 components: {}
24 };
25
26 // default props
27 Object.keys(defaultProps).forEach(component => {
28 const componentValue = theme.components[component] || {};
29 componentValue.defaultProps = defaultProps[component];
30 theme.components[component] = componentValue;
31 });
32 Object.keys(props).forEach(component => {
33 const componentValue = theme.components[component] || {};
34 componentValue.defaultProps = props[component];
35 theme.components[component] = componentValue;
36 });
37
38 // CSS overrides
39 Object.keys(styleOverrides).forEach(component => {
40 const componentValue = theme.components[component] || {};
41 componentValue.styleOverrides = styleOverrides[component];
42 theme.components[component] = componentValue;
43 });
44 Object.keys(overrides).forEach(component => {
45 const componentValue = theme.components[component] || {};
46 componentValue.styleOverrides = overrides[component];
47 theme.components[component] = componentValue;
48 });
49
50 // theme.spacing
51 theme.spacing = (0, _system.createSpacing)(inputTheme.spacing);
52
53 // theme.mixins.gutters
54 const breakpoints = (0, _system.createBreakpoints)(inputTheme.breakpoints || {});
55 const spacing = theme.spacing;
56 theme.mixins = {
57 gutters: (styles = {}) => {
58 return {
59 paddingLeft: spacing(2),
60 paddingRight: spacing(2),
61 ...styles,
62 [breakpoints.up('sm')]: {
63 paddingLeft: spacing(3),
64 paddingRight: spacing(3),
65 ...styles[breakpoints.up('sm')]
66 }
67 };
68 },
69 ...mixins
70 };
71 const {
72 type: typeInput,
73 mode: modeInput,
74 ...paletteRest
75 } = palette;
76 const finalMode = modeInput || typeInput || 'light';
77 theme.palette = {
78 // theme.palette.text.hint
79 text: {
80 hint: finalMode === 'dark' ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.38)'
81 },
82 mode: finalMode,
83 type: finalMode,
84 ...paletteRest
85 };
86 return theme;
87}
\No newline at end of file