Permalink
    
      
  
      
    
      
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
            
          
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
                
                  
            
          
          
          
          
          
            
              
                
              
            
            
              
            
            
                
                  
                
                  
                
                  
                
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                
                  
            
          
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
                
                  
                
                  
                
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
            
          
          
            
              
                
              
            
            
            
                
                  
            
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
          
            
            
            
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
                
                  
            
          
          
            
            
            
                
                  
                
                  
            
          
          
          
            
            
            
                
                  
            
          
          
          
          
      
    
  
  
  material-ui/packages/material-ui/src/styles/createMuiTheme.js
  
    
    
 
  Newer
  
  
        
          
        
        100644
        
          104 lines (95 sloc)
          
        2.92 KB
      
    1
                  import { deepmerge } from '@material-ui/utils';
                2
                  import createBreakpoints from './createBreakpoints';
                3
                  import createMixins from './createMixins';
                4
                  import createPalette from './createPalette';
                5
                  import createTypography from './createTypography';
                8
                  import createSpacing from './createSpacing';
                9
                  import transitions from './transitions';
                13
                    const {
                14
                      breakpoints: breakpointsInput = {},
                15
                      mixins: mixinsInput = {},
                19
                      ...other
                20
                    } = options;
                21
                  22
                    const palette = createPalette(paletteInput);
                23
                    const breakpoints = createBreakpoints(breakpointsInput);
                24
                    const spacing = createSpacing(spacingInput);
                26
                    let muiTheme = deepmerge(
                27
                      {
                28
                        breakpoints,
                29
                        direction: 'ltr',
                30
                        mixins: createMixins(breakpoints, spacing, mixinsInput),
                31
                        overrides: {}, // Inject custom styles
                32
                        palette,
                33
                        props: {}, // Provide default props
                34
                        shadows,
                35
                        typography: createTypography(palette, typographyInput),
                36
                        spacing,
                37
                        shape,
                38
                        transitions,
                40
                        zIndex,
                41
                      },
                42
                      other,
                43
                    );
                44
                  45
                    muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
                47
                    if (process.env.NODE_ENV !== 'production') {
                48
                      const pseudoClasses = [
                49
                        'checked',
                50
                        'disabled',
                51
                        'error',
                52
                        'focused',
                53
                        'focusVisible',
                54
                        'required',
                55
                        'expanded',
                56
                        'selected',
                57
                      ];
                58
                      const traverse = (node, parentKey, depth = 1) => {
                59
                        let key;
                60
                  61
                        // eslint-disable-next-line guard-for-in, no-restricted-syntax
                62
                        for (key in node) {
                63
                          const child = node[key];
                64
                          if (depth === 1) {
                65
                            if (key.indexOf('Mui') === 0 && child) {
                66
                              traverse(child, key, depth + 1);
                67
                            }
                68
                          } else if (pseudoClasses.indexOf(key) !== -1 && Object.keys(child).length > 0) {
                69
                            if (process.env.NODE_ENV !== 'production') {
                70
                              console.error(
                71
                                [
                72
                                  `Material-UI: The \`${parentKey}\` 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 $ruleName syntax:',
                78
                                  JSON.stringify(
                79
                                    {
                80
                                      root: {
                81
                                        [`&$${key}`]: child,
                82
                                      },
                84
                                    null,
                85
                                    2,
                86
                                  ),
                87
                                  '',
                88
                                  'https://material-ui.com/r/pseudo-classes-guide',
                89
                                ].join('\n'),
                90
                              );
                91
                            }
                92
                            // Remove the style to prevent global conflicts.
                93
                            node[key] = {};
                98
                      traverse(muiTheme.overrides);