@shopgate/engage
Version:
Shopgate's ENGAGE library.
15 lines • 1.8 kB
JavaScript
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{push,pop,replace,reset,update}from"../router/helpers";/**
* Gets the navigation props for the wrapped component.
* @param {string|null} prop The optional prop name.
* @returns {Object}
*/var getInjectedProps=function getInjectedProps(prop){var injected={historyPush:push,historyPop:pop,historyReplace:replace,historyReset:reset,historyUpdate:update};if(!prop){return injected;}return _defineProperty({},prop,_extends({},injected));};/**
* Injects navigation functions into the desired component.
* @param {Function} WrappedComponent The react component to wrap.
* @param {Object} [options] A optional prop name to inject the navigation properties.
* @param {string} [options.prop] An optional prop name to inject the navigation properties.
* @returns {JSX}
*/export function withNavigation(WrappedComponent){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};/**
* The actual HOC.
* @param {Object} props The component props.
* @returns {JSX}
*/var WithNavigation=function WithNavigation(props){return React.createElement(WrappedComponent,_extends({},getInjectedProps(options.prop),props));};var displayName=WrappedComponent.displayName||WrappedComponent.name||'Component';WithNavigation.displayName="WithNavigation(".concat(displayName,")");return WithNavigation;}