PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.2
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 / icon-box / edit.js

edit.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.2, at gutenberg/blocks/icon-box/edit.js

316 lines 7.4 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 InnerBlocks,
6 InspectorControls,
7 useBlockProps,
8 useInnerBlocksProps,
9 } from '@wordpress/block-editor';
10 import {
11 BaseControl,
12 PanelBody,
13 TabPanel,
14 ToggleControl,
15 Toolbar,
16 ToolbarButton,
17 ToolbarGroup,
18 } from '@wordpress/components';
19 import { useSelect } from '@wordpress/data';
20 import { applyFilters } from '@wordpress/hooks';
21 import { __ } from '@wordpress/i18n';
22
23 import ApplyFilters from '../../components/apply-filters';
24 import ColorIndicator from '../../components/color-indicator';
25 import ColorPicker from '../../components/color-picker';
26 import IconPicker from '../../components/icon-picker';
27 import RangeControl from '../../components/range-control';
28 import ToggleGroup from '../../components/toggle-group';
29 import URLPicker from '../../components/url-picker';
30 import getIcon from '../../utils/get-icon';
31
32 /**
33 * Block Edit Class.
34 *
35 * @param props
36 */
37 export default function BlockEdit(props) {
38 const { attributes, setAttributes, isSelected, clientId } = props;
39
40 let { className = '' } = props;
41
42 const {
43 icon,
44 iconPosition,
45 iconAlign,
46 iconSize,
47 showContent,
48 iconColor,
49 hoverIconColor,
50 url,
51 ariaLabel,
52 target,
53 rel,
54 } = attributes;
55
56 const hasChildBlocks = useSelect(
57 (select) => {
58 const blockEditor = select('core/block-editor');
59
60 return blockEditor
61 ? blockEditor.getBlockOrder(clientId).length > 0
62 : false;
63 },
64 [clientId]
65 );
66
67 className = classnames('ghostkit-icon-box', className);
68 className = applyFilters('ghostkit.editor.className', className, props);
69
70 const classNameIcon = classnames(
71 'ghostkit-icon-box-icon',
72 `ghostkit-icon-box-icon-align-${iconPosition || 'left'}`,
73 iconPosition === 'top'
74 ? `ghostkit-icon-box-icon-top-align-${iconAlign || 'center'}`
75 : ''
76 );
77
78 const blockProps = useBlockProps({ className });
79 const innerBlockProps = useInnerBlocksProps(
80 { className: 'ghostkit-icon-box-content' },
81 {
82 renderAppender: hasChildBlocks
83 ? undefined
84 : InnerBlocks.ButtonBlockAppender,
85 templateLock: false,
86 }
87 );
88 const iconPassionLabel = __('Icon Position', 'ghostkit');
89
90 return (
91 <>
92 <InspectorControls>
93 <PanelBody>
94 <IconPicker
95 label={__('Icon', 'ghostkit')}
96 value={icon}
97 onChange={(value) => setAttributes({ icon: value })}
98 insideInspector
99 />
100 {icon ? (
101 <>
102 <RangeControl
103 label={__('Icon Size', 'ghostkit')}
104 value={iconSize}
105 onChange={(value) =>
106 setAttributes({ iconSize: value })
107 }
108 min={20}
109 beforeIcon="editor-textcolor"
110 afterIcon="editor-textcolor"
111 allowCustomMin
112 allowCustomMax
113 />
114 <BaseControl
115 id={iconPassionLabel}
116 label={iconPassionLabel}
117 >
118 <div>
119 <Toolbar label={iconPassionLabel}>
120 <ToolbarButton
121 icon="align-center"
122 title={__('Top', 'ghostkit')}
123 onClick={() =>
124 setAttributes({
125 iconPosition: 'top',
126 })
127 }
128 isActive={iconPosition === 'top'}
129 />
130 <ToolbarButton
131 icon="align-left"
132 title={__('Left', 'ghostkit')}
133 onClick={() =>
134 setAttributes({
135 iconPosition: 'left',
136 })
137 }
138 isActive={iconPosition === 'left'}
139 />
140 <ToolbarButton
141 icon="align-right"
142 title={__('Right', 'ghostkit')}
143 onClick={() =>
144 setAttributes({
145 iconPosition: 'right',
146 })
147 }
148 isActive={iconPosition === 'right'}
149 />
150 </Toolbar>
151 </div>
152 </BaseControl>
153 {iconPosition === 'top' ? (
154 <ToggleGroup
155 label={__('Icon Alignment', 'ghostkit')}
156 value={iconAlign || 'center'}
157 options={[
158 {
159 icon: getIcon(
160 'icon-horizontal-start'
161 ),
162 label: __('Start', 'ghostkit'),
163 value: 'left',
164 },
165 {
166 icon: getIcon(
167 'icon-horizontal-center'
168 ),
169 label: __('Center', 'ghostkit'),
170 value: 'center',
171 },
172 {
173 icon: getIcon(
174 'icon-horizontal-end'
175 ),
176 label: __('End', 'ghostkit'),
177 value: 'right',
178 },
179 ]}
180 onChange={(value) => {
181 setAttributes({ iconAlign: value });
182 }}
183 />
184 ) : null}
185 </>
186 ) : null}
187 </PanelBody>
188 {!showContent || icon ? (
189 <PanelBody>
190 <ToggleControl
191 label={__('Show Content', 'ghostkit')}
192 checked={!!showContent}
193 onChange={(val) =>
194 setAttributes({ showContent: val })
195 }
196 />
197 </PanelBody>
198 ) : null}
199 <PanelBody
200 title={
201 <>
202 {__('Colors', 'ghostkit')}
203 <ColorIndicator colorValue={iconColor} />
204 </>
205 }
206 initialOpen={false}
207 >
208 <TabPanel
209 className="ghostkit-control-tabs ghostkit-control-tabs-wide"
210 tabs={[
211 {
212 name: 'normal',
213 title: __('Normal', 'ghostkit'),
214 className: 'ghostkit-control-tabs-tab',
215 },
216 {
217 name: 'hover',
218 title: __('Hover', 'ghostkit'),
219 className: 'ghostkit-control-tabs-tab',
220 },
221 ]}
222 >
223 {(tabData) => {
224 const isHover = tabData.name === 'hover';
225 return (
226 <ApplyFilters
227 name="ghostkit.editor.controls"
228 attribute={
229 isHover ? 'hoverIconColor' : 'iconColor'
230 }
231 props={props}
232 >
233 <ColorPicker
234 label={__('Icon', 'ghostkit')}
235 value={
236 isHover ? hoverIconColor : iconColor
237 }
238 onChange={(val) =>
239 setAttributes(
240 isHover
241 ? { hoverIconColor: val }
242 : { iconColor: val }
243 )
244 }
245 alpha
246 gradient
247 />
248 </ApplyFilters>
249 );
250 }}
251 </TabPanel>
252 </PanelBody>
253 </InspectorControls>
254 <URLPicker
255 url={url}
256 rel={rel}
257 ariaLabel={ariaLabel}
258 target={target}
259 onChange={(data) => {
260 setAttributes(data);
261 }}
262 isSelected={isSelected}
263 toolbarSettings
264 inspectorSettings
265 />
266 {icon ? (
267 <BlockControls>
268 <ToolbarGroup>
269 <ToolbarButton
270 icon="align-center"
271 title={__('Top', 'ghostkit')}
272 onClick={() =>
273 setAttributes({ iconPosition: 'top' })
274 }
275 isActive={iconPosition === 'top'}
276 />
277 <ToolbarButton
278 icon="align-left"
279 title={__('Left', 'ghostkit')}
280 onClick={() =>
281 setAttributes({ iconPosition: 'left' })
282 }
283 isActive={iconPosition === 'left'}
284 />
285 <ToolbarButton
286 icon="align-right"
287 title={__('Right', 'ghostkit')}
288 onClick={() =>
289 setAttributes({ iconPosition: 'right' })
290 }
291 isActive={iconPosition === 'right'}
292 />
293 </ToolbarGroup>
294 </BlockControls>
295 ) : null}
296 <div {...blockProps}>
297 {icon ? (
298 <div className={classNameIcon}>
299 <IconPicker.Dropdown
300 onChange={(value) => setAttributes({ icon: value })}
301 value={icon}
302 renderToggle={({ onToggle }) => (
303 <IconPicker.Preview
304 onClick={onToggle}
305 name={icon}
306 />
307 )}
308 />
309 </div>
310 ) : null}
311 {showContent ? <div {...innerBlockProps} /> : null}
312 </div>
313 </>
314 );
315 }
316