react-props-classnames
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -16,9 +16,15 @@ "use strict"; | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
// eslint-disable-next-line react/prop-types | ||
var _default = function _default(options) { | ||
return function (Component) { | ||
return function (props) { | ||
return function (_ref) { | ||
var children = _ref.children, | ||
otherProps = _objectWithoutProperties(_ref, ["children"]); | ||
return _react.default.createElement(_TransformedComponent.default, _extends({ | ||
options: options | ||
}, props), function (transformedProps) { | ||
return _react.default.createElement(Component, transformedProps); | ||
}, otherProps), function (transformedProps) { | ||
return _react.default.createElement(Component, transformedProps, children); | ||
}); | ||
@@ -25,0 +31,0 @@ }; |
@@ -33,7 +33,7 @@ "use strict"; | ||
_defineProperty(this, "getClassNamesFromProps", function (props) { | ||
_defineProperty(this, "getClassNameFromProps", function (props) { | ||
var _prefix = _this._prefix, | ||
_transformBool = _this._transformBool, | ||
_transformString = _this._transformString; | ||
var classNames = Object.keys(props).reduce(function (result, propsKey) { | ||
var className = Object.keys(props).reduce(function (result, propsKey) { | ||
var newResult = result; | ||
@@ -50,3 +50,3 @@ var value = props[propsKey]; | ||
}, []).join(' '); | ||
return classNames; | ||
return className; | ||
}); | ||
@@ -53,0 +53,0 @@ |
@@ -22,11 +22,11 @@ "use strict"; | ||
var options = _ref.options, | ||
classNames = _ref.classNames, | ||
className = _ref.className, | ||
children = _ref.children, | ||
otherOrops = _objectWithoutProperties(_ref, ["options", "classNames", "children"]); | ||
otherOrops = _objectWithoutProperties(_ref, ["options", "className", "children"]); | ||
var propsTransform = new _PropsTransform.default(options); | ||
var propsClassNames = propsTransform.getClassNamesFromProps(otherOrops); | ||
var mergedClassNames = "".concat(classNames, " ").concat(propsClassNames).trim(); | ||
var propsClassName = propsTransform.getClassNameFromProps(otherOrops); | ||
var mergedClassName = "".concat(className, " ").concat(propsClassName).trim(); | ||
return children(_objectSpread({ | ||
classNames: mergedClassNames | ||
className: mergedClassName | ||
}, otherOrops)); | ||
@@ -37,3 +37,3 @@ }; | ||
TransformedComponent.propTypes = { | ||
classNames: _propTypes.default.string, | ||
className: _propTypes.default.string, | ||
options: _propTypes.default.shape({ | ||
@@ -46,3 +46,3 @@ string: _propTypes.default.string, | ||
TransformedComponent.defaultProps = { | ||
classNames: '', | ||
className: '', | ||
options: {} | ||
@@ -49,0 +49,0 @@ }; |
{ | ||
"name": "react-props-classnames", | ||
"description": "Easily transform component's props to classnames", | ||
"license": "MIT", | ||
"author": "jigsawye <jigsawe.ye@gmail.com>", | ||
"license": "MIT", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "lib/index.js", | ||
@@ -20,6 +20,11 @@ "files": [ | ||
"testonly": "jest", | ||
"testonly:cov": "jest --coverage --runInBand --forceExit", | ||
"testonly:watch": "jest --runInBand --watchAll", | ||
"testonly:cov": "jest --coverage --runInBand --forceExit", | ||
"preversion": "npm run test" | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.6.1", | ||
"react": "^16.4.0", | ||
"react-dom": "^16.4.0" | ||
}, | ||
"devDependencies": { | ||
@@ -95,8 +100,3 @@ "@babel/cli": "^7.0.0-beta.47", | ||
"singleQuote": true | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.6.1", | ||
"react": "^16.4.0", | ||
"react-dom": "^16.4.0" | ||
} | ||
} |
@@ -5,5 +5,5 @@ # React Props Classnames | ||
- Good usage with `styled-components` when you want to control styles by props. | ||
- Transform your boolena and string props to className. | ||
- Customized classNames prefix. | ||
- Good usage with `styled-components` when you want to control styles by props. | ||
- Transform your boolena and string props to className. | ||
- Customized classNames prefix. | ||
@@ -49,13 +49,18 @@ ## Install | ||
### `createPropsTransform` | ||
### `createPropsTransform(options)` | ||
| key | Type | Default | Description | | ||
|:--------|:-----------|:---------------|:--------------------------------------------| | ||
| bool | `Boolean` | true |Transform boolean props to classNames or not.| | ||
| string | `Boolean` | true |Transform string props to classNames or not. | | ||
| prefix | `String` |'default-prefix'|The prefix of every classNames. | | ||
#### `options` _(Object)_ | ||
| key | Type | Default | Description | | ||
| :----- | :-------- | :--------------- | :-------------------------------------------- | | ||
| bool | `Boolean` | true | Transform boolean props to classNames or not. | | ||
| string | `Boolean` | true | Transform string props to classNames or not. | | ||
| prefix | `String` | 'default-prefix' | The prefix of every classNames. | | ||
#### Returns | ||
A higher-order component that transform props then pass into your components. | ||
## License | ||
MIT © [jigsawye](https://github.com/jigsawye) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11477
116
65