@shopgate/engage
Version:
Shopgate's ENGAGE library.
10 lines • 983 B
JavaScript
import PropTypes from'prop-types';/**
* Conditionally wraps React children with another component.
* @param {Object} props The component props.
* @returns {JSX}
*/var ConditionalWrapper=function ConditionalWrapper(_ref){var condition=_ref.condition,wrapper=_ref.wrapper,wrapperFalsy=_ref.wrapperFalsy,children=_ref.children;if(condition){return wrapper(children);}return typeof wrapperFalsy==='function'?wrapperFalsy(children):children;};ConditionalWrapper.propTypes={/**
* When set to `true`, the component children will be wrapped by the React component which is
* defined in `wrapper`.
* When the to `false`, the component children will be wrapped by the React component which is
* optionally defined in `wrapperFalsy`.
*/condition:PropTypes.bool.isRequired,children:PropTypes.node,wrapper:PropTypes.elementType,wrapperFalsy:PropTypes.elementType};ConditionalWrapper.defaultProps={children:null,wrapper:null,wrapperFalsy:null};export default ConditionalWrapper;