PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.4.1
Block Animations, Motion & Scroll Effects – Ghost Kit v3.4.1
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.4.1, at gutenberg/blocks/divider/edit.js

269 lines 6.1 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 __next40pxDefaultSize
123 __nextHasNoMarginBottom
124 />
125 <RangeControl
126 label={__('Size', 'ghostkit')}
127 value={size}
128 onChange={(value) => setAttributes({ size: value })}
129 min={1}
130 max={7}
131 beforeIcon="editor-textcolor"
132 afterIcon="editor-textcolor"
133 allowCustomMax
134 __next40pxDefaultSize
135 __nextHasNoMarginBottom
136 />
137 </PanelBody>
138 <PanelBody>
139 <IconPicker
140 label={__('Icon', 'ghostkit')}
141 value={icon}
142 onChange={(value) => setAttributes({ icon: value })}
143 insideInspector
144 />
145 {icon ? (
146 <RangeControl
147 label={__('Icon Size', 'ghostkit')}
148 value={iconSize}
149 onChange={(value) =>
150 setAttributes({ iconSize: value })
151 }
152 min={10}
153 beforeIcon="editor-textcolor"
154 afterIcon="editor-textcolor"
155 allowCustomMin
156 allowCustomMax
157 __next40pxDefaultSize
158 __nextHasNoMarginBottom
159 />
160 ) : null}
161 </PanelBody>
162 <PanelBody
163 title={
164 <>
165 {__('Colors', 'ghostkit')}
166 <ColorIndicator colorValue={color} />
167 {icon ? (
168 <ColorIndicator colorValue={iconColor} />
169 ) : null}
170 </>
171 }
172 initialOpen={false}
173 >
174 <TabPanel
175 className="ghostkit-control-tabs ghostkit-control-tabs-wide"
176 tabs={[
177 {
178 name: 'normal',
179 title: __('Normal', 'ghostkit'),
180 className: 'ghostkit-control-tabs-tab',
181 },
182 {
183 name: 'hover',
184 title: __('Hover', 'ghostkit'),
185 className: 'ghostkit-control-tabs-tab',
186 },
187 ]}
188 >
189 {(tabData) => {
190 const isHover = tabData.name === 'hover';
191 return (
192 <>
193 <ApplyFilters
194 name="ghostkit.editor.controls"
195 attribute={
196 isHover ? 'hoverColor' : 'color'
197 }
198 props={props}
199 >
200 <ColorPicker
201 label={__('Divider', 'ghostkit')}
202 value={isHover ? hoverColor : color}
203 onChange={(val) =>
204 setAttributes(
205 isHover
206 ? { hoverColor: val }
207 : { color: val }
208 )
209 }
210 alpha
211 />
212 </ApplyFilters>
213 {icon ? (
214 <ApplyFilters
215 name="ghostkit.editor.controls"
216 attribute={
217 isHover
218 ? 'hoverIconColor'
219 : 'iconColor'
220 }
221 props={props}
222 >
223 <ColorPicker
224 label={__('Icon', 'ghostkit')}
225 value={
226 isHover
227 ? hoverIconColor
228 : iconColor
229 }
230 onChange={(val) =>
231 setAttributes(
232 isHover
233 ? {
234 hoverIconColor:
235 val,
236 }
237 : { iconColor: val }
238 )
239 }
240 alpha
241 />
242 </ApplyFilters>
243 ) : null}
244 </>
245 );
246 }}
247 </TabPanel>
248 </PanelBody>
249 </InspectorControls>
250 <div {...blockProps}>
251 {icon ? (
252 <div className="ghostkit-divider-icon">
253 <IconPicker.Dropdown
254 onChange={(value) => setAttributes({ icon: value })}
255 value={icon}
256 renderToggle={({ onToggle }) => (
257 <IconPicker.Preview
258 onClick={onToggle}
259 name={icon}
260 />
261 )}
262 />
263 </div>
264 ) : null}
265 </div>
266 </>
267 );
268 }
269