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

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

105 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 __nextHasNoMarginBottom
64 />
65 </PanelBody>
66 </InspectorControls>
67 <div {...blockProps}>
68 <FieldLabel {...props} />
69
70 {isSelected ? (
71 <FieldOptions
72 options={options}
73 onChange={(val) => setAttributes({ options: val })}
74 multiple
75 />
76 ) : (
77 <div className="ghostkit-form-field-checkbox-items">
78 {options.map((data, i) => {
79 const itemName = `${slug}-item-${i}`;
80
81 return (
82 <label
83 key={itemName}
84 htmlFor={itemName}
85 className="ghostkit-form-field-checkbox-item"
86 >
87 <input
88 type="checkbox"
89 checked={data.selected}
90 onChange={() => {}}
91 {...getFieldAttributes(attributes)}
92 />
93 {data.label}
94 </label>
95 );
96 })}
97 </div>
98 )}
99
100 <FieldDescription {...props} />
101 </div>
102 </>
103 );
104 }
105