PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.3
GenerateBlocks v1.8.3
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / hoc / withDocumentation.js
generateblocks / src / hoc Last commit date
migrations 2 years ago index.js 2 years ago withButtonContainerLegacyMigration.js 2 years ago withButtonLegacyMigration.js 2 years ago withContainerLegacyMigration.js 2 years ago withDeviceType.js 3 years ago withDocumentation.js 4 years ago withGridLegacyMigration.js 2 years ago withHeadlineLegacyMigration.js 2 years ago withImageLegacyMigration.js 2 years ago withSetAttributes.js 2 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