withDynamicContent.js
28 lines
| 1 | import { Fragment } from '@wordpress/element'; |
| 2 | import InspectorControls from '../InspectorControls'; |
| 3 | import DynamicRenderer from '../DynamicRenderer'; |
| 4 | |
| 5 | export default ( WrappedComponent ) => { |
| 6 | return ( props ) => { |
| 7 | const { attributes, setAttributes, context, name } = props; |
| 8 | |
| 9 | const newProps = attributes.useDynamicData && |
| 10 | ( !! attributes.dynamicContentType || !! attributes.dynamicLinkType ) |
| 11 | ? Object.assign( {}, props, { |
| 12 | ContentRenderer: DynamicRenderer, |
| 13 | } ) : props; |
| 14 | |
| 15 | return ( |
| 16 | <Fragment> |
| 17 | <WrappedComponent { ...newProps } /> |
| 18 | <InspectorControls |
| 19 | context={ context } |
| 20 | attributes={ attributes } |
| 21 | setAttributes={ setAttributes } |
| 22 | name={ name } |
| 23 | /> |
| 24 | </Fragment> |
| 25 | ); |
| 26 | }; |
| 27 | }; |
| 28 |