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
withDocumentation.js
88 lines
| 1 | import { createHigherOrderComponent } from '@wordpress/compose'; |
| 2 | import { Fragment } from '@wordpress/element'; |
| 3 | import { InspectorControls } from '@wordpress/block-editor'; |
| 4 | import { addFilter, applyFilters } from '@wordpress/hooks'; |
| 5 | import { __ } from '@wordpress/i18n'; |
| 6 | import PanelArea from '../components/panel-area'; |
| 7 | import getIcon from '../utils/get-icon'; |
| 8 | |
| 9 | const data = [ |
| 10 | { |
| 11 | name: 'generateblocks/button', |
| 12 | id: 'buttonDocumentation', |
| 13 | url: 'https://docs.generateblocks.com/collection/buttons/', |
| 14 | }, |
| 15 | { |
| 16 | name: 'generateblocks/button-container', |
| 17 | id: 'buttonContainerDocumentation', |
| 18 | url: 'https://docs.generateblocks.com/collection/buttons/', |
| 19 | }, |
| 20 | { |
| 21 | name: 'generateblocks/container', |
| 22 | id: 'containerDocumentation', |
| 23 | url: 'https://docs.generateblocks.com/collection/container/', |
| 24 | }, |
| 25 | { |
| 26 | name: 'generateblocks/grid', |
| 27 | id: 'gridDocumentation', |
| 28 | url: 'https://docs.generateblocks.com/collection/grid/', |
| 29 | }, |
| 30 | { |
| 31 | name: 'generateblocks/headline', |
| 32 | id: 'headlineDocumentation', |
| 33 | url: 'https://docs.generateblocks.com/collection/headline/', |
| 34 | }, |
| 35 | { |
| 36 | name: 'generateblocks/image', |
| 37 | id: 'imageDocumentation', |
| 38 | url: 'https://docs.generateblocks.com/collection/image/', |
| 39 | }, |
| 40 | ]; |
| 41 | |
| 42 | const withDocumentation = createHigherOrderComponent( ( BlockEdit ) => { |
| 43 | return ( props ) => { |
| 44 | const { |
| 45 | name, |
| 46 | state, |
| 47 | } = props; |
| 48 | |
| 49 | const blockData = data.find( ( obj ) => { |
| 50 | return name === obj.name; |
| 51 | } ); |
| 52 | |
| 53 | if ( ! blockData || 0 === blockData.length ) { |
| 54 | return <BlockEdit { ...props } />; |
| 55 | } |
| 56 | |
| 57 | return ( |
| 58 | <Fragment> |
| 59 | <BlockEdit { ...props } /> |
| 60 | |
| 61 | <InspectorControls> |
| 62 | <PanelArea |
| 63 | { ...props } |
| 64 | title={ __( 'Documentation', 'generateblocks' ) } |
| 65 | icon={ getIcon( 'documentation' ) } |
| 66 | initialOpen={ false } |
| 67 | className={ 'gblocks-panel-label' } |
| 68 | id={ blockData.id } |
| 69 | state={ state } |
| 70 | > |
| 71 | <p>{ __( 'Need help with this block?', 'generateblocks' ) }</p> |
| 72 | <a href={ blockData.url } target="_blank" rel="noreferrer noopener">{ __( 'Visit our documentation', 'generateblocks' ) }</a> |
| 73 | |
| 74 | { applyFilters( 'generateblocks.editor.controls', '', blockData.id, props, state ) } |
| 75 | </PanelArea> |
| 76 | </InspectorControls> |
| 77 | </Fragment> |
| 78 | ); |
| 79 | }; |
| 80 | }, 'withDocumentation' ); |
| 81 | |
| 82 | addFilter( |
| 83 | 'editor.BlockEdit', |
| 84 | 'generateblocks/with-documentation', |
| 85 | withDocumentation, |
| 86 | 99 |
| 87 | ); |
| 88 |