11import warning from 'warning' ;
2- import { nested } from '../ThemeProvider/ThemeProvider' ;
3-
4- function safePrefix ( classNamePrefix ) {
5- const prefix = String ( classNamePrefix ) ;
6- warning ( prefix . length < 256 , `Material-UI: the class name prefix is too long: ${ prefix } .` ) ;
7- return prefix ;
8- }
2+ import nested from '../ThemeProvider/nested' ;
93
104/**
115 * This is the list of the style rule name we use as drop in replacement for the built-in
@@ -35,30 +29,10 @@ const pseudoClasses = [
3529// https://github.com/cssinjs/jss/blob/4e6a05dd3f7b6572fdd3ab216861d9e446c20331/src/utils/createGenerateClassName.js
3630export default function createGenerateClassName ( options = { } ) {
3731 const { disableGlobal = false , productionPrefix = 'jss' , seed = '' } = options ;
32+ const classNameSeed = seed === '' ? '' : `-${ seed } ` ;
3833 let ruleCounter = 0 ;
3934
4035 return ( rule , styleSheet ) => {
41- const isGlobal =
42- ! styleSheet . options . link &&
43- styleSheet . options . name &&
44- styleSheet . options . name . indexOf ( 'Mui' ) === 0 &&
45- ! disableGlobal ;
46-
47- if ( isGlobal ) {
48- if ( pseudoClasses . indexOf ( rule . key ) !== - 1 ) {
49- return rule . key ;
50- }
51-
52- if ( ! styleSheet . options . theme [ nested ] ) {
53- const prefix = `${ safePrefix ( styleSheet . options . name ) } ${ seed } ` ;
54-
55- if ( rule . key === 'root' ) {
56- return prefix ;
57- }
58- return `${ prefix } -${ rule . key } ` ;
59- }
60- }
61-
6236 ruleCounter += 1 ;
6337 warning (
6438 ruleCounter < 1e10 ,
@@ -68,15 +42,33 @@ export default function createGenerateClassName(options = {}) {
6842 ] . join ( '' ) ,
6943 ) ;
7044
45+ const name = styleSheet . options . name ;
46+
47+ // Is a global static MUI style?
48+ if ( name && name . indexOf ( 'Mui' ) === 0 && ! styleSheet . options . link && ! disableGlobal ) {
49+ // We can use a shorthand class name, we never use the keys to style the components.
50+ if ( pseudoClasses . indexOf ( rule . key ) !== - 1 ) {
51+ return rule . key ;
52+ }
53+
54+ const prefix = `${ name } ${ rule . key === 'root' ? '' : `-${ rule . key } ` } ${ classNameSeed } ` ;
55+
56+ if ( ! styleSheet . options . theme [ nested ] || seed !== '' ) {
57+ return prefix ;
58+ }
59+
60+ return `${ prefix } -${ ruleCounter } ` ;
61+ }
62+
7163 if ( process . env . NODE_ENV === 'production' && productionPrefix !== '' ) {
72- return `${ productionPrefix } ${ seed } ${ ruleCounter } ` ;
64+ return `${ productionPrefix } ${ classNameSeed } ${ ruleCounter } ` ;
7365 }
7466
75- const suffix = `${ rule . key } - ${ seed } ${ ruleCounter } ` ;
67+ const suffix = `${ rule . key } ${ classNameSeed } - ${ ruleCounter } ` ;
7668
7769 // Help with debuggability.
7870 if ( styleSheet . options . classNamePrefix ) {
79- return `${ safePrefix ( styleSheet . options . classNamePrefix ) } -${ suffix } ` ;
71+ return `${ styleSheet . options . classNamePrefix } -${ suffix } ` ;
8072 }
8173
8274 return suffix ;
0 commit comments