@callstack/react-theme-provider
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -12,4 +12,2 @@ "use strict"; | ||
var _utils = require("./utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -21,2 +19,4 @@ | ||
function _objectWithoutPropertiesLoose(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]; } return target; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
@@ -28,6 +28,2 @@ | ||
var isClassComponent = function isClassComponent(Component) { | ||
return Boolean(Component.prototype && Component.prototype.isReactComponent); | ||
}; | ||
var createWithTheme = function createWithTheme(ThemeProvider, ThemeContext) { | ||
@@ -58,3 +54,3 @@ return function withTheme(Comp) { | ||
var result = a && b ? (0, _deepmerge.default)(a, b) : a || b; | ||
var result = a && b && a !== b ? (0, _deepmerge.default)(a, b) : a || b; | ||
_this._previous = { | ||
@@ -68,4 +64,2 @@ a: a, | ||
_defineProperty(_assertThisInitialized(_this), "_root", void 0); | ||
return _this; | ||
@@ -79,23 +73,15 @@ } | ||
var _this$props = this.props, | ||
_reactThemeProviderForwardedRef = _this$props._reactThemeProviderForwardedRef, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["_reactThemeProviderForwardedRef"]); | ||
return React.createElement(ThemeContext.Consumer, null, function (theme) { | ||
var merged = _this2._merge(theme, _this2.props.theme); | ||
var merged = _this2._merge(theme, rest.theme); | ||
var element; | ||
var element = React.createElement(Comp, _extends({}, rest, { | ||
theme: merged, | ||
ref: _reactThemeProviderForwardedRef | ||
})); | ||
if (isClassComponent(Comp)) { | ||
// Only add refs for class components as function components don't support them | ||
// It's needed to support use cases which need access to the underlying node | ||
element = React.createElement(Comp, _extends({}, _this2.props, { | ||
ref: function ref(c) { | ||
_this2._root = c; | ||
}, | ||
theme: merged | ||
})); | ||
} else { | ||
element = React.createElement(Comp, _extends({}, _this2.props, { | ||
theme: merged | ||
})); | ||
} | ||
if (merged !== _this2.props.theme) { | ||
if (rest.theme && merged !== rest.theme) { | ||
// If a theme prop was passed, expose it to the children | ||
@@ -114,18 +100,10 @@ return React.createElement(ThemeProvider, { | ||
_defineProperty(ThemedComponent, "displayName", "withTheme(" + (Comp.displayName || Comp.name) + ")"); | ||
if (isClassComponent(Comp)) { | ||
// getWrappedInstance is exposed by some HOCs like react-redux's connect | ||
// Use it to get the ref to the underlying element | ||
// Also expose it to access the underlying element after wrapping | ||
// $FlowFixMe | ||
ThemedComponent.prototype.getWrappedInstance = function getWrappedInstance() { | ||
return this._root && this._root.getWrappedInstance ? this._root.getWrappedInstance() : this._root; | ||
}; | ||
ThemedComponent = (0, _utils.copyRefs)(ThemedComponent, Comp); | ||
} | ||
(0, _hoistNonReactStatics.default)(ThemedComponent, Comp); | ||
return ThemedComponent; | ||
var ResultComponent = React.forwardRef(function (props, ref) { | ||
return React.createElement(ThemedComponent, _extends({}, props, { | ||
_reactThemeProviderForwardedRef: ref | ||
})); | ||
}); | ||
ResultComponent.displayName = "withTheme(" + (Comp.displayName || Comp.name) + ")"; | ||
(0, _hoistNonReactStatics.default)(ResultComponent, Comp); | ||
return ResultComponent; | ||
}; | ||
@@ -132,0 +110,0 @@ }; |
{ | ||
"name": "@callstack/react-theme-provider", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Theme provider for react and react-naitve applications", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
32217
20
206