Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlessified #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions material-ui.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
4 changes: 2 additions & 2 deletions packages/material-ui-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@material-ui/icons",
"private": true,
"name": "@unless.com/material-ui-icons",
"private": false,
"author": "Material-UI Team",
"version": "3.0.1",
"description": "Material Design Svg Icons converted to Material-UI React components.",
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@material-ui/core",
"private": true,
"name": "@unless.com/material-ui-core",
"private": false,
"author": "Material-UI Team",
"version": "3.1.2",
"description": "React components that implement Google's Material Design.",
Expand Down
64 changes: 7 additions & 57 deletions packages/material-ui/src/styles/createGenerateClassName.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,16 @@
/* eslint-disable no-underscore-dangle */

import warning from 'warning';

const escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g;

function safePrefix(classNamePrefix) {
const prefix = String(classNamePrefix);
warning(prefix.length < 256, `Material-UI: the class name prefix is too long: ${prefix}.`);
// Sanitize the string as will be used to prefix the generated class name.
return prefix.replace(escapeRegex, '-');
}

// Returns a function which generates unique class names based on counters.
// When new generator function is created, rule counter is reset.
// We need to reset the rule counter for SSR for each request.
//
// It's inspired by
// https://github.com/cssinjs/jss/blob/4e6a05dd3f7b6572fdd3ab216861d9e446c20331/src/utils/createGenerateClassName.js
export default function createGenerateClassName(options = {}) {
const { dangerouslyUseGlobalCSS = false, productionPrefix = 'jss', seed = '' } = options;
let ruleCounter = 0;

return (rule, styleSheet) => {
ruleCounter += 1;
warning(
ruleCounter < 1e10,
[
'Material-UI: you might have a memory leak.',
'The ruleCounter is not supposed to grow that much.',
].join(''),
);

// Code branch the whole block at the expense of more code.
if (dangerouslyUseGlobalCSS) {
if (styleSheet) {
if (styleSheet.options.name) {
return `${styleSheet.options.name}-${rule.key}`;
}

if (styleSheet.options.classNamePrefix && process.env.NODE_ENV !== 'production') {
const prefix = safePrefix(styleSheet.options.classNamePrefix);
return `${prefix}-${rule.key}-${seed}${ruleCounter}`;
}
}

if (process.env.NODE_ENV === 'production') {
return `${productionPrefix}${seed}${ruleCounter}`;
}

return `${rule.key}-${seed}${ruleCounter}`;
}

if (process.env.NODE_ENV === 'production') {
return `${productionPrefix}${seed}${ruleCounter}`;
if (styleSheet.options.classNamePrefix) {
return `${styleSheet.options.classNamePrefix}-${rule.key}`
}

if (styleSheet && styleSheet.options.classNamePrefix) {
const prefix = safePrefix(styleSheet.options.classNamePrefix);

return `${prefix}-${rule.key}-${seed}${ruleCounter}`;
if (styleSheet.options.name) {
return `${styleSheet.options.name}-${rule.key}`
}

return `${rule.key}-${seed}${ruleCounter}`;
ruleCounter += 1;
return `txt-${rule.key}-${ruleCounter}`
};
}