index.js
4 years ago
withButtonContainerLegacyMigration.js
4 years ago
withButtonLegacyMigration.js
4 years ago
withContainerLegacyMigration.js
4 years ago
withDocumentation.js
4 years ago
withGridLegacyMigration.js
4 years ago
withResponsiveTabs.js
4 years ago
withUniqueId.js
4 years ago
withResponsiveTabs.js
54 lines
| 1 | import { createHigherOrderComponent } from '@wordpress/compose'; |
| 2 | import { addFilter, applyFilters } from '@wordpress/hooks'; |
| 3 | import { InspectorControls } from '@wordpress/block-editor'; |
| 4 | import ResponsiveTabs from '../components/responsive-tabs'; |
| 5 | import { useDeviceType } from '../hooks'; |
| 6 | |
| 7 | const withResponsiveTabs = createHigherOrderComponent( ( BlockEdit ) => { |
| 8 | return ( props ) => { |
| 9 | const { |
| 10 | name, |
| 11 | } = props; |
| 12 | |
| 13 | const blocks = applyFilters( |
| 14 | 'generateblocks.editor.responsiveTabBlocks', |
| 15 | [ |
| 16 | 'generateblocks/button', |
| 17 | 'generateblocks/button-container', |
| 18 | 'generateblocks/container', |
| 19 | 'generateblocks/grid', |
| 20 | 'generateblocks/headline', |
| 21 | 'generateblocks/image', |
| 22 | ], |
| 23 | props, |
| 24 | ); |
| 25 | |
| 26 | if ( ! blocks.includes( name ) ) { |
| 27 | return <BlockEdit { ...props } />; |
| 28 | } |
| 29 | |
| 30 | const [ deviceType, setDeviceType ] = useDeviceType( 'Desktop' ); |
| 31 | |
| 32 | return ( |
| 33 | <> |
| 34 | <InspectorControls> |
| 35 | <ResponsiveTabs |
| 36 | { ...props } |
| 37 | selectedDevice={ deviceType } |
| 38 | onClick={ setDeviceType } |
| 39 | /> |
| 40 | </InspectorControls> |
| 41 | |
| 42 | <BlockEdit { ...props } /> |
| 43 | </> |
| 44 | ); |
| 45 | }; |
| 46 | }, 'withResponsiveTabs' ); |
| 47 | |
| 48 | addFilter( |
| 49 | 'editor.BlockEdit', |
| 50 | 'generateblocks/with-responsive-tabs', |
| 51 | withResponsiveTabs, |
| 52 | 1 |
| 53 | ); |
| 54 |