Comparing version 4.0.2 to 4.1.0
@@ -9,4 +9,10 @@ 'use strict'; | ||
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 _react = require('react'); | ||
var _hoistNonReactStatics = require('hoist-non-react-statics'); | ||
var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics); | ||
var _lodash = require('lodash'); | ||
@@ -22,29 +28,86 @@ | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
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; } | ||
// const isStateless(component: Function): boolean { | ||
// return !component.render && !(component.prototype && component.prototype.render); | ||
// } | ||
var createDefaultStyle = function createDefaultStyle(defaultStyle, getModifiers) { | ||
return function (WrappedComponent) { | ||
function WithDefaultStyle(_ref, _ref2) { | ||
var _ref2$ENHANCER_CONTEX = _ref2[_types.ENHANCER_CONTEXT_NAME], | ||
enhance = _ref2$ENHANCER_CONTEX === undefined ? _lodash.identity : _ref2$ENHANCER_CONTEX; | ||
var WithDefaultStyle = function (_Component) { | ||
_inherits(WithDefaultStyle, _Component); | ||
var style = _ref.style, | ||
className = _ref.className, | ||
classNames = _ref.classNames, | ||
rest = _objectWithoutProperties(_ref, ['style', 'className', 'classNames']); | ||
function WithDefaultStyle(props, context) { | ||
_classCallCheck(this, WithDefaultStyle); | ||
var substyle = (0, _createSubstyle2.default)({ style: style, className: className, classNames: classNames }); | ||
var modifiers = getModifiers && getModifiers(rest); | ||
var _this = _possibleConstructorReturn(this, (WithDefaultStyle.__proto__ || Object.getPrototypeOf(WithDefaultStyle)).call(this, props, context)); | ||
return (0, _react.createElement)(enhance(WrappedComponent), _extends({ style: substyle(modifiers, defaultStyle) }, rest)); | ||
} | ||
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this); | ||
return _this; | ||
} | ||
_createClass(WithDefaultStyle, [{ | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
style = _props.style, | ||
className = _props.className, | ||
classNames = _props.classNames, | ||
rest = _objectWithoutProperties(_props, ['style', 'className', 'classNames']); | ||
var substyle = (0, _createSubstyle2.default)({ style: style, className: className, classNames: classNames }); | ||
var modifiers = getModifiers && getModifiers(rest); | ||
return (0, _react.createElement)(this.getWrappedComponent(), _extends({ | ||
style: substyle(modifiers, defaultStyle), | ||
ref: this.setWrappedInstance | ||
}, rest)); | ||
} | ||
}, { | ||
key: 'getWrappedComponent', | ||
value: function getWrappedComponent() { | ||
var _context$ENHANCER_CON = this.context[_types.ENHANCER_CONTEXT_NAME], | ||
enhance = _context$ENHANCER_CON === undefined ? _lodash.identity : _context$ENHANCER_CON; | ||
if (this.memoizedEnhance !== enhance) { | ||
this.memoizedEnhance = enhance; | ||
this.enhancedWrappedComponent = enhance(WrappedComponent); | ||
} | ||
return this.enhancedWrappedComponent || WrappedComponent; | ||
} | ||
}, { | ||
key: 'getWrappedInstance', | ||
value: function getWrappedInstance() { | ||
return this.wrappedInstance; | ||
} | ||
}, { | ||
key: 'setWrappedInstance', | ||
value: function setWrappedInstance(ref) { | ||
this.wrappedInstance = ref; | ||
} | ||
}]); | ||
return WithDefaultStyle; | ||
}(_react.Component); | ||
var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name; | ||
WithDefaultStyle.displayName = 'withDefaultStyle(' + wrappedComponentName + ')'; | ||
WithDefaultStyle.contextTypes = _defineProperty({}, _types.ENHANCER_CONTEXT_NAME, _react.PropTypes.func); | ||
// define prop types based on WrappedComponent's prop types | ||
WithDefaultStyle.propTypes = _extends({}, WrappedComponent.propTypes, _types.PropTypes); | ||
return WithDefaultStyle; | ||
WithDefaultStyle.contextTypes = _types.ContextTypes; | ||
// expose WrappedComponent, e.g., for testing purposes | ||
WithDefaultStyle.WrappedComponent = WrappedComponent; | ||
return (0, _hoistNonReactStatics2.default)(WithDefaultStyle, WrappedComponent); | ||
}; | ||
@@ -51,0 +114,0 @@ }; |
@@ -53,5 +53,5 @@ 'use strict'; | ||
EnhancerProvider.childContextTypes = _defineProperty({}, _types.ENHANCER_CONTEXT_NAME, _react.PropTypes.func); | ||
EnhancerProvider.childContextTypes = _types.ContextTypes; | ||
EnhancerProvider.displayName = 'EnhancerProvider'; | ||
module.exports = exports['default']; |
@@ -6,4 +6,23 @@ 'use strict'; | ||
}); | ||
exports.ContextTypes = exports.PropTypes = exports.ENHANCER_CONTEXT_NAME = undefined; | ||
/* eslint-disable import/prefer-default-export */ | ||
var ENHANCER_CONTEXT_NAME = exports.ENHANCER_CONTEXT_NAME = '__substyle__Enhancer'; | ||
var _react = require('react'); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var ENHANCER_CONTEXT_NAME = exports.ENHANCER_CONTEXT_NAME = '__substyle__Enhancer'; | ||
var StylePT = _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.object]); | ||
var ClassNamesPT = _react.PropTypes.objectOf(_react.PropTypes.shape({ | ||
className: _react.PropTypes.string, | ||
classNames: ClassNamesPT | ||
})); | ||
var PropTypes = exports.PropTypes = { | ||
style: StylePT, | ||
className: _react.PropTypes.string, | ||
classNames: ClassNamesPT | ||
}; | ||
var ContextTypes = exports.ContextTypes = _defineProperty({}, ENHANCER_CONTEXT_NAME, _react.PropTypes.func); |
{ | ||
"name": "substyle", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "Universal styling for reusable React components", | ||
@@ -33,2 +33,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"hoist-non-react-statics": "^1.2.0", | ||
"invariant": "^2.2.0", | ||
@@ -53,2 +54,3 @@ "lodash": "^4.3.0", | ||
"eslint-plugin-mocha": "^4.7.0", | ||
"jsdom": "^9.10.0", | ||
"mocha": "^2.4.5", | ||
@@ -55,0 +57,0 @@ "react": "^15.4.1", |
@@ -81,2 +81,8 @@ # substyle | ||
### Organize default styles | ||
- essential styles: co-located with component | ||
- nice example styles/different themes: extra export, css file, or both | ||
## API | ||
@@ -83,0 +89,0 @@ |
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
40432
317
127
5
21
+ Addedhoist-non-react-statics@1.2.0(transitive)