Permalink
    
      
  
      
    
        
          
            
              
                
              
            
            
            
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
            
          
          
          
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
          
          
          
            
            
            
                
                  
            
          
          
          
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
            
          
          
            
              
                
              
            
            
              
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
          
          
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
            
            
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
            
            
            
                
                  
                
                  
            
          
          
          
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
                
                  
            
          
      
    
  
  
  material-ui/packages/mui-material/src/styles/createTheme.js
  
    
    
 
  Newer
  
  
        
          
        
        100644
        
          129 lines (114 sloc)
          
        3.76 KB
      
    
          
            Ignoring revisions in .git-blame-ignore-revs.
        
      1
                  import { deepmerge } from '@mui/utils';
                2
                  import { createTheme as systemCreateTheme } from '@mui/system';
                3
                  import MuiError from '@mui/utils/macros/MuiError.macro';
                4
                  import generateUtilityClass from '../generateUtilityClass';
                6
                  import createPalette from './createPalette';
                7
                  import createTypography from './createTypography';
                9
                  import createTransitions from './createTransitions';
                12
                  function createTheme(options = {}, ...args) {
                18
                      transitions: transitionsInput = {},
                24
                    if (options.vars) {
                25
                      throw new MuiError(
                26
                        'MUI: `vars` is a private field used for CSS variables support.\n' +
                27
                          'Please use another name.',
                28
                      );
                29
                    }
                30
                  31
                    const palette = createPalette(paletteInput);
                32
                    const systemTheme = systemCreateTheme(options);
                35
                      mixins: createMixins(systemTheme.breakpoints, mixinsInput),
                36
                      palette,
                37
                      // Don't use [...shadows] until you've verified its transpiled code is not invoking the iterator protocol.
                38
                      shadows: shadows.slice(),
                39
                      typography: createTypography(palette, typographyInput),
                40
                      transitions: createTransitions(transitionsInput),
                41
                      zIndex: { ...zIndex },
                42
                    });
                45
                    muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
                47
                    if (process.env.NODE_ENV !== 'production') {
                55
                        'focused',
                56
                        'focusVisible',
                57
                        'required',
                58
                        'selected',
                59
                      ];
                61
                      const traverse = (node, component) => {
                62
                        let key;
                63
                  64
                        // eslint-disable-next-line guard-for-in, no-restricted-syntax
                65
                        for (key in node) {
                66
                          const child = node[key];
                67
                          if (stateClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
                68
                            if (process.env.NODE_ENV !== 'production') {
                69
                              const stateClass = generateUtilityClass('', key);
                72
                                  `MUI: The \`${component}\` component increases ` +
                73
                                    `the CSS specificity of the \`${key}\` internal state.`,
                74
                                  'You can not override it like this: ',
                75
                                  JSON.stringify(node, null, 2),
                76
                                  '',
                77
                                  `Instead, you need to use the '&.${stateClass}' syntax:`,
                78
                                  JSON.stringify(
                79
                                    {
                80
                                      root: {
                81
                                        [`&.${stateClass}`]: child,
                88
                                  'https://mui.com/r/state-classes-guide',
                92
                            // Remove the style to prevent global conflicts.
                93
                            node[key] = {};
                98
                      Object.keys(muiTheme.components).forEach((component) => {
                99
                        const styleOverrides = muiTheme.components[component].styleOverrides;
                101
                        if (styleOverrides && component.indexOf('Mui') === 0) {
                102
                          traverse(styleOverrides, component);
                110
                  let warnedOnce = false;
                111
                  112
                  export function createMuiTheme(...args) {
                113
                    if (process.env.NODE_ENV !== 'production') {
                114
                      if (!warnedOnce) {
                115
                        warnedOnce = true;
                116
                        console.error(
                117
                          [
                118
                            'MUI: the createMuiTheme function was renamed to createTheme.',
                120
                            "You should use `import { createTheme } from '@mui/material/styles'`",
                121
                          ].join('\n'),
                122
                        );
                123
                      }
                124
                    }
                125
                  126
                    return createTheme(...args);
                127
                  }
                128
                  129
                  export default createTheme;