@shopgate/engage
Version:
Shopgate's ENGAGE library.
17 lines • 2.65 kB
JavaScript
var _excluded=["contexts"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;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;}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 _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 _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import React from'react';import{ThemeContext}from'@shopgate/pwa-common/context';/**
* Gets the context props for the wrapped component.
* @param {Object} context The context.
* @param {string|null} prop The optional prop name.
* @returns {Object}
*/var getInjectedProps=function getInjectedProps(context,prop){if(!prop){return context;}return _defineProperty({},prop,_extends({},context));};/**
* Injects the theme API into the desired component. This does not include the contexts.
* @param {Function} WrappedComponent The react component to wrap.
* @param {Object} [options={}] Options for the HOC.
* @param {string} [options.prop] An optional prop name to inject the theme properties.
* @returns {JSX}
*/export function withTheme(WrappedComponent){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};/**
* The actual HOC.
* @param {Object} props The component props.
* @returns {JSX}
*/var WithTheme=function WithTheme(props){return React.createElement(ThemeContext.Consumer,null,function(_ref2){var contexts=_ref2.contexts,themeContext=_objectWithoutProperties(_ref2,_excluded);return(// The contexts are left out in favor of other HOCs.
React.createElement(WrappedComponent,_extends({},getInjectedProps(themeContext,options.prop),props)));});};var displayName=WrappedComponent.displayName||WrappedComponent.name||'Component';WithTheme.displayName="WithTheme(".concat(displayName,")");return WithTheme;}