@shopgate/engage
Version:
Shopgate's ENGAGE library.
13 lines • 1.4 kB
JavaScript
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{useWidgetSettings}from"../hooks/useWidgetSettings";/**
* Injects the widget - configuration - settings for a specific widget by its id and
* an optional index. into the desired component. If no index is given it will inject the first
* found widget - configuration - settings by widgetId.
* @param {Function} WrappedComponent The react component to wrap.
* @param {string} widgetId The id of the widget to look for, which must exist in the config.
* @param {number|undefined} [index] The optional index of the widget.
* @returns {JSX}
*/export function withWidgetSettings(WrappedComponent,widgetId,index){/**
* The actual HOC.
* @param {Object} props The component props.
* @returns {JSX}
*/var WithWidgetSettings=function WithWidgetSettings(props){var settings=useWidgetSettings(widgetId,index);return React.createElement(WrappedComponent,_extends({widgetSettings:settings},props));};var displayName=WrappedComponent.displayName||WrappedComponent.name||'Component';WithWidgetSettings.displayName="WithWidgetSettings(".concat(displayName,")");return WithWidgetSettings;}