PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.0
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 / extend / inspector-control / index.js
generateblocks / src / extend / inspector-control Last commit date
controls 1 year ago index.js 2 years ago
index.js
128 lines
1 import { InspectorControls } from '@wordpress/block-editor';
2 import { useContext, useState, useEffect } from '@wordpress/element';
3
4 import ControlsContext from '../../block-context';
5 import ResponsiveTabs from './controls/responsive-tabs';
6 import TypographyControls from './controls/typography';
7 import SpacingControls from './controls/spacing';
8 import BorderControls from './controls/borders';
9 import ColorsControls from './controls/colors';
10 import IconControls from './controls/icon';
11 import SettingsPanel from './controls/settings-panel';
12 import BackgroundPanel from './controls/background-panel';
13 import ShapesPanel from './controls/shapes-panel';
14 import LayoutControls from './controls/layout';
15 import SizingControls from './controls/sizing';
16 import getDeviceType from '../../utils/get-device-type';
17 import { useSelectedBlockElement } from '../../hooks';
18
19 export default function GenerateBlocksInspectorControls( { attributes, setAttributes, children } ) {
20 const device = getDeviceType();
21 const {
22 supports: {
23 responsiveTabs,
24 settingsPanel,
25 layout,
26 typography,
27 spacing,
28 borders,
29 colors,
30 backgroundPanel,
31 shapesPanel,
32 icon,
33 sizingPanel,
34 },
35 } = useContext( ControlsContext );
36 const selectedBlockElement = useSelectedBlockElement();
37 const selectedBlockElementClientId = selectedBlockElement ? selectedBlockElement?.dataset.block : 0;
38 const [ computedStyles, setComputedStyles ] = useState( {} );
39
40 useEffect( () => {
41 if ( selectedBlockElement ) {
42 setComputedStyles( getComputedStyle( selectedBlockElement ) );
43 }
44 }, [ selectedBlockElementClientId ] );
45
46 return (
47 <InspectorControls>
48 { responsiveTabs && <ResponsiveTabs /> }
49
50 { settingsPanel.enabled && !! children &&
51 <SettingsPanel>{ children }</SettingsPanel>
52 }
53
54 { layout.enabled &&
55 <LayoutControls
56 attributes={ attributes }
57 setAttributes={ setAttributes }
58 computedStyles={ computedStyles }
59 />
60 }
61
62 { sizingPanel.enabled &&
63 <SizingControls
64 attributes={ attributes }
65 setAttributes={ setAttributes }
66 computedStyles={ computedStyles }
67 />
68 }
69
70 { spacing.enabled &&
71 <SpacingControls
72 attributes={ attributes }
73 setAttributes={ setAttributes }
74 computedStyles={ computedStyles }
75 />
76 }
77
78 { borders.enabled &&
79 <BorderControls
80 attributes={ attributes }
81 setAttributes={ setAttributes }
82 computedStyles={ computedStyles }
83 />
84 }
85
86 { typography.enabled && ! attributes.removeText &&
87 <TypographyControls
88 attributes={ attributes }
89 setAttributes={ setAttributes }
90 computedStyles={ computedStyles }
91 />
92 }
93
94 { colors.enabled && 'Desktop' === device &&
95 <ColorsControls
96 attributes={ attributes }
97 setAttributes={ setAttributes }
98 computedStyles={ computedStyles }
99 />
100 }
101
102 { backgroundPanel.enabled && 'Desktop' === device &&
103 <BackgroundPanel
104 attributes={ attributes }
105 setAttributes={ setAttributes }
106 computedStyles={ computedStyles }
107 />
108 }
109
110 { shapesPanel.enabled && ( 'Desktop' === device || attributes?.shapeDividers.length > 0 ) &&
111 <ShapesPanel
112 attributes={ attributes }
113 setAttributes={ setAttributes }
114 computedStyles={ computedStyles }
115 />
116 }
117
118 { icon.enabled && ( 'Desktop' === device || !! attributes.icon ) &&
119 <IconControls
120 attributes={ attributes }
121 setAttributes={ setAttributes }
122 computedStyles={ computedStyles }
123 />
124 }
125 </InspectorControls>
126 );
127 }
128