wix-style-react
Version:
107 lines (93 loc) • 4.29 kB
JavaScript
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React from 'react';
import PropTypes from 'prop-types';
import kebabCase from 'lodash/kebabCase';
import { ThemeContext } from './ThemeContext';
/** ThemeProvider */
var ThemeProvider = /*#__PURE__*/function (_React$PureComponent) {
_inherits(ThemeProvider, _React$PureComponent);
var _super = _createSuper(ThemeProvider);
function ThemeProvider() {
_classCallCheck(this, ThemeProvider);
return _super.apply(this, arguments);
}
_createClass(ThemeProvider, [{
key: "_parseTheme",
value: function _parseTheme(theme) {
var style = {};
for (var _i = 0, _Object$entries = Object.entries(theme); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
key = _Object$entries$_i[0],
value = _Object$entries$_i[1];
if (key !== 'className' && key !== 'icons' && key !== 'componentWrapper') {
style["--wsr-".concat(kebabCase(key))] = value;
}
}
return style;
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
dataHook = _this$props.dataHook,
_this$props$theme = _this$props.theme,
theme = _this$props$theme === void 0 ? {} : _this$props$theme,
children = _this$props.children;
return /*#__PURE__*/React.createElement("div", {
className: theme.className,
style: this._parseTheme(theme),
"data-hook": dataHook
}, /*#__PURE__*/React.createElement(ThemeContext.Provider, {
value: {
icons: theme.icons,
className: theme.className
}
}, theme.componentWrapper ? theme.componentWrapper({
children: children
}) : children));
}
}]);
return ThemeProvider;
}(React.PureComponent);
ThemeProvider.displayName = 'ThemeProvider';
ThemeProvider.propTypes = {
/** Applied as data-hook HTML attribute that can be used in the tests */
dataHook: PropTypes.string,
/** A theme object */
theme: PropTypes.shape({
className: PropTypes.string,
// Applies a main class on the root element, useful when theming with the stylable approach
icons: PropTypes.object,
// an object of icons mapping per component
componentWrapper: PropTypes.func,
// a function that returns a component to be placed between the theme and the children
color00: PropTypes.string,
color05: PropTypes.string,
color10: PropTypes.string,
color20: PropTypes.string,
color30: PropTypes.string,
color40: PropTypes.string,
color50: PropTypes.string,
color60: PropTypes.string,
textColorPrimary: PropTypes.string,
textColorSecondary: PropTypes.string,
textColorPrimaryLight: PropTypes.string,
textColorSecondaryLight: PropTypes.string,
dividerColor: PropTypes.string,
borderRadius02: PropTypes.string,
borderRadius04: PropTypes.string,
borderRadius06: PropTypes.string,
borderRadius08: PropTypes.string,
// Button
buttonBorderRadius: PropTypes.string
})
};
ThemeProvider.defaultProps = {};
export default ThemeProvider;