From 168e11abd225934ba5b7ce96ccc90907d119137e Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Wed, 26 Aug 2015 20:45:16 +0100
Subject: [PATCH 001/229] Added useModuleName.
---
README.md | 23 ++++++++++++++++++++---
dist/index.js | 4 ++++
dist/linkClass.js | 14 +++++++++++---
src/index.js | 4 ++++
src/linkClass.js | 14 +++++++++++---
5 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 9221f03..1ac8d2e 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ React CSS Modules implement automatic mapping of class names to CSS modules. Eve
- [Browserify](#browserify)
- [Decorator](#decorator)
- [Options](#options)
+ - [`useModuleName`](#usemodulename)
- [`allowMultiple`](#allowmultiple)
- [`keepOriginal`](#keeporiginal)
- [`errorNotFound`](#errornotfound)
@@ -191,9 +192,21 @@ or as a second parameter when using `CSSModules` as a decorator:
@CSSModules(styles, options);
```
+#### `useModuleName`
+
+Default: `false`.
+
+When enabled then CSS Modules are loaded using `moduleName` property and `className` is used only for global CSS, e.g.
+
+```js
+
+```
+
#### `allowMultiple`
-Allows multiple CSS class names. Default: `true`.
+Default: `true`.
+
+Allows multiple CSS class names.
When `false`, the following will cause an error:
@@ -203,7 +216,9 @@ When `false`, the following will cause an error:
#### `keepOriginal`
-Keeps original CSS class name in addition to the names of the CSS Modules. Default: `true`.
+Default: `true`.
+
+Keeps original CSS class name in addition to the names of the CSS Modules.
When `true`, the following `ReactElement`:
@@ -215,7 +230,9 @@ will be rendered with a `className` property `foo component__foo___2w27N bar com
#### `errorNotFound`
-Throws an error when class name cannot be mapped to a CSS Module. Default: `false`.
+Default: `false`.
+
+Throws an error when class name cannot be mapped to a CSS Module.
## SASS, SCSS, LESS and other CSS Preprocessors
diff --git a/dist/index.js b/dist/index.js
index 7477f0a..6424571 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -56,6 +56,10 @@ functionConstructor = function (Component, styles) {
options.errorNotFound = false;
}
+ if (options.useModuleNames !== true) {
+ options.useModuleNames = false;
+ }
+
return (0, _linkClass2['default'])(_get(Object.getPrototypeOf(_class.prototype), 'render', this).call(this), styles, options);
}
}]);
diff --git a/dist/linkClass.js b/dist/linkClass.js
index 3b8fc21..b296ed5 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -17,6 +17,7 @@ var linkClass = undefined;
* @property {Boolean} allowMultiple Determines whether `className` can have multiple class names. Throws an error when the constrained is not met. Default: true.
* @property {Boolean} keepOriginal Determines whether the original `className` value is kept in addition to the appended CSS modules styles CSS class name. Default: true.
* @property {Boolean} errorNotFound Determines whether an error is raised if `className` defines a CSS class(es) that is not present in the CSS modules styles. Default: false.
+ * @property {Boolean} useModuleName When enabled then CSS Modules are loaded using `moduleName` property and `className` is used only for global CSS. Default: false.
*/
/**
@@ -32,10 +33,17 @@ linkClass = function (element) {
var newProps = undefined,
newClassName = undefined,
newChildren = undefined,
- childrenCount = undefined;
+ childrenCount = undefined,
+ moduleName = undefined;
- if (element.props.className) {
- newClassName = element.props.className.split(' ');
+ if (options.useModuleName) {
+ moduleName = element.props.moduleName;
+ } else {
+ moduleName = element.props.className;
+ }
+
+ if (moduleName) {
+ newClassName = moduleName.split(' ');
if (options.allowMultiple === false && newClassName.length > 1) {
throw new Error('ReactElement defines multiple class names ("' + element.props.className + '") in className declaration.');
diff --git a/src/index.js b/src/index.js
index 0c71a14..b3fce2f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -26,6 +26,10 @@ functionConstructor = (Component, styles, options = {}) => {
options.errorNotFound = false;
}
+ if (options.useModuleNames !== true) {
+ options.useModuleNames = false;
+ }
+
return linkClass(super.render(), styles, options);
}
};
diff --git a/src/linkClass.js b/src/linkClass.js
index c2f6993..acecc8b 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -7,6 +7,7 @@ let linkClass;
* @property {Boolean} allowMultiple Determines whether `className` can have multiple class names. Throws an error when the constrained is not met. Default: true.
* @property {Boolean} keepOriginal Determines whether the original `className` value is kept in addition to the appended CSS modules styles CSS class name. Default: true.
* @property {Boolean} errorNotFound Determines whether an error is raised if `className` defines a CSS class(es) that is not present in the CSS modules styles. Default: false.
+ * @property {Boolean} useModuleName When enabled then CSS Modules are loaded using `moduleName` property and `className` is used only for global CSS. Default: false.
*/
/**
@@ -19,10 +20,17 @@ linkClass = (element, styles = {}, options = {}) => {
let newProps,
newClassName,
newChildren,
- childrenCount;
+ childrenCount,
+ moduleName;
- if (element.props.className) {
- newClassName = element.props.className.split(' ');
+ if (options.useModuleName) {
+ moduleName = element.props.moduleName;
+ } else {
+ moduleName = element.props.className;
+ }
+
+ if (moduleName) {
+ newClassName = moduleName.split(' ');
if (options.allowMultiple === false && newClassName.length > 1) {
throw new Error(`ReactElement defines multiple class names ("${element.props.className}") in className declaration.`);
From 5ad88aa691811080581d9f4fd90008bca931f5a6 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Wed, 26 Aug 2015 20:52:42 +0100
Subject: [PATCH 002/229] includeOriginal must be false when useModulName is
true
---
dist/linkClass.js | 2 ++
src/linkClass.js | 2 ++
test/linkClass.js | 17 +++++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/dist/linkClass.js b/dist/linkClass.js
index b296ed5..82883fb 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -38,6 +38,8 @@ linkClass = function (element) {
if (options.useModuleName) {
moduleName = element.props.moduleName;
+
+ options.includeOriginal = false;
} else {
moduleName = element.props.className;
}
diff --git a/src/linkClass.js b/src/linkClass.js
index acecc8b..1dcdbb4 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -25,6 +25,8 @@ linkClass = (element, styles = {}, options = {}) => {
if (options.useModuleName) {
moduleName = element.props.moduleName;
+
+ options.includeOriginal = false;
} else {
moduleName = element.props.className;
}
diff --git a/test/linkClass.js b/test/linkClass.js
index 9c58286..b9b7c82 100644
--- a/test/linkClass.js
+++ b/test/linkClass.js
@@ -129,6 +129,23 @@ describe('linkClass', () => {
});
});
+ describe('when options.useModuleName is true', () => {
+ it('does not lookup the className property', () => {
+ let subject;
+
+ subject = linkClass(, {foo: 'foo-1'}, {useModuleName: true});
+
+ expect(subject.props.className).to.equal('foo');
+ });
+ it('appends CSS Modules using modulName', () => {
+ let subject;
+
+ subject = linkClass(, {foo: 'foo-1'}, {useModuleName: true});
+
+ expect(subject.props.className).to.equal('foo-1');
+ });
+ });
+
describe('when options.allowMultiple is false', () => {
describe('when it finds multiple CSS class names in a className', () => {
it('throws an error', () => {
From afeb2667ee69a8c7ca8a75da57f682341d3e997c Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Wed, 26 Aug 2015 20:52:49 +0100
Subject: [PATCH 003/229] 1.2.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 2f5fc53..3bb785a 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "1.1.0",
+ "version": "1.2.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
From 60c1f69d5b61834ab1b108fb4b6bd3363b91ba54 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Wed, 26 Aug 2015 21:35:36 +0100
Subject: [PATCH 004/229] Stricted config validation.
---
dist/index copy.js | 127 ---------------------------------------------
dist/index.js | 22 ++------
dist/linkClass.js | 8 ---
dist/makeConfig.js | 60 +++++++++++++++++++++
dist/utils.js | 26 ++++++++++
src/index.js | 19 +------
src/linkClass.js | 8 ---
src/makeConfig.js | 50 ++++++++++++++++++
src/utils.js | 9 ++++
test/makeConfig.js | 54 +++++++++++++++++++
10 files changed, 206 insertions(+), 177 deletions(-)
delete mode 100644 dist/index copy.js
create mode 100644 dist/makeConfig.js
create mode 100644 dist/utils.js
create mode 100644 src/makeConfig.js
create mode 100644 src/utils.js
create mode 100644 test/makeConfig.js
diff --git a/dist/index copy.js b/dist/index copy.js
deleted file mode 100644
index 2a27213..0000000
--- a/dist/index copy.js
+++ /dev/null
@@ -1,127 +0,0 @@
-'use strict';
-
-Object.defineProperty(exports, '__esModule', {
- value: true
-});
-
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
-
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
-
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
-
-function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
-
-var _react = require('react');
-
-var _react2 = _interopRequireDefault(_react);
-
-var _reactDom = require('react-dom');
-
-var _reactDom2 = _interopRequireDefault(_reactDom);
-
-var _lodashLangIsArray = require('lodash/lang/isArray');
-
-var _lodashLangIsArray2 = _interopRequireDefault(_lodashLangIsArray);
-
-var _lodash = require('lodash');
-
-var _lodash2 = _interopRequireDefault(_lodash);
-
-var unfreeze = undefined;
-
-/**
- * Make a shallow copy of the object.
- *
- * @param {Object} source Frozen object.
- * @return {Object}
- */
-unfreeze = function (source) {
- var property = undefined,
- target = undefined;
-
- target = {};
-
- for (property in source) {
- target[property] = source[property];
- }
-
- return target;
-};
-
-/**
- * @param {ReactClass} Target
- * @return {ReactClass}
- */
-
-exports['default'] = function (Target, styles) {
- var linkClass = undefined;
-
- console.log('styles', styles);
-
- /**
- * @param {ReactElement} element
- * @return {ReactElement}
- */
- linkClass = function (element) {
- var isFrozen = undefined;
-
- if (Object.isFrozen && Object.isFrozen(element)) {
- isFrozen = true;
-
- // https://github.com/facebook/react/blob/v0.13.3/src/classic/element/ReactElement.js#L131
- element = unfreeze(element);
- element.props = unfreeze(element.props);
- }
-
- if (element.props.className) {
- element.props.className = element.props.className.split(' ').map(function (className) {
- if (styles[className]) {
- return className + ' ' + styles[className];
- } else {
- return className;
- }
- }).join(' ');
- }
-
- if ((0, _lodashLangIsArray2['default'])(element.props.children)) {
- element.props.children = element.props.children.map(function (node) {
- if (_react2['default'].isValidElement(node)) {
- return linkClass(node);
- } else {
- return node;
- }
- });
- }
-
- if (isFrozen) {
- Object.freeze(element);
- Object.freeze(element.props);
- }
-
- return element;
- };
-
- return (function (_Target) {
- _inherits(_class, _Target);
-
- function _class() {
- _classCallCheck(this, _class);
-
- _get(Object.getPrototypeOf(_class.prototype), 'constructor', this).apply(this, arguments);
- }
-
- _createClass(_class, [{
- key: 'render',
- value: function render() {
- return linkClass(_get(Object.getPrototypeOf(_class.prototype), 'render', this).call(this));
- }
- }]);
-
- return _class;
- })(Target);
-};
-
-module.exports = exports['default'];
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
index 6424571..b99afe3 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -18,6 +18,10 @@ var _linkClass = require('./linkClass');
var _linkClass2 = _interopRequireDefault(_linkClass);
+var _makeConfig = require('./makeConfig');
+
+var _makeConfig2 = _interopRequireDefault(_makeConfig);
+
var functionConstructor = undefined,
decoratorConstructor = undefined;
@@ -44,23 +48,7 @@ functionConstructor = function (Component, styles) {
_createClass(_class, [{
key: 'render',
value: function render() {
- if (options.allowMultiple !== false) {
- options.allowMultiple = true;
- }
-
- if (options.includeOriginal !== false) {
- options.includeOriginal = true;
- }
-
- if (options.errorNotFound !== true) {
- options.errorNotFound = false;
- }
-
- if (options.useModuleNames !== true) {
- options.useModuleNames = false;
- }
-
- return (0, _linkClass2['default'])(_get(Object.getPrototypeOf(_class.prototype), 'render', this).call(this), styles, options);
+ return (0, _linkClass2['default'])(_get(Object.getPrototypeOf(_class.prototype), 'render', this).call(this), styles, (0, _makeConfig2['default'])(options));
}
}]);
diff --git a/dist/linkClass.js b/dist/linkClass.js
index 82883fb..d258b34 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -12,14 +12,6 @@ var _react2 = _interopRequireDefault(_react);
var linkClass = undefined;
-/**
- * @typedef CSSModules~Options
- * @property {Boolean} allowMultiple Determines whether `className` can have multiple class names. Throws an error when the constrained is not met. Default: true.
- * @property {Boolean} keepOriginal Determines whether the original `className` value is kept in addition to the appended CSS modules styles CSS class name. Default: true.
- * @property {Boolean} errorNotFound Determines whether an error is raised if `className` defines a CSS class(es) that is not present in the CSS modules styles. Default: false.
- * @property {Boolean} useModuleName When enabled then CSS Modules are loaded using `moduleName` property and `className` is used only for global CSS. Default: false.
- */
-
/**
* @param {ReactElement} element
* @param {Object} styles CSS modules class map.
diff --git a/dist/makeConfig.js b/dist/makeConfig.js
new file mode 100644
index 0000000..9f3808a
--- /dev/null
+++ b/dist/makeConfig.js
@@ -0,0 +1,60 @@
+'use strict';
+
+Object.defineProperty(exports, '__esModule', {
+ value: true
+});
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+var _utils = require('./utils');
+
+var _utils2 = _interopRequireDefault(_utils);
+
+/**
+ * @see {@link https://github.com/gajus/react-css-modules#options}
+ * @property {Boolean} allowMultiple
+ * @property {Boolean} keepOriginal
+ * @property {Boolean} errorNotFound
+ * @property {Boolean} useModuleNam
+ */
+
+exports['default'] = function () {
+ var userConfig = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
+
+ var knownProperties = undefined,
+ unknownProperties = undefined;
+
+ knownProperties = ['allowMultiple', 'includeOriginal', 'errorNotFound', 'useModuleName'];
+
+ unknownProperties = _utils2['default'].difference(_utils2['default'].keys(userConfig), knownProperties);
+
+ if (unknownProperties.length) {
+ throw new Error('Unknown config property "' + unknownProperties[0] + '".');
+ }
+
+ _utils2['default'].forEach(userConfig, function (value, name) {
+ if (typeof value !== 'boolean') {
+ throw new Error('"' + name + '" property value must be a boolean.');
+ }
+ });
+
+ if (typeof userConfig.allowMultiple === 'undefined') {
+ userConfig.allowMultiple = true;
+ }
+
+ if (typeof userConfig.includeOriginal === 'undefined') {
+ userConfig.includeOriginal = true;
+ }
+
+ if (typeof userConfig.errorNotFound === 'undefined') {
+ userConfig.errorNotFound = false;
+ }
+
+ if (typeof userConfig.useModuleName === 'undefined') {
+ userConfig.useModuleName = false;
+ }
+
+ return userConfig;
+};
+
+module.exports = exports['default'];
\ No newline at end of file
diff --git a/dist/utils.js b/dist/utils.js
new file mode 100644
index 0000000..94ee160
--- /dev/null
+++ b/dist/utils.js
@@ -0,0 +1,26 @@
+'use strict';
+
+Object.defineProperty(exports, '__esModule', {
+ value: true
+});
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+var _lodashObjectKeys = require('lodash/object/keys');
+
+var _lodashObjectKeys2 = _interopRequireDefault(_lodashObjectKeys);
+
+var _lodashArrayDifference = require('lodash/array/difference');
+
+var _lodashArrayDifference2 = _interopRequireDefault(_lodashArrayDifference);
+
+var _lodashCollectionForEach = require('lodash/collection/forEach');
+
+var _lodashCollectionForEach2 = _interopRequireDefault(_lodashCollectionForEach);
+
+exports['default'] = {
+ keys: _lodashObjectKeys2['default'],
+ difference: _lodashArrayDifference2['default'],
+ forEach: _lodashCollectionForEach2['default']
+};
+module.exports = exports['default'];
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index b3fce2f..f933809 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,5 @@
import linkClass from './linkClass';
+import makeConfig from './makeConfig';
let functionConstructor,
decoratorConstructor;
@@ -14,23 +15,7 @@ let functionConstructor,
functionConstructor = (Component, styles, options = {}) => {
return class extends Component {
render () {
- if (options.allowMultiple !== false) {
- options.allowMultiple = true;
- }
-
- if (options.includeOriginal !== false) {
- options.includeOriginal = true;
- }
-
- if (options.errorNotFound !== true) {
- options.errorNotFound = false;
- }
-
- if (options.useModuleNames !== true) {
- options.useModuleNames = false;
- }
-
- return linkClass(super.render(), styles, options);
+ return linkClass(super.render(), styles, makeConfig(options));
}
};
};
diff --git a/src/linkClass.js b/src/linkClass.js
index 1dcdbb4..d54a045 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -2,14 +2,6 @@ import React from 'react';
let linkClass;
-/**
- * @typedef CSSModules~Options
- * @property {Boolean} allowMultiple Determines whether `className` can have multiple class names. Throws an error when the constrained is not met. Default: true.
- * @property {Boolean} keepOriginal Determines whether the original `className` value is kept in addition to the appended CSS modules styles CSS class name. Default: true.
- * @property {Boolean} errorNotFound Determines whether an error is raised if `className` defines a CSS class(es) that is not present in the CSS modules styles. Default: false.
- * @property {Boolean} useModuleName When enabled then CSS Modules are loaded using `moduleName` property and `className` is used only for global CSS. Default: false.
- */
-
/**
* @param {ReactElement} element
* @param {Object} styles CSS modules class map.
diff --git a/src/makeConfig.js b/src/makeConfig.js
new file mode 100644
index 0000000..d3c66f7
--- /dev/null
+++ b/src/makeConfig.js
@@ -0,0 +1,50 @@
+import _ from './utils';
+
+/**
+ * @see {@link https://github.com/gajus/react-css-modules#options}
+ * @property {Boolean} allowMultiple
+ * @property {Boolean} keepOriginal
+ * @property {Boolean} errorNotFound
+ * @property {Boolean} useModuleNam
+ */
+export default (userConfig = {}) => {
+ let knownProperties,
+ unknownProperties;
+
+ knownProperties = [
+ 'allowMultiple',
+ 'includeOriginal',
+ 'errorNotFound',
+ 'useModuleName'
+ ];
+
+ unknownProperties = _.difference(_.keys(userConfig), knownProperties);
+
+ if (unknownProperties.length) {
+ throw new Error(`Unknown config property "${unknownProperties[0]}".`);
+ }
+
+ _.forEach(userConfig, (value, name) => {
+ if (typeof value !== 'boolean') {
+ throw new Error(`"${name}" property value must be a boolean.`);
+ }
+ });
+
+ if (typeof userConfig.allowMultiple === 'undefined') {
+ userConfig.allowMultiple = true;
+ }
+
+ if (typeof userConfig.includeOriginal === 'undefined') {
+ userConfig.includeOriginal = true;
+ }
+
+ if (typeof userConfig.errorNotFound === 'undefined') {
+ userConfig.errorNotFound = false;
+ }
+
+ if (typeof userConfig.useModuleName === 'undefined') {
+ userConfig.useModuleName = false;
+ }
+
+ return userConfig;
+};
diff --git a/src/utils.js b/src/utils.js
new file mode 100644
index 0000000..861dd24
--- /dev/null
+++ b/src/utils.js
@@ -0,0 +1,9 @@
+import keys from 'lodash/object/keys';
+import difference from 'lodash/array/difference';
+import forEach from 'lodash/collection/forEach';
+
+export default {
+ keys,
+ difference,
+ forEach
+};
diff --git a/test/makeConfig.js b/test/makeConfig.js
new file mode 100644
index 0000000..3b8edad
--- /dev/null
+++ b/test/makeConfig.js
@@ -0,0 +1,54 @@
+import {
+ expect
+} from 'chai';
+
+import makeConfig from './../dist/makeConfig';
+
+describe('makeConfig', () => {
+ describe('when using default config', () => {
+ let options;
+ beforeEach(() => {
+ options = makeConfig();
+ });
+ describe('allowMultiple property', () => {
+ it('defaults to true', () => {
+ expect(options.allowMultiple).to.equal(true);
+ });
+ });
+ describe('includeOriginal property', () => {
+ it('defaults to true', () => {
+ expect(options.includeOriginal).to.equal(true);
+ });
+ });
+
+ describe('errorNotFound property', () => {
+ it('defaults to true', () => {
+ expect(options.errorNotFound).to.equal(false);
+ });
+ });
+
+ describe('useModuleName property', () => {
+ it('defaults to true', () => {
+ expect(options.useModuleName).to.equal(false);
+ });
+ });
+ });
+ describe('when unknown property is provided', () => {
+ it('throws an error', () => {
+ expect(() => {
+ makeConfig({
+ unknownProperty: true
+ });
+ }).to.throw(Error, 'Unknown config property "unknownProperty".');
+ });
+ });
+ describe('when property value is not boolean', () => {
+ it('throws an error', () => {
+ expect(() => {
+ makeConfig({
+ useModuleName: 1
+ });
+ }).to.throw(Error, '"useModuleName" property value must be a boolean.');
+ });
+ });
+});
From d45feb69c361f1d042876bd3541b63ffec69f451 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Wed, 26 Aug 2015 21:35:43 +0100
Subject: [PATCH 005/229] 1.3.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 3bb785a..6778312 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "1.2.0",
+ "version": "1.3.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
From 015c86094e9870548b0a2f67df15aa9f7c115413 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Wed, 26 Aug 2015 22:01:20 +0100
Subject: [PATCH 006/229] Use eslint in the build process.
---
.eslintrc | 9 ++++++---
dist/index.js | 4 ++--
dist/linkClass.js | 15 ++++++++-------
dist/makeConfig.js | 1 +
package.json | 5 ++++-
src/index.js | 4 ++--
src/linkClass.js | 17 +++++++++--------
src/makeConfig.js | 1 +
test/linkClass.js | 2 +-
test/makeConfig.js | 1 +
10 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index 140c7d1..a2a446a 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -254,7 +254,7 @@
"no-array-constructor": 2,
"no-continue": 2,
"no-inline-comments": 2,
- "no-lonely-if": 2,
+ "no-lonely-if": 0,
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": [
2,
@@ -382,9 +382,12 @@
"react"
],
"parser": "babel-eslint",
+ "globals": {
+ "global": true
+ },
"env": {
- "browser": true
- // "mocha": true,
+ "browser": true,
+ "mocha": true
// "node": true
}
}
diff --git a/dist/index.js b/dist/index.js
index b99afe3..a4008bd 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -22,8 +22,8 @@ var _makeConfig = require('./makeConfig');
var _makeConfig2 = _interopRequireDefault(_makeConfig);
-var functionConstructor = undefined,
- decoratorConstructor = undefined;
+var decoratorConstructor = undefined,
+ functionConstructor = undefined;
/**
* When used as a function.
diff --git a/dist/linkClass.js b/dist/linkClass.js
index d258b34..d28ab89 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -22,11 +22,12 @@ linkClass = function (element) {
var styles = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
- var newProps = undefined,
- newClassName = undefined,
+ var childrenCount = undefined,
+ clonedElement = undefined,
+ moduleName = undefined,
newChildren = undefined,
- childrenCount = undefined,
- moduleName = undefined;
+ newClassName = undefined,
+ newProps = undefined;
if (options.useModuleName) {
moduleName = element.props.moduleName;
@@ -95,12 +96,12 @@ linkClass = function (element) {
}
if (newChildren) {
- element = _react2['default'].cloneElement(element, newProps, newChildren);
+ clonedElement = _react2['default'].cloneElement(element, newProps, newChildren);
} else {
- element = _react2['default'].cloneElement(element, newProps);
+ clonedElement = _react2['default'].cloneElement(element, newProps);
}
- return element;
+ return clonedElement;
};
exports['default'] = linkClass;
diff --git a/dist/makeConfig.js b/dist/makeConfig.js
index 9f3808a..dbff05c 100644
--- a/dist/makeConfig.js
+++ b/dist/makeConfig.js
@@ -16,6 +16,7 @@ var _utils2 = _interopRequireDefault(_utils);
* @property {Boolean} keepOriginal
* @property {Boolean} errorNotFound
* @property {Boolean} useModuleNam
+ * @return {Object}
*/
exports['default'] = function () {
diff --git a/package.json b/package.json
index 6778312..71a46e1 100644
--- a/package.json
+++ b/package.json
@@ -27,14 +27,17 @@
},
"devDependencies": {
"babel": "^5.8.21",
+ "babel-eslint": "^4.1.0",
"chai": "^3.2.0",
+ "eslint": "^1.2.1",
+ "eslint-plugin-react": "^3.3.0",
"jsdom": "^6.2.0",
"mocha": "^2.2.5",
"react": "^0.14.0-beta3",
"react-addons-test-utils": "^0.14.0-beta3"
},
"scripts": {
- "test": "mocha",
+ "test": "./node_modules/.bin/eslint ./src/ ./test/ && mocha",
"build": "babel ./src/ --out-dir ./dist/",
"watch": "babel --watch ./src/ --out-dir ./dist/"
}
diff --git a/src/index.js b/src/index.js
index f933809..7bb6ecb 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,8 +1,8 @@
import linkClass from './linkClass';
import makeConfig from './makeConfig';
-let functionConstructor,
- decoratorConstructor;
+let decoratorConstructor,
+ functionConstructor;
/**
* When used as a function.
diff --git a/src/linkClass.js b/src/linkClass.js
index d54a045..82fb397 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -9,11 +9,12 @@ let linkClass;
* @return {ReactElement}
*/
linkClass = (element, styles = {}, options = {}) => {
- let newProps,
- newClassName,
+ let childrenCount,
+ clonedElement,
+ moduleName,
newChildren,
- childrenCount,
- moduleName;
+ newClassName,
+ newProps;
if (options.useModuleName) {
moduleName = element.props.moduleName;
@@ -50,7 +51,7 @@ linkClass = (element, styles = {}, options = {}) => {
}
});
- newClassName = newClassName.filter(function (className) {
+ newClassName = newClassName.filter((className) => {
return className.length;
});
@@ -83,12 +84,12 @@ linkClass = (element, styles = {}, options = {}) => {
}
if (newChildren) {
- element = React.cloneElement(element, newProps, newChildren);
+ clonedElement = React.cloneElement(element, newProps, newChildren);
} else {
- element = React.cloneElement(element, newProps);
+ clonedElement = React.cloneElement(element, newProps);
}
- return element;
+ return clonedElement;
};
export default linkClass;
diff --git a/src/makeConfig.js b/src/makeConfig.js
index d3c66f7..9d860ea 100644
--- a/src/makeConfig.js
+++ b/src/makeConfig.js
@@ -6,6 +6,7 @@ import _ from './utils';
* @property {Boolean} keepOriginal
* @property {Boolean} errorNotFound
* @property {Boolean} useModuleNam
+ * @return {Object}
*/
export default (userConfig = {}) => {
let knownProperties,
diff --git a/test/linkClass.js b/test/linkClass.js
index b9b7c82..12d158a 100644
--- a/test/linkClass.js
+++ b/test/linkClass.js
@@ -169,7 +169,7 @@ describe('linkClass', () => {
describe('when options.errorNotFound is true', () => {
it('throws an error when className defines a CSS class that does not exist in CSS modules styles', () => {
expect(() => {
- linkClass(, {}, {errorNotFound: true})
+ linkClass(, {}, {errorNotFound: true});
}).to.throw(Error, '"foo" CSS class name is not found in CSS modules styles.');
});
});
diff --git a/test/makeConfig.js b/test/makeConfig.js
index 3b8edad..465cb74 100644
--- a/test/makeConfig.js
+++ b/test/makeConfig.js
@@ -7,6 +7,7 @@ import makeConfig from './../dist/makeConfig';
describe('makeConfig', () => {
describe('when using default config', () => {
let options;
+
beforeEach(() => {
options = makeConfig();
});
From ed12c02dcfb9544146782a5bd3ec138f3a762003 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:12:11 +0100
Subject: [PATCH 007/229] V2 using moduleName.
---
README.md | 124 ++++++++++++++++-------------------
dist/index.js | 4 +-
dist/linkClass.js | 56 +++++++---------
dist/makeConfig.js | 27 ++++----
src/index.js | 4 +-
src/linkClass.js | 56 +++++++---------
src/makeConfig.js | 29 ++++----
test/linkClass.js | 160 ++++++++++++++++++---------------------------
test/makeConfig.js | 29 ++------
9 files changed, 198 insertions(+), 291 deletions(-)
diff --git a/README.md b/README.md
index 1ac8d2e..3f9d770 100644
--- a/README.md
+++ b/README.md
@@ -3,28 +3,27 @@
[](https://travis-ci.org/gajus/react-css-modules)
[](https://www.npmjs.org/package/react-css-modules)
-React CSS Modules implement automatic mapping of class names to CSS modules. Every CSS class is assigned a local-scoped identifier with a global unique name. CSS Modules enable a modular and reusable CSS!
+React CSS Modules implement automatic mapping of CSS modules. Every CSS class is assigned a local-scoped identifier with a global unique name. CSS Modules enable a modular and reusable CSS!
- [What's the Problem?](#whats-the-problem)
+- [The Implementation](#theimplementation)
- [Usage](#usage)
- [Module Bundler](#module-bundler)
- [webpack](#webpack)
- [Browserify](#browserify)
- [Decorator](#decorator)
- [Options](#options)
- - [`useModuleName`](#usemodulename)
- [`allowMultiple`](#allowmultiple)
- - [`keepOriginal`](#keeporiginal)
- - [`errorNotFound`](#errornotfound)
+ - [`errorWhenNotFound`](#errorwhennotfound)
- [SASS, SCSS, LESS and other CSS Preprocessors](#sass-scss-less-and-other-css-preprocessors)
- [Global CSS](#global-css)
- [Multiple CSS Classes](#multiple-css-classes)
## What's the Problem?
-[CSS modules](https://github.com/css-modules/css-modules) are awesome. If you are not familiar with CSS modules, it is a concept of using a module bundler such as [webpack](http://webpack.github.io/docs/) to load CSS scoped to a particular document. CSS modules loader will generate a unique name for a each CSS class at the time of loading the CSS. Refer to [webpack-demo](https://css-modules.github.io/webpack-demo/) for a full example.
+[CSS Modules](https://github.com/css-modules/css-modules) are awesome. If you are not familiar with CSS Modules, it is a concept of using a module bundler such as [webpack](http://webpack.github.io/docs/) to load CSS scoped to a particular document. CSS module loader will generate a unique name for a each CSS class at the time of loading the CSS document ([Interoperable CSS](https://github.com/css-modules/icss) to be precise). To see CSS Modules in practice, [webpack-demo](https://css-modules.github.io/webpack-demo/).
-In the context of React, this looks like this:
+In the context of React, CSS Modules look like this:
```js
import React from 'react';
@@ -43,9 +42,9 @@ export default class Car extends React.Component {
Rendering the component will produce a markup similar to:
```js
-
-
front-door
-
back-door
+
```
@@ -57,8 +56,10 @@ However, this approach has several disadvantages:
* You have to use `camelCase` CSS class names.
* You have to use `styles` object whenever constructing a `className`.
+* Mixing CSS Modules and global CSS classes is cumbersome.
+* Reference to an undefined CSS Module resolves to `undefined` without a warning.
-React CSS Modules enables seamless CSS modules for React, e.g.
+React CSS Modules component automates loading of CSS Modules using `moduleName` property, e.g.
```js
import React from 'react';
@@ -67,9 +68,9 @@ import CSSModules from 'react-css-modules';
class Car extends React.Component {
render () {
- return
-
-
+ return
;
}
}
@@ -77,9 +78,22 @@ class Car extends React.Component {
export default CSSModules(Car, styles);
```
-`CSSModules` extends `Car` `render` method. It will look for CSS classes in `./car.css` that match CSS class names in `ReactElement` `className` and will replace/append the matching unique class names to `className` declaration.
+Using `react-css-modules`:
+
+* You are not forced to use the `camelCase` naming convention.
+* You do not need to refer to the `styles` object every time you use a CSS Module.
+* There is clear distinction between global CSS and CSS Modules, e.g.
+
+```js
+
+```
+
+* You are warned when `moduleName` refers to an undefined CSS Module ([`errorWhenNotFound`](#errorwhennotfound) option).
+* You can enforce use of a single CSS module per `ReactElement` ([`allowMultiple`](#allowmultiple) option).
-Refer to the [react-css-modules-examples](https://github.com/gajus/react-css-modules-examples) repository for a complete usage example.
+## The Implementation
+
+`react-css-modules` extends `render` method of the target component. It will use the value of `moduleName` to look for CSS Modules in the associated styles object and will append the matching unique CSS class names to the `ReactElement` `className` property value.
[Awesome!](https://twitter.com/intent/retweet?tweet_id=636497036603428864)
@@ -87,7 +101,7 @@ Refer to the [react-css-modules-examples](https://github.com/gajus/react-css-mod
Setup consists of:
-* Setting up a module bundler to load your [ICSS](https://github.com/css-modules/icss).
+* Setting up a [module bundler](#modulebundler) to load the [Interoperable CSS](https://github.com/css-modules/icss).
* [Decorating](#decorator) your component using `react-css-modules`.
### Module Bundler
@@ -95,8 +109,8 @@ Setup consists of:
#### webpack
* Install [`style-loader`](https://www.npmjs.com/package/style-loader) and [`css-loader`](https://www.npmjs.com/package/css-loader).
-* You will also need to use [`extract-text-webpack-plugin`](https://www.npmjs.com/package/extract-text-webpack-plugin) to aggregate the CSS into a single file.
-* Setup a `/\.css$/` loader:
+* You need to use [`extract-text-webpack-plugin`](https://www.npmjs.com/package/extract-text-webpack-plugin) to aggregate the CSS into a single file.
+* Setup `/\.css$/` loader:
```js
{
@@ -113,7 +127,7 @@ new ExtractTextPlugin('app.css', {
})
```
-Refer to [webpack-demo](https://github.com/css-modules/webpack-demo) or [react-css-modules-examples](https://github.com/gajus/react-css-modules-examples) for a complete setup.
+Refer to [webpack-demo](https://github.com/css-modules/webpack-demo) or [react-css-modules-examples](https://github.com/gajus/react-css-modules-examples) for an example of a complete setup.
#### Browserify
@@ -124,16 +138,16 @@ Refer to [`css-modulesify`](https://github.com/css-modules/css-modulesify).
```js
/**
* @typedef CSSModules~Options
- * @property {Boolean} allowMultiple Determines whether `className` can have multiple class names. Throws an error when the constrained is not met. Default: true.
- * @property {Boolean} keepOriginal Determines whether the original `className` value is kept in addition to the appended CSS modules styles CSS class name. Default: true.
- * @property {Boolean} errorNotFound Determines whether an error is raised if `className` defines a CSS class(es) that is not present in the CSS modules styles. Default: false.
+ * @see {@link https://github.com/gajus/react-css-modules#options}
+ * @property {Boolean} allowMultiple
+ * @property {Boolean} errorWhenNotFound
*/
/**
- * @param {ReactClass} Component
- * @param {Object} styles CSS modules class map.
+ * @param {Function} Component
+ * @param {Object} styles CSS Modules class map.
* @param {CSSModules~Options} options
- * @return {ReactClass}
+ * @return {Function}
*/
```
@@ -178,6 +192,8 @@ export default class extends React.Component {
[Awesome!](https://twitter.com/intent/retweet?tweet_id=636497036603428864)
+Refer to the [react-css-modules-examples](https://github.com/gajus/react-css-modules-examples) repository for an example of webpack setup.
+
### Options
Options are supplied as the third parameter to the `CSSModules` function.
@@ -186,57 +202,33 @@ Options are supplied as the third parameter to the `CSSModules` function.
CSSModules(Component, styles, options);
```
-or as a second parameter when using `CSSModules` as a decorator:
+or as a second parameter to the decorator:
```js
@CSSModules(styles, options);
```
-#### `useModuleName`
-
-Default: `false`.
-
-When enabled then CSS Modules are loaded using `moduleName` property and `className` is used only for global CSS, e.g.
-
-```js
-
-```
-
#### `allowMultiple`
-Default: `true`.
+Default: `false`.
-Allows multiple CSS class names.
+Allows multiple CSS Module names.
When `false`, the following will cause an error:
```js
-
+
```
-#### `keepOriginal`
+#### `errorWhenNotFound`
Default: `true`.
-Keeps original CSS class name in addition to the names of the CSS Modules.
-
-When `true`, the following `ReactElement`:
-
-```js
-
-```
-
-will be rendered with a `className` property `foo component__foo___2w27N bar component__bar__1oVw5`.
-
-#### `errorNotFound`
-
-Default: `false`.
-
-Throws an error when class name cannot be mapped to a CSS Module.
+Throws an error when `moduleName` cannot be mapped to an existing CSS Module.
## SASS, SCSS, LESS and other CSS Preprocessors
-[ICSS](https://github.com/css-modules/icss) is compatible with the CSS Preprocessors. All you need is to add the preprocessor to the chain of loaders, e.g. in the case of webpack it is as simple as installing `sass-loader` and adding `!sass` to the end of the `style-loader` loader chain declaration (loaders are processed from right to left):
+[Interoperable CSS](https://github.com/css-modules/icss) is compatible with the CSS Preprocessors. To use a preprocessor, all you need to do is add the preprocessor to the chain of loaders, e.g. in the case of webpack it is as simple as installing `sass-loader` and adding `!sass` to the end of the `style-loader` loader query (loaders are processed from right to left):
```js
{
@@ -255,13 +247,11 @@ CSS Modules does not restrict you from using global CSS.
}
```
-When using global CSS, you need to enable [`keepOriginal`](#keeporiginal) option.
+However, use global CSS with caution. With CSS Modules, there are only a handful of valid use cases for global CSS (e.g. [normalization](https://github.com/necolas/normalize.css/)).
-Use global CSS with caution. With CSS Modules, there are only a handful of valid use cases for global CSS (e.g. [normalization](https://github.com/necolas/normalize.css/)).
+## Multiple CSS Modules
-## Multiple CSS Classes
-
-CSS modules promote composition pattern, i.e. every CSS class that is used in a component should define all properties required to describe the element, e.g.
+CSS Modules promote composition pattern, i.e. every CSS Module that is used in a component should define all properties required to describe an element, e.g.
```css
.button {
@@ -281,9 +271,11 @@ CSS modules promote composition pattern, i.e. every CSS class that is used in a
}
```
-To learn more about composing CSS rules, I suggest reading Glen Maddern article about [CSS Modules](http://glenmaddern.com/articles/css-modules) and the official [CSS modules spec](https://github.com/css-modules/css-modules).
+Composition promotes better separation of markup and style using semantics that would be hard to achieve without CSS Modules.
+
+To learn more about composing CSS rules, I suggest reading Glen Maddern article about [CSS Modules](http://glenmaddern.com/articles/css-modules) and the official [spec of the CSS Modules](https://github.com/css-modules/css-modules).
-Using React CSS Modules, you can map as many CSS classes to the element as you want. `CSSModules` will append a unique class name for every class name it matches in the `className` declaration, e.g.
+That said, if you enable [`allowMultiple`](#allowmultiple) option, you can map multiple CSS Modules to a single `ReactElement`. `react-css-modules` will append a unique class name for every CSS Module it matches in the `moduleName` declaration, e.g.
```css
.button {
@@ -296,9 +288,7 @@ Using React CSS Modules, you can map as many CSS classes to the element as you w
```
```js
-
+
```
-This will map both [ICSS](https://github.com/css-modules/icss) CSS classes to the target element.
-
-However, I encourage you to use composition whenever possible. Composition promotes better separation of markup from style sheets using semantics that would be hard to achieve without CSS modules. You can enforce one CSS class name per `className` using [`allowMultiple` option](#usage).
+This will map both [Interoperable CSS](https://github.com/css-modules/icss) CSS classes to the target element.
diff --git a/dist/index.js b/dist/index.js
index a4008bd..f7f655d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -29,7 +29,7 @@ var decoratorConstructor = undefined,
* When used as a function.
*
* @param {Function} Component
- * @param {Object} styles CSS modules class map.
+ * @param {Object} styles CSS Modules class map.
* @param {Object} options {@link https://github.com/gajus/react-css-modules#options}
* @return {Function}
*/
@@ -59,7 +59,7 @@ functionConstructor = function (Component, styles) {
/**
* When used as a ES7 decorator.
*
- * @param {Object} styles CSS modules class map.
+ * @param {Object} styles CSS Modules class map.
* @param {Object} options {@link https://github.com/gajus/react-css-modules#options}
* @return {Function}
*/
diff --git a/dist/linkClass.js b/dist/linkClass.js
index d28ab89..7962d68 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -24,51 +24,37 @@ linkClass = function (element) {
var childrenCount = undefined,
clonedElement = undefined,
- moduleName = undefined,
+ moduleNames = undefined,
newChildren = undefined,
- newClassName = undefined,
- newProps = undefined;
+ newProps = undefined,
+ appendClassName = undefined;
- if (options.useModuleName) {
- moduleName = element.props.moduleName;
+ moduleNames = element.props.moduleName;
- options.includeOriginal = false;
- } else {
- moduleName = element.props.className;
- }
-
- if (moduleName) {
- newClassName = moduleName.split(' ');
+ if (moduleNames) {
+ moduleNames = moduleNames.split(' ');
- if (options.allowMultiple === false && newClassName.length > 1) {
- throw new Error('ReactElement defines multiple class names ("' + element.props.className + '") in className declaration.');
+ if (options.allowMultiple === false && moduleNames.length > 1) {
+ throw new Error('ReactElement moduleName property defines multiple module names ("' + element.props.moduleName + '").');
}
- newClassName = newClassName.map(function (className) {
- if (!styles[className] && options.errorNotFound === true) {
- throw new Error('"' + className + '" CSS class name is not found in CSS modules styles.');
- }
-
- if (options.includeOriginal === false) {
- if (styles[className]) {
- return styles[className];
- } else {
- return '';
- }
+ appendClassName = moduleNames.map(function (moduleName) {
+ if (styles[moduleName]) {
+ return styles[moduleName];
} else {
- if (styles[className]) {
- return className + ' ' + styles[className];
- } else {
- return className;
+ if (options.errorWhenNotFound === true) {
+ throw new Error('"' + moduleName + '" CSS module is undefined.');
}
+
+ return '';
}
});
- newClassName = newClassName.filter(function (className) {
+ appendClassName = appendClassName.filter(function (className) {
return className.length;
});
- newClassName = newClassName.join(' ');
+ appendClassName = appendClassName.join(' ');
}
// A child can be either an array, a sole object or a string.
@@ -89,9 +75,13 @@ linkClass = function (element) {
}
}
- if (newClassName) {
+ if (appendClassName) {
+ if (element.props.className) {
+ appendClassName = element.props.className + ' ' + appendClassName;
+ }
+
newProps = {
- className: newClassName
+ className: appendClassName
};
}
diff --git a/dist/makeConfig.js b/dist/makeConfig.js
index dbff05c..b286719 100644
--- a/dist/makeConfig.js
+++ b/dist/makeConfig.js
@@ -11,12 +11,15 @@ var _utils = require('./utils');
var _utils2 = _interopRequireDefault(_utils);
/**
+ * @typedef CSSModules~Options
* @see {@link https://github.com/gajus/react-css-modules#options}
* @property {Boolean} allowMultiple
- * @property {Boolean} keepOriginal
- * @property {Boolean} errorNotFound
- * @property {Boolean} useModuleNam
- * @return {Object}
+ * @property {Boolean} errorWhenNotFound
+ */
+
+/**
+ * @param {Options} userConfig
+ * @return {CSSModules~Options}
*/
exports['default'] = function () {
@@ -25,7 +28,7 @@ exports['default'] = function () {
var knownProperties = undefined,
unknownProperties = undefined;
- knownProperties = ['allowMultiple', 'includeOriginal', 'errorNotFound', 'useModuleName'];
+ knownProperties = ['allowMultiple', 'errorWhenNotFound'];
unknownProperties = _utils2['default'].difference(_utils2['default'].keys(userConfig), knownProperties);
@@ -40,19 +43,11 @@ exports['default'] = function () {
});
if (typeof userConfig.allowMultiple === 'undefined') {
- userConfig.allowMultiple = true;
- }
-
- if (typeof userConfig.includeOriginal === 'undefined') {
- userConfig.includeOriginal = true;
- }
-
- if (typeof userConfig.errorNotFound === 'undefined') {
- userConfig.errorNotFound = false;
+ userConfig.allowMultiple = false;
}
- if (typeof userConfig.useModuleName === 'undefined') {
- userConfig.useModuleName = false;
+ if (typeof userConfig.errorWhenNotFound === 'undefined') {
+ userConfig.errorWhenNotFound = false;
}
return userConfig;
diff --git a/src/index.js b/src/index.js
index 7bb6ecb..aab47ea 100644
--- a/src/index.js
+++ b/src/index.js
@@ -8,7 +8,7 @@ let decoratorConstructor,
* When used as a function.
*
* @param {Function} Component
- * @param {Object} styles CSS modules class map.
+ * @param {Object} styles CSS Modules class map.
* @param {Object} options {@link https://github.com/gajus/react-css-modules#options}
* @return {Function}
*/
@@ -23,7 +23,7 @@ functionConstructor = (Component, styles, options = {}) => {
/**
* When used as a ES7 decorator.
*
- * @param {Object} styles CSS modules class map.
+ * @param {Object} styles CSS Modules class map.
* @param {Object} options {@link https://github.com/gajus/react-css-modules#options}
* @return {Function}
*/
diff --git a/src/linkClass.js b/src/linkClass.js
index 82fb397..f295866 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -11,51 +11,37 @@ let linkClass;
linkClass = (element, styles = {}, options = {}) => {
let childrenCount,
clonedElement,
- moduleName,
+ moduleNames,
newChildren,
- newClassName,
- newProps;
+ newProps,
+ appendClassName;
- if (options.useModuleName) {
- moduleName = element.props.moduleName;
+ moduleNames = element.props.moduleName;
- options.includeOriginal = false;
- } else {
- moduleName = element.props.className;
- }
-
- if (moduleName) {
- newClassName = moduleName.split(' ');
+ if (moduleNames) {
+ moduleNames = moduleNames.split(' ');
- if (options.allowMultiple === false && newClassName.length > 1) {
- throw new Error(`ReactElement defines multiple class names ("${element.props.className}") in className declaration.`);
+ if (options.allowMultiple === false && moduleNames.length > 1) {
+ throw new Error(`ReactElement moduleName property defines multiple module names ("${element.props.moduleName}").`);
}
- newClassName = newClassName.map((className) => {
- if (!styles[className] && options.errorNotFound === true) {
- throw new Error(`"${className}" CSS class name is not found in CSS modules styles.`);
- }
-
- if (options.includeOriginal === false) {
- if (styles[className]) {
- return styles[className];
- } else {
- return '';
- }
+ appendClassName = moduleNames.map((moduleName) => {
+ if (styles[moduleName]) {
+ return styles[moduleName];
} else {
- if (styles[className]) {
- return `${className} ${styles[className]}`;
- } else {
- return className;
+ if (options.errorWhenNotFound === true) {
+ throw new Error(`"${moduleName}" CSS module is undefined.`);
}
+
+ return '';
}
});
- newClassName = newClassName.filter((className) => {
+ appendClassName = appendClassName.filter((className) => {
return className.length;
});
- newClassName = newClassName.join(' ');
+ appendClassName = appendClassName.join(' ');
}
// A child can be either an array, a sole object or a string.
@@ -77,9 +63,13 @@ linkClass = (element, styles = {}, options = {}) => {
}
- if (newClassName) {
+ if (appendClassName) {
+ if (element.props.className) {
+ appendClassName = element.props.className + ' ' + appendClassName;
+ }
+
newProps = {
- className: newClassName
+ className: appendClassName
};
}
diff --git a/src/makeConfig.js b/src/makeConfig.js
index 9d860ea..f9c8715 100644
--- a/src/makeConfig.js
+++ b/src/makeConfig.js
@@ -1,12 +1,15 @@
import _ from './utils';
/**
+ * @typedef CSSModules~Options
* @see {@link https://github.com/gajus/react-css-modules#options}
* @property {Boolean} allowMultiple
- * @property {Boolean} keepOriginal
- * @property {Boolean} errorNotFound
- * @property {Boolean} useModuleNam
- * @return {Object}
+ * @property {Boolean} errorWhenNotFound
+ */
+
+/**
+ * @param {Options} userConfig
+ * @return {CSSModules~Options}
*/
export default (userConfig = {}) => {
let knownProperties,
@@ -14,9 +17,7 @@ export default (userConfig = {}) => {
knownProperties = [
'allowMultiple',
- 'includeOriginal',
- 'errorNotFound',
- 'useModuleName'
+ 'errorWhenNotFound'
];
unknownProperties = _.difference(_.keys(userConfig), knownProperties);
@@ -32,19 +33,11 @@ export default (userConfig = {}) => {
});
if (typeof userConfig.allowMultiple === 'undefined') {
- userConfig.allowMultiple = true;
- }
-
- if (typeof userConfig.includeOriginal === 'undefined') {
- userConfig.includeOriginal = true;
- }
-
- if (typeof userConfig.errorNotFound === 'undefined') {
- userConfig.errorNotFound = false;
+ userConfig.allowMultiple = false;
}
- if (typeof userConfig.useModuleName === 'undefined') {
- userConfig.useModuleName = false;
+ if (typeof userConfig.errorWhenNotFound === 'undefined') {
+ userConfig.errorWhenNotFound = false;
}
return userConfig;
diff --git a/test/linkClass.js b/test/linkClass.js
index 12d158a..d00fb15 100644
--- a/test/linkClass.js
+++ b/test/linkClass.js
@@ -8,19 +8,23 @@ import jsdom from 'jsdom';
import linkClass from './../dist/linkClass';
describe('linkClass', () => {
- describe('when elements do not define className', () => {
- it('does not affect the element declaration', () => {
+ context('when ReactElement does not define moduleName', () => {
+ it('does not affect element properties', () => {
expect(linkClass(
)).to.deep.equal(
);
});
- it('does not affect element with a single element child', () => {
+ it('does not affect element properties with a single element child', () => {
expect(linkClass(
)).to.deep.equal(
);
});
- it('does not affect element with a single text child', () => {
+ it('does not affect element properties with a single text child', () => {
expect(linkClass(
test
)).to.deep.equal(
test
);
});
+ it('does not affect the className', () => {
+ expect(linkClass(
)).to.deep.equal(
);
+ });
+
// Using array instead of object causes the following error:
// Warning: Each child in an array or iterator should have a unique "key" prop.
// Check the render method of _class. See https://fb.me/react-warning-keys for more information.
@@ -29,74 +33,85 @@ describe('linkClass', () => {
});
});
- describe('when element className does not match an existing CSS class', () => {
- it('does not affect element className', () => {
- let subject;
-
- subject =
;
-
- subject = linkClass(subject, {});
-
- expect(subject.props.className).to.deep.equal('foo');
- });
- });
+ context('when moduleName matches an existing CSS module', () => {
+ context('when ReactElement does not have an existing className', () => {
+ it('uses the generated class name to set the className property', () => {
+ let subject;
- describe('when element className matches an existing CSS class', () => {
- it('appends the generated class name to the className property', () => {
- let subject;
+ subject =
;
- subject =
;
+ subject = linkClass(subject, {
+ foo: 'foo-1'
+ });
- subject = linkClass(subject, {
- foo: 'foo-1'
+ expect(subject.props.className).to.deep.equal('foo-1');
});
-
- expect(subject.props.className).to.deep.equal('foo foo-1');
});
- });
-
- describe('when element classNames refers to multiple CSS classes', () => {
- describe('when all referenced CSS classes exist', () => {
- it('appends a generated class name for every referenced CSS class', () => {
+ context('when ReactElement has an existing className', () => {
+ it('appends the generated class name to the className property', () => {
let subject;
- subject =
;
+ subject =
;
subject = linkClass(subject, {
- foo: 'foo-1',
bar: 'bar-1'
});
- expect(subject.props.className).to.deep.equal('foo foo-1 bar bar-1');
+ expect(subject.props.className).to.deep.equal('foo bar-1');
});
});
- describe('when some referenced CSS classes exist', () => {
- it('appends a generated class name for the matched CSS classes', () => {
- let subject;
-
- subject =
;
+ });
- subject = linkClass(subject, {
- foo: 'foo-1'
+ describe('options.allowMultiple', () => {
+ context('when multiple module names are used', () => {
+ context('when false', () => {
+ it('throws an error', () => {
+ expect(() => {
+ linkClass(
, {}, {allowMultiple: false});
+ }).to.throw(Error, 'ReactElement moduleName property defines multiple module names ("foo bar").');
});
+ });
+ context('when true', () => {
+ it('appends a generated class name for every referenced CSS module', () => {
+ let subject;
+
+ subject =
;
+
+ subject = linkClass(subject, {
+ foo: 'foo-1',
+ bar: 'bar-1'
+ }, {allowMultiple: true});
- expect(subject.props.className).to.deep.equal('foo foo-1 bar');
+ expect(subject.props.className).to.deep.equal('foo-1 bar-1');
+ });
});
});
- describe('when none of the referenced CSS classes exist', () => {
- it('does not append anything', () => {
- let subject;
+ });
- subject =
;
+ describe('options.errorWhenNotFound', () => {
+ context('when moduleName does not match an existing CSS module', () => {
+ context('when false', () => {
+ it('ignores the missing CSS module', () => {
+ let subject;
- subject = linkClass(subject, {});
+ subject =
;
- expect(subject.props.className).to.deep.equal('foo bar');
+ subject = linkClass(subject, {}, {errorWhenNotFound: false});
+
+ expect(subject.props.className).to.be.an('undefined');
+ });
+ });
+ context('when is true', () => {
+ it('throws an error', () => {
+ expect(() => {
+ linkClass(
, {}, {errorWhenNotFound: true});
+ }).to.throw(Error, '"foo" CSS module is undefined.');
+ });
});
});
});
- describe('when ReactElement includes ReactComponent', () => {
+ context('when ReactElement includes ReactComponent', () => {
let Foo,
nodeList;
@@ -115,62 +130,17 @@ describe('linkClass', () => {
Foo = class extends React.Component {
render () {
- return
Hello
;
+ return
Hello
;
}
};
- nodeList = TestUtils.renderIntoDocument(linkClass(
, {foo: 'foo-1'}));
+ nodeList = TestUtils.renderIntoDocument(linkClass(
, {foo: 'foo-1'}));
});
it('processes ReactElement nodes', () => {
- expect(nodeList.className).to.equal('foo foo-1');
+ expect(nodeList.className).to.equal('foo-1');
});
it('does not process ReactComponent nodes', () => {
- expect(nodeList.firstChild.className).to.equal('foo');
- });
- });
-
- describe('when options.useModuleName is true', () => {
- it('does not lookup the className property', () => {
- let subject;
-
- subject = linkClass(
, {foo: 'foo-1'}, {useModuleName: true});
-
- expect(subject.props.className).to.equal('foo');
- });
- it('appends CSS Modules using modulName', () => {
- let subject;
-
- subject = linkClass(
, {foo: 'foo-1'}, {useModuleName: true});
-
- expect(subject.props.className).to.equal('foo-1');
- });
- });
-
- describe('when options.allowMultiple is false', () => {
- describe('when it finds multiple CSS class names in a className', () => {
- it('throws an error', () => {
- expect(() => {
- linkClass(
, {}, {allowMultiple: false});
- }).to.throw(Error, 'ReactElement defines multiple class names ("foo bar") in className declaration.');
- });
- });
- });
-
- describe('when options.includeOriginal is false', () => {
- it('does not include the original class name', () => {
- let subject;
-
- subject = linkClass(
, {foo: 'foo-1'}, {includeOriginal: false});
-
- expect(subject.props.className).to.equal('foo-1');
- });
- });
-
- describe('when options.errorNotFound is true', () => {
- it('throws an error when className defines a CSS class that does not exist in CSS modules styles', () => {
- expect(() => {
- linkClass(
, {}, {errorNotFound: true});
- }).to.throw(Error, '"foo" CSS class name is not found in CSS modules styles.');
+ expect(nodeList.firstChild.className).to.equal('');
});
});
});
diff --git a/test/makeConfig.js b/test/makeConfig.js
index 465cb74..a48bd86 100644
--- a/test/makeConfig.js
+++ b/test/makeConfig.js
@@ -12,25 +12,13 @@ describe('makeConfig', () => {
options = makeConfig();
});
describe('allowMultiple property', () => {
- it('defaults to true', () => {
- expect(options.allowMultiple).to.equal(true);
- });
- });
- describe('includeOriginal property', () => {
- it('defaults to true', () => {
- expect(options.includeOriginal).to.equal(true);
+ it('defaults to false', () => {
+ expect(options.allowMultiple).to.equal(false);
});
});
-
- describe('errorNotFound property', () => {
+ describe('errorWhenNotFound property', () => {
it('defaults to true', () => {
- expect(options.errorNotFound).to.equal(false);
- });
- });
-
- describe('useModuleName property', () => {
- it('defaults to true', () => {
- expect(options.useModuleName).to.equal(false);
+ expect(options.errorWhenNotFound).to.equal(false);
});
});
});
@@ -43,13 +31,4 @@ describe('makeConfig', () => {
}).to.throw(Error, 'Unknown config property "unknownProperty".');
});
});
- describe('when property value is not boolean', () => {
- it('throws an error', () => {
- expect(() => {
- makeConfig({
- useModuleName: 1
- });
- }).to.throw(Error, '"useModuleName" property value must be a boolean.');
- });
- });
});
From 203e4e5a2e0ccb4bbbb58ca86961e09178a8436f Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:12:16 +0100
Subject: [PATCH 008/229] 2.0.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 71a46e1..d07eb46 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "1.3.0",
+ "version": "2.0.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
From 66e599663aaa6a94a9c52435479333f126846137 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:12:58 +0100
Subject: [PATCH 009/229] 3.0.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index d07eb46..84373ef 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "2.0.0",
+ "version": "3.0.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
From ed7fa4fd107adfbb2fbc75bbad17bfea6cc01c33 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:14:19 +0100
Subject: [PATCH 010/229] Ignore npm-debug.log.
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 07e6e47..6edd850 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/node_modules
+npm-debug.log
From 9e9b482531af64f9083d00365f20920c75a838ad Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:14:24 +0100
Subject: [PATCH 011/229] 4.0.0
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 84373ef..db9a0e9 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "3.0.0",
+ "version": "4.0.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
From b59e0403ccdc9ddcb887ce48d827716599c46b5c Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:15:14 +0100
Subject: [PATCH 012/229] V2. Using localClassName instead of overloading
className.
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index db9a0e9..bc01bbf 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "4.0.0",
+ "version": "5.0.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
From ba67d3641a09493f8b0bc02e89dddace231bffe5 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 11:47:03 +0100
Subject: [PATCH 013/229] ESLint compliance.
---
README.md | 22 +++++++++++-----------
dist/linkClass.js | 26 +++++++++++++-------------
package.json | 2 +-
src/linkClass.js | 28 ++++++++++++++--------------
test/linkClass.js | 24 ++++++++++++------------
5 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/README.md b/README.md
index 3f9d770..74c7337 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ However, this approach has several disadvantages:
* Mixing CSS Modules and global CSS classes is cumbersome.
* Reference to an undefined CSS Module resolves to `undefined` without a warning.
-React CSS Modules component automates loading of CSS Modules using `moduleName` property, e.g.
+React CSS Modules component automates loading of CSS Modules using `localClassName` property, e.g.
```js
import React from 'react';
@@ -68,9 +68,9 @@ import CSSModules from 'react-css-modules';
class Car extends React.Component {
render () {
- return
-
-
+ return
;
}
}
@@ -85,15 +85,15 @@ Using `react-css-modules`:
* There is clear distinction between global CSS and CSS Modules, e.g.
```js
-
+
```
-* You are warned when `moduleName` refers to an undefined CSS Module ([`errorWhenNotFound`](#errorwhennotfound) option).
+* You are warned when `localClassName` refers to an undefined CSS Module ([`errorWhenNotFound`](#errorwhennotfound) option).
* You can enforce use of a single CSS module per `ReactElement` ([`allowMultiple`](#allowmultiple) option).
## The Implementation
-`react-css-modules` extends `render` method of the target component. It will use the value of `moduleName` to look for CSS Modules in the associated styles object and will append the matching unique CSS class names to the `ReactElement` `className` property value.
+`react-css-modules` extends `render` method of the target component. It will use the value of `localClassName` to look for CSS Modules in the associated styles object and will append the matching unique CSS class names to the `ReactElement` `className` property value.
[Awesome!](https://twitter.com/intent/retweet?tweet_id=636497036603428864)
@@ -217,14 +217,14 @@ Allows multiple CSS Module names.
When `false`, the following will cause an error:
```js
-
+
```
#### `errorWhenNotFound`
Default: `true`.
-Throws an error when `moduleName` cannot be mapped to an existing CSS Module.
+Throws an error when `localClassName` cannot be mapped to an existing CSS Module.
## SASS, SCSS, LESS and other CSS Preprocessors
@@ -275,7 +275,7 @@ Composition promotes better separation of markup and style using semantics that
To learn more about composing CSS rules, I suggest reading Glen Maddern article about [CSS Modules](http://glenmaddern.com/articles/css-modules) and the official [spec of the CSS Modules](https://github.com/css-modules/css-modules).
-That said, if you enable [`allowMultiple`](#allowmultiple) option, you can map multiple CSS Modules to a single `ReactElement`. `react-css-modules` will append a unique class name for every CSS Module it matches in the `moduleName` declaration, e.g.
+That said, if you enable [`allowMultiple`](#allowmultiple) option, you can map multiple CSS Modules to a single `ReactElement`. `react-css-modules` will append a unique class name for every CSS Module it matches in the `localClassName` declaration, e.g.
```css
.button {
@@ -288,7 +288,7 @@ That said, if you enable [`allowMultiple`](#allowmultiple) option, you can map m
```
```js
-
+
```
This will map both [Interoperable CSS](https://github.com/css-modules/icss) CSS classes to the target element.
diff --git a/dist/linkClass.js b/dist/linkClass.js
index 7962d68..111a10f 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -22,28 +22,28 @@ linkClass = function (element) {
var styles = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
- var childrenCount = undefined,
+ var appendClassName = undefined,
+ childrenCount = undefined,
clonedElement = undefined,
- moduleNames = undefined,
+ localClassNames = undefined,
newChildren = undefined,
- newProps = undefined,
- appendClassName = undefined;
+ newProps = undefined;
- moduleNames = element.props.moduleName;
+ localClassNames = element.props.localClassName;
- if (moduleNames) {
- moduleNames = moduleNames.split(' ');
+ if (localClassNames) {
+ localClassNames = localClassNames.split(' ');
- if (options.allowMultiple === false && moduleNames.length > 1) {
- throw new Error('ReactElement moduleName property defines multiple module names ("' + element.props.moduleName + '").');
+ if (options.allowMultiple === false && localClassNames.length > 1) {
+ throw new Error('ReactElement localClassName property defines multiple module names ("' + element.props.localClassName + '").');
}
- appendClassName = moduleNames.map(function (moduleName) {
- if (styles[moduleName]) {
- return styles[moduleName];
+ appendClassName = localClassNames.map(function (localClassName) {
+ if (styles[localClassName]) {
+ return styles[localClassName];
} else {
if (options.errorWhenNotFound === true) {
- throw new Error('"' + moduleName + '" CSS module is undefined.');
+ throw new Error('"' + localClassName + '" CSS module is undefined.');
}
return '';
diff --git a/package.json b/package.json
index bc01bbf..d07eb46 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "5.0.0",
+ "version": "2.0.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
diff --git a/src/linkClass.js b/src/linkClass.js
index f295866..9c7dffe 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -9,28 +9,28 @@ let linkClass;
* @return {ReactElement}
*/
linkClass = (element, styles = {}, options = {}) => {
- let childrenCount,
+ let appendClassName,
+ childrenCount,
clonedElement,
- moduleNames,
+ localClassNames,
newChildren,
- newProps,
- appendClassName;
+ newProps;
- moduleNames = element.props.moduleName;
+ localClassNames = element.props.localClassName;
- if (moduleNames) {
- moduleNames = moduleNames.split(' ');
+ if (localClassNames) {
+ localClassNames = localClassNames.split(' ');
- if (options.allowMultiple === false && moduleNames.length > 1) {
- throw new Error(`ReactElement moduleName property defines multiple module names ("${element.props.moduleName}").`);
+ if (options.allowMultiple === false && localClassNames.length > 1) {
+ throw new Error(`ReactElement localClassName property defines multiple module names ("${element.props.localClassName}").`);
}
- appendClassName = moduleNames.map((moduleName) => {
- if (styles[moduleName]) {
- return styles[moduleName];
+ appendClassName = localClassNames.map((localClassName) => {
+ if (styles[localClassName]) {
+ return styles[localClassName];
} else {
if (options.errorWhenNotFound === true) {
- throw new Error(`"${moduleName}" CSS module is undefined.`);
+ throw new Error(`"${localClassName}" CSS module is undefined.`);
}
return '';
@@ -65,7 +65,7 @@ linkClass = (element, styles = {}, options = {}) => {
if (appendClassName) {
if (element.props.className) {
- appendClassName = element.props.className + ' ' + appendClassName;
+ appendClassName = `${element.props.className} ${appendClassName}`;
}
newProps = {
diff --git a/test/linkClass.js b/test/linkClass.js
index d00fb15..d805d51 100644
--- a/test/linkClass.js
+++ b/test/linkClass.js
@@ -8,7 +8,7 @@ import jsdom from 'jsdom';
import linkClass from './../dist/linkClass';
describe('linkClass', () => {
- context('when ReactElement does not define moduleName', () => {
+ context('when ReactElement does not define localClassName', () => {
it('does not affect element properties', () => {
expect(linkClass(
)).to.deep.equal(
);
});
@@ -33,12 +33,12 @@ describe('linkClass', () => {
});
});
- context('when moduleName matches an existing CSS module', () => {
+ context('when localClassName matches an existing CSS module', () => {
context('when ReactElement does not have an existing className', () => {
it('uses the generated class name to set the className property', () => {
let subject;
- subject =
;
+ subject =
;
subject = linkClass(subject, {
foo: 'foo-1'
@@ -51,7 +51,7 @@ describe('linkClass', () => {
it('appends the generated class name to the className property', () => {
let subject;
- subject =
;
+ subject =
;
subject = linkClass(subject, {
bar: 'bar-1'
@@ -67,15 +67,15 @@ describe('linkClass', () => {
context('when false', () => {
it('throws an error', () => {
expect(() => {
- linkClass(
, {}, {allowMultiple: false});
- }).to.throw(Error, 'ReactElement moduleName property defines multiple module names ("foo bar").');
+ linkClass(
, {}, {allowMultiple: false});
+ }).to.throw(Error, 'ReactElement localClassName property defines multiple module names ("foo bar").');
});
});
context('when true', () => {
it('appends a generated class name for every referenced CSS module', () => {
let subject;
- subject =
;
+ subject =
;
subject = linkClass(subject, {
foo: 'foo-1',
@@ -89,12 +89,12 @@ describe('linkClass', () => {
});
describe('options.errorWhenNotFound', () => {
- context('when moduleName does not match an existing CSS module', () => {
+ context('when localClassName does not match an existing CSS module', () => {
context('when false', () => {
it('ignores the missing CSS module', () => {
let subject;
- subject =
;
+ subject =
;
subject = linkClass(subject, {}, {errorWhenNotFound: false});
@@ -104,7 +104,7 @@ describe('linkClass', () => {
context('when is true', () => {
it('throws an error', () => {
expect(() => {
- linkClass(
, {}, {errorWhenNotFound: true});
+ linkClass(
, {}, {errorWhenNotFound: true});
}).to.throw(Error, '"foo" CSS module is undefined.');
});
});
@@ -130,11 +130,11 @@ describe('linkClass', () => {
Foo = class extends React.Component {
render () {
- return
Hello
;
+ return
Hello
;
}
};
- nodeList = TestUtils.renderIntoDocument(linkClass(
, {foo: 'foo-1'}));
+ nodeList = TestUtils.renderIntoDocument(linkClass(
, {foo: 'foo-1'}));
});
it('processes ReactElement nodes', () => {
expect(nodeList.className).to.equal('foo-1');
From 4b00b4206e6bd7ce0678077f229591b2dc795e98 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 12:13:28 +0100
Subject: [PATCH 014/229] V3. Reading Christopher Chedeau presentation on CSS
in JS made me rethik my decision of using localClassName convention.
styleName it is.
---
dist/linkClass.js | 20 ++++++++++----------
package.json | 2 +-
src/linkClass.js | 20 ++++++++++----------
test/linkClass.js | 24 ++++++++++++------------
4 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/dist/linkClass.js b/dist/linkClass.js
index 111a10f..6c44a3d 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -25,25 +25,25 @@ linkClass = function (element) {
var appendClassName = undefined,
childrenCount = undefined,
clonedElement = undefined,
- localClassNames = undefined,
+ styleNames = undefined,
newChildren = undefined,
newProps = undefined;
- localClassNames = element.props.localClassName;
+ styleNames = element.props.styleName;
- if (localClassNames) {
- localClassNames = localClassNames.split(' ');
+ if (styleNames) {
+ styleNames = styleNames.split(' ');
- if (options.allowMultiple === false && localClassNames.length > 1) {
- throw new Error('ReactElement localClassName property defines multiple module names ("' + element.props.localClassName + '").');
+ if (options.allowMultiple === false && styleNames.length > 1) {
+ throw new Error('ReactElement styleName property defines multiple module names ("' + element.props.styleName + '").');
}
- appendClassName = localClassNames.map(function (localClassName) {
- if (styles[localClassName]) {
- return styles[localClassName];
+ appendClassName = styleNames.map(function (styleName) {
+ if (styles[styleName]) {
+ return styles[styleName];
} else {
if (options.errorWhenNotFound === true) {
- throw new Error('"' + localClassName + '" CSS module is undefined.');
+ throw new Error('"' + styleName + '" CSS module is undefined.');
}
return '';
diff --git a/package.json b/package.json
index d07eb46..84373ef 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"css",
"modules"
],
- "version": "2.0.0",
+ "version": "3.0.0",
"author": {
"name": "Gajus Kuizinas",
"email": "gk@anuary.com",
diff --git a/src/linkClass.js b/src/linkClass.js
index 9c7dffe..088afa3 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -12,25 +12,25 @@ linkClass = (element, styles = {}, options = {}) => {
let appendClassName,
childrenCount,
clonedElement,
- localClassNames,
+ styleNames,
newChildren,
newProps;
- localClassNames = element.props.localClassName;
+ styleNames = element.props.styleName;
- if (localClassNames) {
- localClassNames = localClassNames.split(' ');
+ if (styleNames) {
+ styleNames = styleNames.split(' ');
- if (options.allowMultiple === false && localClassNames.length > 1) {
- throw new Error(`ReactElement localClassName property defines multiple module names ("${element.props.localClassName}").`);
+ if (options.allowMultiple === false && styleNames.length > 1) {
+ throw new Error(`ReactElement styleName property defines multiple module names ("${element.props.styleName}").`);
}
- appendClassName = localClassNames.map((localClassName) => {
- if (styles[localClassName]) {
- return styles[localClassName];
+ appendClassName = styleNames.map((styleName) => {
+ if (styles[styleName]) {
+ return styles[styleName];
} else {
if (options.errorWhenNotFound === true) {
- throw new Error(`"${localClassName}" CSS module is undefined.`);
+ throw new Error(`"${styleName}" CSS module is undefined.`);
}
return '';
diff --git a/test/linkClass.js b/test/linkClass.js
index d805d51..f88884b 100644
--- a/test/linkClass.js
+++ b/test/linkClass.js
@@ -8,7 +8,7 @@ import jsdom from 'jsdom';
import linkClass from './../dist/linkClass';
describe('linkClass', () => {
- context('when ReactElement does not define localClassName', () => {
+ context('when ReactElement does not define styleName', () => {
it('does not affect element properties', () => {
expect(linkClass()).to.deep.equal();
});
@@ -33,12 +33,12 @@ describe('linkClass', () => {
});
});
- context('when localClassName matches an existing CSS module', () => {
+ context('when styleName matches an existing CSS module', () => {
context('when ReactElement does not have an existing className', () => {
it('uses the generated class name to set the className property', () => {
let subject;
- subject = ;
+ subject = ;
subject = linkClass(subject, {
foo: 'foo-1'
@@ -51,7 +51,7 @@ describe('linkClass', () => {
it('appends the generated class name to the className property', () => {
let subject;
- subject = ;
+ subject = ;
subject = linkClass(subject, {
bar: 'bar-1'
@@ -67,15 +67,15 @@ describe('linkClass', () => {
context('when false', () => {
it('throws an error', () => {
expect(() => {
- linkClass(, {}, {allowMultiple: false});
- }).to.throw(Error, 'ReactElement localClassName property defines multiple module names ("foo bar").');
+ linkClass(, {}, {allowMultiple: false});
+ }).to.throw(Error, 'ReactElement styleName property defines multiple module names ("foo bar").');
});
});
context('when true', () => {
it('appends a generated class name for every referenced CSS module', () => {
let subject;
- subject = ;
+ subject = ;
subject = linkClass(subject, {
foo: 'foo-1',
@@ -89,12 +89,12 @@ describe('linkClass', () => {
});
describe('options.errorWhenNotFound', () => {
- context('when localClassName does not match an existing CSS module', () => {
+ context('when styleName does not match an existing CSS module', () => {
context('when false', () => {
it('ignores the missing CSS module', () => {
let subject;
- subject = ;
+ subject = ;
subject = linkClass(subject, {}, {errorWhenNotFound: false});
@@ -104,7 +104,7 @@ describe('linkClass', () => {
context('when is true', () => {
it('throws an error', () => {
expect(() => {
- linkClass(, {}, {errorWhenNotFound: true});
+ linkClass(, {}, {errorWhenNotFound: true});
}).to.throw(Error, '"foo" CSS module is undefined.');
});
});
@@ -130,11 +130,11 @@ describe('linkClass', () => {
Foo = class extends React.Component {
render () {
- return Hello
;
+ return Hello
;
}
};
- nodeList = TestUtils.renderIntoDocument(linkClass(
, {foo: 'foo-1'}));
+ nodeList = TestUtils.renderIntoDocument(linkClass(
, {foo: 'foo-1'}));
});
it('processes ReactElement nodes', () => {
expect(nodeList.className).to.equal('foo-1');
From fae35f8ff89b4a6faa0ffe31f418808a03a4e745 Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 12:14:45 +0100
Subject: [PATCH 015/229] ESLint compliance.
---
dist/linkClass.js | 4 ++--
src/linkClass.js | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/dist/linkClass.js b/dist/linkClass.js
index 6c44a3d..6176156 100644
--- a/dist/linkClass.js
+++ b/dist/linkClass.js
@@ -25,9 +25,9 @@ linkClass = function (element) {
var appendClassName = undefined,
childrenCount = undefined,
clonedElement = undefined,
- styleNames = undefined,
newChildren = undefined,
- newProps = undefined;
+ newProps = undefined,
+ styleNames = undefined;
styleNames = element.props.styleName;
diff --git a/src/linkClass.js b/src/linkClass.js
index 088afa3..b058657 100644
--- a/src/linkClass.js
+++ b/src/linkClass.js
@@ -12,9 +12,9 @@ linkClass = (element, styles = {}, options = {}) => {
let appendClassName,
childrenCount,
clonedElement,
- styleNames,
newChildren,
- newProps;
+ newProps,
+ styleNames;
styleNames = element.props.styleName;
From e6196344df087b2e52fafc8fb818a4e65fc0a30c Mon Sep 17 00:00:00 2001
From: Gajus Kuizinas
Date: Thu, 27 Aug 2015 12:17:19 +0100
Subject: [PATCH 016/229] Docs.
---
README.md | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 74c7337..947819f 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ However, this approach has several disadvantages:
* Mixing CSS Modules and global CSS classes is cumbersome.
* Reference to an undefined CSS Module resolves to `undefined` without a warning.
-React CSS Modules component automates loading of CSS Modules using `localClassName` property, e.g.
+React CSS Modules component automates loading of CSS Modules using `styleName` property, e.g.
```js
import React from 'react';
@@ -68,9 +68,9 @@ import CSSModules from 'react-css-modules';
class Car extends React.Component {
render () {
- return