wix-style-react
Version:
44 lines (39 loc) • 2.67 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["defaultIcons"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import React from 'react';
import { ThemeContext } from './ThemeContext';
/**
* This is a utility for every component that uses an icon to declare its defaults but also replace it with the theme context
* Usage Example:
*
* <ThemeProviderConsumerBackwardCompatible
* defaultIcons={{
* CloseButton: CloseIcon,
* }}
* >
* {({ icons }) => {
* const CloseIcon = icons.CloseButton
* return <CloseIcon data-hook="additional-content"/>
* }
* }
* </ThemeProviderConsumerBackwardCompatible>
*
* Note that this implementation is temporary and needed only to preserve backwards compatability for components with built-in icons (like CloseButton).
* It will be removed in the future once a <ThemeProvider/> will be required on the top of any theme, including the default one.
* This will assist in creating smaller bundle size for themes that would override the default icons. */
export var ThemeProviderConsumerBackwardCompatible = function ThemeProviderConsumerBackwardCompatible(_ref) {
var _ref$defaultIcons = _ref.defaultIcons,
defaultIcons = _ref$defaultIcons === void 0 ? {} : _ref$defaultIcons,
rest = _objectWithoutProperties(_ref, _excluded);
return /*#__PURE__*/React.createElement(ThemeContext.Consumer, null, function (context) {
return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
value: {
icons: _objectSpread(_objectSpread({}, defaultIcons), context && context.icons),
className: context && context.className
}
}, /*#__PURE__*/React.createElement(ThemeContext.Consumer, rest));
});
};