PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
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 / blocks / shape / components / BlockSettings.jsx
generateblocks / src / blocks / shape / components Last commit date
BlockSettings.jsx 1 year ago ShapeDividerControls.jsx 1 year ago
BlockSettings.jsx
151 lines
1 import { __ } from '@wordpress/i18n';
2 import { applyFilters } from '@wordpress/hooks';
3 import { Flex, FlexBlock } from '@wordpress/components';
4
5 import { OpenPanel, IconControl } from '@edge22/components';
6 import { UnitControl } from '@edge22/styles-builder';
7
8 import {
9 ApplyFilters,
10 ColorPickerControls,
11 } from '@components/index.js';
12 import { moreDesignOptions } from '@utils';
13 import { useBlockStyles } from '@hooks/useBlockStyles';
14 import generalSvgs from '@components/icon-picker/svgs-general';
15 import socialSvgs from '@components/icon-picker/svgs-social';
16 import { ShapeDividerControls } from './ShapeDividerControls';
17
18 export const shapeColorControls = [
19 {
20 label: 'Color',
21 id: 'shape-color',
22 items: [
23 {
24 tooltip: 'Color',
25 value: 'color',
26 selector: 'svg',
27 },
28 ],
29 },
30 ];
31
32 export function BlockSettings( {
33 getStyleValue,
34 onStyleChange,
35 name,
36 attributes,
37 setAttributes,
38 } ) {
39 const {
40 html,
41 className,
42 } = attributes;
43
44 const {
45 currentAtRule,
46 } = useBlockStyles();
47
48 const panelProps = {
49 name,
50 attributes,
51 setAttributes,
52 };
53
54 const iconType = className?.includes( 'gb-shape--divider' ) ? 'divider' : 'icon';
55
56 let icons = applyFilters(
57 'generateblocks.editor.iconSVGSets',
58 {
59 general: {
60 group: __( 'General', 'generateblocks' ),
61 svgs: generalSvgs,
62 },
63 social: {
64 group: __( 'Social', 'generateblocks' ),
65 svgs: socialSvgs,
66 },
67 },
68 { attributes }
69 );
70
71 if ( 'divider' === iconType ) {
72 icons = generateBlocksInfo.svgShapes;
73 }
74
75 return (
76 <ApplyFilters
77 name="generateblocks.editor.blockControls"
78 blockName={ name }
79 getStyleValue={ getStyleValue }
80 onStyleChange={ onStyleChange }
81 currentAtRule={ currentAtRule }
82 attributes={ attributes }
83 setAttributes={ setAttributes }
84 >
85 <OpenPanel
86 { ...panelProps }
87 shouldRender={ '' === currentAtRule }
88 panelId="shape"
89 >
90 <IconControl
91 label={ __( 'Shape', 'generateblocks' ) }
92 value={ html }
93 onChange={ ( value ) => setAttributes( { html: value } ) }
94 onClear={ () => setAttributes( { html: '' } ) }
95 icons={ icons }
96 iconType={ iconType }
97 clearLabel={ __( 'Clear', 'generateblocks' ) }
98 openLabel={ __( 'Open Library', 'generateblocks' ) }
99 modalTitle={ __( 'Shape Library', 'generateblocks' ) }
100 />
101
102 <ShapeDividerControls
103 onStyleChange={ onStyleChange }
104 getStyleValue={ getStyleValue }
105 />
106 </OpenPanel>
107
108 <OpenPanel
109 { ...panelProps }
110 dropdownOptions={ [
111 moreDesignOptions,
112 ] }
113 panelId="design"
114 >
115 <Flex>
116 <FlexBlock>
117 <UnitControl
118 id="width"
119 label={ __( 'Width', 'generateblocks' ) }
120 value={ getStyleValue( 'width', currentAtRule, 'svg' ) }
121 onChange={ ( value ) => onStyleChange( 'width', value, currentAtRule, 'svg' ) }
122 />
123 </FlexBlock>
124
125 <FlexBlock>
126 <UnitControl
127 id="height"
128 label={ __( 'Height', 'generateblocks' ) }
129 value={ getStyleValue( 'height', currentAtRule, 'svg' ) }
130 onChange={ ( value ) => onStyleChange( 'height', value, currentAtRule, 'svg' ) }
131 />
132 </FlexBlock>
133 </Flex>
134
135 <ColorPickerControls
136 items={ shapeColorControls }
137 getStyleValue={ getStyleValue }
138 onStyleChange={ onStyleChange }
139 currentAtRule={ currentAtRule }
140 />
141 </OpenPanel>
142
143 <OpenPanel
144 { ...panelProps }
145 shouldRender={ '' === currentAtRule }
146 panelId="settings"
147 />
148 </ApplyFilters>
149 );
150 }
151