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 / form / fields / checkbox / edit.js

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

104 lines 2.3 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 { InspectorControls, useBlockProps } from '@wordpress/block-editor';
4 import { PanelBody, ToggleControl } from '@wordpress/components';
5 import { applyFilters } from '@wordpress/hooks';
6 import { __ } from '@wordpress/i18n';
7
8 import {
9 FieldDefaultSettings,
10 getFieldAttributes,
11 } from '../../field-attributes';
12 import FieldDescription from '../../field-description';
13 import FieldLabel from '../../field-label';
14 import FieldOptions from '../../field-options';
15
16 /**
17 * Block Edit component.
18 *
19 * @param props
20 */
21 export default function BlockEdit(props) {
22 const { attributes, setAttributes, isSelected } = props;
23
24 const { slug, inline } = attributes;
25
26 let { options } = attributes;
27
28 let { className = '' } = props;
29
30 className = classnames(
31 'ghostkit-form-field ghostkit-form-field-checkbox',
32 inline && 'ghostkit-form-field-checkbox-inline',
33 className
34 );
35
36 className = applyFilters('ghostkit.editor.className', className, props);
37
38 if (!options || !options.length) {
39 options = [
40 {
41 label: '',
42 value: '',
43 selected: false,
44 },
45 ];
46 }
47
48 const blockProps = useBlockProps({ className });
49
50 return (
51 <>
52 <InspectorControls>
53 <PanelBody>
54 <FieldDefaultSettings
55 {...props}
56 defaultCustom={' '}
57 placeholderCustom={' '}
58 />
59 <ToggleControl
60 label={__('Inline', 'ghostkit')}
61 checked={inline}
62 onChange={() => setAttributes({ inline: !inline })}
63 />
64 </PanelBody>
65 </InspectorControls>
66 <div {...blockProps}>
67 <FieldLabel {...props} />
68
69 {isSelected ? (
70 <FieldOptions
71 options={options}
72 onChange={(val) => setAttributes({ options: val })}
73 multiple
74 />
75 ) : (
76 <div className="ghostkit-form-field-checkbox-items">
77 {options.map((data, i) => {
78 const itemName = `${slug}-item-${i}`;
79
80 return (
81 <label
82 key={itemName}
83 htmlFor={itemName}
84 className="ghostkit-form-field-checkbox-item"
85 >
86 <input
87 type="checkbox"
88 checked={data.selected}
89 onChange={() => {}}
90 {...getFieldAttributes(attributes)}
91 />
92 {data.label}
93 </label>
94 );
95 })}
96 </div>
97 )}
98
99 <FieldDescription {...props} />
100 </div>
101 </>
102 );
103 }
104