Permalink
    
      
  
      
    
      
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
            
          
          
          
          
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
                
                  
            
          
          
          
          
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
                
                  
                
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
          
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
          
          
          
            
            
            
                
                  
                
                  
                
                  
            
          
          
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                
                  
            
          
          
      
    
  
  
  material-ui/packages/material-ui/src/styles/createMuiTheme.js
  
    
    
 
  Newer
  
  
        
          
        
        100644
        
          102 lines (93 sloc)
          
        2.95 KB
      
    1
                  import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb.
                2
                  import isPlainObject from 'is-plain-object';
                4
                  import createBreakpoints from './createBreakpoints';
                5
                  import createMixins from './createMixins';
                6
                  import createPalette from './createPalette';
                7
                  import createTypography from './createTypography';
                10
                  import defaultSpacing from './spacing';
                11
                  import transitions from './transitions';
                15
                    const {
                16
                      breakpoints: breakpointsInput = {},
                17
                      mixins: mixinsInput = {},
                20
                      spacing: spacingInput = {},
                22
                      ...other
                23
                    } = options;
                24
                  25
                    const palette = createPalette(paletteInput);
                26
                    const breakpoints = createBreakpoints(breakpointsInput);
                27
                    const spacing = { ...defaultSpacing, ...spacingInput };
                32
                      mixins: createMixins(breakpoints, spacing, mixinsInput),
                33
                      overrides: {}, // Inject custom styles
                34
                      palette,
                35
                      props: {}, // Inject custom properties
                36
                      shadows: shadowsInput || shadows,
                37
                      typography: createTypography(palette, typographyInput),
                46
                        {
                47
                          isMergeableObject: isPlainObject,
                48
                        },
                52
                    if (process.env.NODE_ENV !== 'production') {
                53
                      const statesWarning = ['disabled', 'focused', 'selected', 'checked'];
                54
                      const traverse = (node, parentKey, depth = 1) => {
                55
                        let key;
                56
                  57
                        // eslint-disable-next-line guard-for-in, no-restricted-syntax
                58
                        for (key in node) {
                59
                          const child = node[key];
                60
                          if (depth === 1) {
                61
                            if (key.indexOf('Mui') === 0 && child) {
                62
                              traverse(child, key, depth + 1);
                63
                            }
                64
                          } else if (statesWarning.indexOf(key) !== -1 && Object.keys(child).length > 0) {
                65
                            warning(
                66
                              false,
                67
                              [
                68
                                `Material-UI: the \`${parentKey}\` component increases ` +
                69
                                  `the CSS specificity of the \`${key}\` internal state.`,
                70
                                'You can not override it like this: ',
                71
                                JSON.stringify(node, null, 2),
                72
                                '',
                73
                                'Instead, you need to use the $ruleName syntax:',
                74
                                JSON.stringify(
                75
                                  {
                79
                                  },
                80
                                  null,
                81
                                  2,
                82
                                ),
                83
                                '',
                84
                                'https://material-ui.com/customization/overrides#internal-states',
                85
                              ].join('\n'),
                86
                            );
                87
                          }
                88
                        }
                89
                      };
                90
                  91
                      traverse(other.overrides);
                92
                    }
                93
                  94
                    warning(
                95
                      muiTheme.shadows.length === 25,
                96
                      'Material-UI: the shadows array provided to createMuiTheme should support 25 elevations.',
                97
                    );
                98
                  99
                    return muiTheme;