Skip to content

Commit

Permalink
Simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 25, 2019
1 parent f46a24a commit e925dc2
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/src/pages/css-in-js/advanced/GlobalClassName.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const StyledTextField = styled(TextField)`
label.focused {
color: green;
}
.MuiOutlinedInput {
.MuiOutlinedInput-root {
fieldset {
border-color: red;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/css-in-js/advanced/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ const useStyles = makeStyles({
generates the following class names you that can override:

```css
.MuiButton { /**/ }
.MuiButton-root { /**/ }
.MuiButton-label { /**/ }
.MuiButton-outlined { /**/ }
.MuiButton-outlined.disabled { /**/ }
Expand All @@ -502,7 +502,7 @@ const StyledTextField = styled(TextField)`
label.focused {
color: green; 💚
}
.MuiOutlinedInput {
.MuiOutlinedInput-root {
fieldset {
border-color: red; ❤️
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/css-in-js/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A function which returns [a class name generator function](http://cssinjs.org/js

1. `options` (*Object* [optional]):
- `options.disableGlobal` (*Boolan* [optional]): Defaults to `false`. Disable the generation of deterministic class names.
- `options.productionPrefix` (*String* [optional]): Defaults to `'jss'`. The string used to prefix the class names in production. You can disable the minification in production by providing an empty string.
- `options.productionPrefix` (*String* [optional]): Defaults to `'jss'`. The string used to prefix the class names in production.
- `options.seed` (*String* [optional]): Defaults to `''`. The string used to uniquely identify the generator. It can be used to avoid class name collisions when using multiple generators in the same document.

#### Returns
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/text-fields/CustomizedInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CssTextField = withStyles({
'& .MuiInput-underline:after': {
borderBottomColor: 'green',
},
'& .MuiOutlinedInput': {
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: 'red',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const pseudoClasses = [
// https://github.com/cssinjs/jss/blob/4e6a05dd3f7b6572fdd3ab216861d9e446c20331/src/utils/createGenerateClassName.js
export default function createGenerateClassName(options = {}) {
const { disableGlobal = false, productionPrefix = 'jss', seed = '' } = options;
const classNameSeed = seed === '' ? '' : `-${seed}`;
const seedPrefix = seed === '' ? '' : `${seed}-`;
let ruleCounter = 0;

return (rule, styleSheet) => {
Expand All @@ -51,7 +51,7 @@ export default function createGenerateClassName(options = {}) {
return rule.key;
}

const prefix = `${name}${rule.key === 'root' ? '' : `-${rule.key}`}${classNameSeed}`;
const prefix = `${seedPrefix}${name}-${rule.key}`;

if (!styleSheet.options.theme[nested] || seed !== '') {
return prefix;
Expand All @@ -60,17 +60,17 @@ export default function createGenerateClassName(options = {}) {
return `${prefix}-${ruleCounter}`;
}

if (process.env.NODE_ENV === 'production' && productionPrefix !== '') {
return `${productionPrefix}${classNameSeed}${ruleCounter}`;
if (process.env.NODE_ENV === 'production') {
return `${seedPrefix}${productionPrefix}${ruleCounter}`;
}

const suffix = `${rule.key}${classNameSeed}-${ruleCounter}`;
const suffix = `${rule.key}-${ruleCounter}`;

// Help with debuggability.
if (styleSheet.options.classNamePrefix) {
return `${styleSheet.options.classNamePrefix}-${suffix}`;
return `${seedPrefix}${styleSheet.options.classNamePrefix}-${suffix}`;
}

return suffix;
return `${seedPrefix}${suffix}`;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('createGenerateClassName', () => {
},
},
),
'MuiButton',
'MuiButton-root',
);
assert.strictEqual(
generateClassName(
Expand All @@ -91,7 +91,7 @@ describe('createGenerateClassName', () => {
},
},
),
'MuiButton-2',
'MuiButton-root-2',
);
});

Expand Down Expand Up @@ -128,9 +128,9 @@ describe('createGenerateClassName', () => {
);
});

it('should disable the minification', () => {
it('should use the seed', () => {
const generateClassName = createGenerateClassName({
productionPrefix: '',
seed: 'dark',
});
assert.strictEqual(
generateClassName(
Expand All @@ -139,7 +139,7 @@ describe('createGenerateClassName', () => {
options: {},
},
),
'root-1',
'dark-jss1',
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-styles/src/makeStyles/makeStyles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ describe('makeStyles', () => {
</ThemeProvider>,
);
assert.strictEqual(sheetsRegistry.registry.length, 1);
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField' });
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField-root' });
wrapper.setProps({ theme: createMuiTheme({ foo: 'bar' }) });
assert.strictEqual(sheetsRegistry.registry.length, 1);
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField' });
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField-root' });
});

it('should support the overrides key', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-styles/src/withStyles/withStyles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ describe('withStyles', () => {
</ThemeProvider>,
);
assert.strictEqual(sheetsRegistry.registry.length, 1);
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField' });
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField-root' });
wrapper.setProps({ theme: createMuiTheme({ foo: 'bar' }) });
assert.strictEqual(sheetsRegistry.registry.length, 1);
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField' });
assert.deepEqual(sheetsRegistry.registry[0].classes, { root: 'MuiTextField-root' });
});

it('should support the overrides key', () => {
Expand Down

0 comments on commit e925dc2

Please sign in to comment.