From 6c9e2917e74261c4b35ad7e17e54589fab63e366 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Thu, 2 Aug 2018 21:48:54 +0200 Subject: [PATCH] [styles] Improve the dangerouslyUseGlobalCSS story --- .../material-ui/src/styles/createGenerateClassName.js | 11 +++++------ .../src/styles/createGenerateClassName.test.js | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/material-ui/src/styles/createGenerateClassName.js b/packages/material-ui/src/styles/createGenerateClassName.js index 203d5ecdc59e84..f5802496ace75e 100644 --- a/packages/material-ui/src/styles/createGenerateClassName.js +++ b/packages/material-ui/src/styles/createGenerateClassName.js @@ -56,14 +56,13 @@ export default function createGenerateClassName(options = {}) { // Code branch the whole block at the expense of more code. if (dangerouslyUseGlobalCSS) { - if (styleSheet && styleSheet.options.classNamePrefix) { - const prefix = safePrefix(styleSheet.options.classNamePrefix); - - if (prefix.match(/^Mui/)) { - return `${prefix}-${rule.key}`; + if (styleSheet) { + if (styleSheet.options.name) { + return `${styleSheet.options.name}-${rule.key}`; } - if (process.env.NODE_ENV !== 'production') { + if (styleSheet.options.classNamePrefix && process.env.NODE_ENV !== 'production') { + const prefix = safePrefix(styleSheet.options.classNamePrefix); return `${prefix}-${rule.key}-${ruleCounter}`; } } diff --git a/packages/material-ui/src/styles/createGenerateClassName.test.js b/packages/material-ui/src/styles/createGenerateClassName.test.js index 9b4a1b943ac763..c3dbafdde836b7 100644 --- a/packages/material-ui/src/styles/createGenerateClassName.test.js +++ b/packages/material-ui/src/styles/createGenerateClassName.test.js @@ -58,12 +58,13 @@ describe('createGenerateClassName', () => { }, { options: { - classNamePrefix: 'MuiButton', + name: 'Button', + classNamePrefix: 'Button2', jss: {}, }, }, ), - 'MuiButton-root', + 'Button-root', ); assert.strictEqual( generateClassName(