PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.3
GenerateBlocks v1.5.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 / components / panel-area / index.js
generateblocks / src / components / panel-area Last commit date
index.js 4 years ago
index.js
86 lines
1 import ApplyFilters from '../apply-filters/';
2
3 import { PanelBody } from '@wordpress/components';
4 import { applyFilters } from '@wordpress/hooks';
5 import useLocalStorageState from 'use-local-storage-state';
6
7 export default function PanelArea( props ) {
8 const {
9 title = false,
10 initialOpen = false,
11 icon,
12 className,
13 id,
14 state,
15 showPanel = true,
16 children,
17 } = props;
18
19 const [ panels, setPanels ] = useLocalStorageState(
20 'generateblocksPanels', {
21 ssr: true,
22 defaultValue: {},
23 }
24 );
25
26 const show = applyFilters( 'generateblocks.editor.showPanel', showPanel, id, props );
27
28 if ( ! show ) {
29 return null;
30 }
31
32 let hasChildren = true;
33
34 if ( '' === children ) {
35 hasChildren = false;
36 }
37
38 // If we have items in the panel, make sure they're not empty.
39 if ( 'object' === typeof children ) {
40 hasChildren = Object.values( children ).some( ( x ) => ( x !== null && x !== false && x !== '' ) );
41 }
42
43 if ( ! hasChildren ) {
44 return null;
45 }
46
47 return (
48 <ApplyFilters name={ 'generateblocks.panel.' + id } props={ props } state={ state }>
49 { title ? (
50 <PanelBody
51 title={ title }
52 initialOpen={
53 'undefined' !== typeof panels[ id ]
54 ? panels[ id ]
55 : initialOpen
56 }
57 icon={ icon }
58 className={ className }
59 onToggle={ () => {
60 const isOpen = panels[ id ] ||
61 (
62 'undefined' === typeof panels[ id ] &&
63 initialOpen
64 );
65
66 setPanels( {
67 ...panels,
68 [ id ]: ! isOpen,
69 } );
70 } }
71 >
72 {
73 applyFilters( 'generateblocks.editor.panelContents', children, id, props )
74 }
75 </PanelBody>
76 ) : (
77 <PanelBody>
78 {
79 applyFilters( 'generateblocks.editor.panelContents', children, id, props )
80 }
81 </PanelBody>
82 ) }
83 </ApplyFilters>
84 );
85 }
86