Permalink
    
      
  
      
    
        
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
            
          
          
          
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
          
          
          
            
            
            
                
                  
            
          
          
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
                
                  
                
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
          
          
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
          
          
            
            
            
                
                  
            
          
          
          
            
            
            
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
            
            
            
                
                  
                
                  
            
          
          
          
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
                
                  
            
          
      
    
  
  
  material-ui/packages/mui-material/src/styles/createTheme.js
  
    
    
 
  Newer
  
  
        
          
        
        100644
        
          121 lines (107 sloc)
          
        3.57 KB
      
    
          
            Ignoring revisions in .git-blame-ignore-revs.
        
      1
                  import { deepmerge } from '@mui/utils';
                2
                  import { generateUtilityClass } from '@mui/core';
                3
                  import { createTheme as systemCreateTheme } from '@mui/system';
                5
                  import createPalette from './createPalette';
                6
                  import createTypography from './createTypography';
                8
                  import createTransitions from './createTransitions';
                11
                  function createTheme(options = {}, ...args) {
                17
                      transitions: transitionsInput = {},
                20
                      ...other
                21
                    } = options;
                22
                  23
                    const palette = createPalette(paletteInput);
                24
                    const systemTheme = systemCreateTheme(options);
                26
                    let muiTheme = deepmerge(systemTheme, {
                27
                      mixins: createMixins(systemTheme.breakpoints, systemTheme.spacing, mixinsInput),
                28
                      palette,
                29
                      // Don't use [...shadows] until you've verified its transpiled code is not invoking the iterator protocol.
                30
                      shadows: shadows.slice(),
                31
                      typography: createTypography(palette, typographyInput),
                32
                      transitions: createTransitions(transitionsInput),
                33
                      zIndex: { ...zIndex },
                34
                    });
                37
                    muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
                39
                    if (process.env.NODE_ENV !== 'production') {
                47
                        'focused',
                48
                        'focusVisible',
                49
                        'required',
                50
                        'selected',
                51
                      ];
                53
                      const traverse = (node, component) => {
                54
                        let key;
                55
                  56
                        // eslint-disable-next-line guard-for-in, no-restricted-syntax
                57
                        for (key in node) {
                58
                          const child = node[key];
                59
                          if (stateClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
                60
                            if (process.env.NODE_ENV !== 'production') {
                61
                              const stateClass = generateUtilityClass('', key);
                64
                                  `Material-UI: The \`${component}\` component increases ` +
                65
                                    `the CSS specificity of the \`${key}\` internal state.`,
                66
                                  'You can not override it like this: ',
                67
                                  JSON.stringify(node, null, 2),
                68
                                  '',
                69
                                  `Instead, you need to use the '&.${stateClass}' syntax:`,
                70
                                  JSON.stringify(
                71
                                    {
                72
                                      root: {
                73
                                        [`&.${stateClass}`]: child,
                80
                                  'https://material-ui.com/r/state-classes-guide',
                84
                            // Remove the style to prevent global conflicts.
                85
                            node[key] = {};
                90
                      Object.keys(muiTheme.components).forEach((component) => {
                91
                        const styleOverrides = muiTheme.components[component].styleOverrides;
                93
                        if (styleOverrides && component.indexOf('Mui') === 0) {
                94
                          traverse(styleOverrides, component);
                102
                  let warnedOnce = false;
                103
                  104
                  export function createMuiTheme(...args) {
                105
                    if (process.env.NODE_ENV !== 'production') {
                106
                      if (!warnedOnce) {
                107
                        warnedOnce = true;
                108
                        console.error(
                109
                          [
                110
                            'Material-UI: the createMuiTheme function was renamed to createTheme.',
                111
                            '',
                112
                            "You should use `import { createTheme } from '@mui/material/styles'`",
                113
                          ].join('\n'),
                114
                        );
                115
                      }
                116
                    }
                117
                  118
                    return createTheme(...args);
                119
                  }
                120
                  121
                  export default createTheme;