PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.3
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.3
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / blocks / divider / edit.js

edit.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.3, at gutenberg/blocks/divider/edit.js

263 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2
3 import {
4 BlockControls,
5 InspectorControls,
6 useBlockProps,
7 } from '@wordpress/block-editor';
8 import {
9 PanelBody,
10 SelectControl,
11 TabPanel,
12 ToolbarDropdownMenu,
13 ToolbarGroup,
14 } from '@wordpress/components';
15 import { applyFilters } from '@wordpress/hooks';
16 import { __ } from '@wordpress/i18n';
17
18 import ApplyFilters from '../../components/apply-filters';
19 import ColorIndicator from '../../components/color-indicator';
20 import ColorPicker from '../../components/color-picker';
21 import IconPicker from '../../components/icon-picker';
22 import RangeControl from '../../components/range-control';
23 import getIcon from '../../utils/get-icon';
24
25 /**
26 * Block Edit Class.
27 *
28 * @param props
29 */
30 export default function BlockEdit(props) {
31 const { attributes, setAttributes } = props;
32 let { className = '' } = props;
33
34 const {
35 type,
36 size,
37 icon,
38 iconSize,
39 color,
40 iconColor,
41 hoverColor,
42 hoverIconColor,
43 } = attributes;
44
45 className = classnames(
46 'ghostkit-divider',
47 `ghostkit-divider-type-${type}`,
48 className
49 );
50
51 if (icon) {
52 className = classnames(className, 'ghostkit-divider-with-icon');
53 }
54
55 className = applyFilters('ghostkit.editor.className', className, props);
56
57 const blockProps = useBlockProps({ className });
58
59 return (
60 <>
61 <BlockControls>
62 <ToolbarGroup>
63 <ToolbarDropdownMenu
64 icon={getIcon('border-solid')}
65 label={__('Type', 'ghostkit')}
66 controls={[
67 {
68 label: __('Line', 'ghostkit'),
69 icon: getIcon('border-solid'),
70 isActive: type === 'solid',
71 onClick: () => setAttributes({ type: 'solid' }),
72 },
73 {
74 label: __('Dashed', 'ghostkit'),
75 icon: getIcon('border-dashed'),
76 isActive: type === 'dashed',
77 onClick: () =>
78 setAttributes({ type: 'dashed' }),
79 },
80 {
81 label: __('Dotted', 'ghostkit'),
82 icon: getIcon('border-dotted'),
83 isActive: type === 'dotted',
84 onClick: () =>
85 setAttributes({ type: 'dotted' }),
86 },
87 {
88 label: __('Double', 'ghostkit'),
89 icon: getIcon('border-double'),
90 isActive: type === 'double',
91 onClick: () =>
92 setAttributes({ type: 'double' }),
93 },
94 ]}
95 />
96 </ToolbarGroup>
97 </BlockControls>
98 <InspectorControls>
99 <PanelBody>
100 <SelectControl
101 label={__('Type', 'ghostkit')}
102 value={type}
103 options={[
104 {
105 value: 'solid',
106 label: __('Line', 'ghostkit'),
107 },
108 {
109 value: 'dashed',
110 label: __('Dashed', 'ghostkit'),
111 },
112 {
113 value: 'dotted',
114 label: __('Dotted', 'ghostkit'),
115 },
116 {
117 value: 'double',
118 label: __('Double', 'ghostkit'),
119 },
120 ]}
121 onChange={(value) => setAttributes({ type: value })}
122 />
123 <RangeControl
124 label={__('Size', 'ghostkit')}
125 value={size}
126 onChange={(value) => setAttributes({ size: value })}
127 min={1}
128 max={7}
129 beforeIcon="editor-textcolor"
130 afterIcon="editor-textcolor"
131 allowCustomMax
132 />
133 </PanelBody>
134 <PanelBody>
135 <IconPicker
136 label={__('Icon', 'ghostkit')}
137 value={icon}
138 onChange={(value) => setAttributes({ icon: value })}
139 insideInspector
140 />
141 {icon ? (
142 <RangeControl
143 label={__('Icon Size', 'ghostkit')}
144 value={iconSize}
145 onChange={(value) =>
146 setAttributes({ iconSize: value })
147 }
148 min={10}
149 beforeIcon="editor-textcolor"
150 afterIcon="editor-textcolor"
151 allowCustomMin
152 allowCustomMax
153 />
154 ) : null}
155 </PanelBody>
156 <PanelBody
157 title={
158 <>
159 {__('Colors', 'ghostkit')}
160 <ColorIndicator colorValue={color} />
161 {icon ? (
162 <ColorIndicator colorValue={iconColor} />
163 ) : null}
164 </>
165 }
166 initialOpen={false}
167 >
168 <TabPanel
169 className="ghostkit-control-tabs ghostkit-control-tabs-wide"
170 tabs={[
171 {
172 name: 'normal',
173 title: __('Normal', 'ghostkit'),
174 className: 'ghostkit-control-tabs-tab',
175 },
176 {
177 name: 'hover',
178 title: __('Hover', 'ghostkit'),
179 className: 'ghostkit-control-tabs-tab',
180 },
181 ]}
182 >
183 {(tabData) => {
184 const isHover = tabData.name === 'hover';
185 return (
186 <>
187 <ApplyFilters
188 name="ghostkit.editor.controls"
189 attribute={
190 isHover ? 'hoverColor' : 'color'
191 }
192 props={props}
193 >
194 <ColorPicker
195 label={__('Divider', 'ghostkit')}
196 value={isHover ? hoverColor : color}
197 onChange={(val) =>
198 setAttributes(
199 isHover
200 ? { hoverColor: val }
201 : { color: val }
202 )
203 }
204 alpha
205 />
206 </ApplyFilters>
207 {icon ? (
208 <ApplyFilters
209 name="ghostkit.editor.controls"
210 attribute={
211 isHover
212 ? 'hoverIconColor'
213 : 'iconColor'
214 }
215 props={props}
216 >
217 <ColorPicker
218 label={__('Icon', 'ghostkit')}
219 value={
220 isHover
221 ? hoverIconColor
222 : iconColor
223 }
224 onChange={(val) =>
225 setAttributes(
226 isHover
227 ? {
228 hoverIconColor:
229 val,
230 }
231 : { iconColor: val }
232 )
233 }
234 alpha
235 />
236 </ApplyFilters>
237 ) : null}
238 </>
239 );
240 }}
241 </TabPanel>
242 </PanelBody>
243 </InspectorControls>
244 <div {...blockProps}>
245 {icon ? (
246 <div className="ghostkit-divider-icon">
247 <IconPicker.Dropdown
248 onChange={(value) => setAttributes({ icon: value })}
249 value={icon}
250 renderToggle={({ onToggle }) => (
251 <IconPicker.Preview
252 onClick={onToggle}
253 name={icon}
254 />
255 )}
256 />
257 </div>
258 ) : null}
259 </div>
260 </>
261 );
262 }
263