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 / radio / edit.js

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

110 lines 2.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 { 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 Class.
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-radio',
32 inline && 'ghostkit-form-field-radio-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 let selectVal = '';
49
50 options.forEach((data) => {
51 if (!selectVal && data.selected) {
52 selectVal = data.value;
53 }
54 });
55
56 const blockProps = useBlockProps({ className });
57
58 return (
59 <>
60 <InspectorControls>
61 <PanelBody>
62 <FieldDefaultSettings
63 {...props}
64 defaultCustom={' '}
65 placeholderCustom={' '}
66 />
67 <ToggleControl
68 label={__('Inline', 'ghostkit')}
69 checked={inline}
70 onChange={() => setAttributes({ inline: !inline })}
71 />
72 </PanelBody>
73 </InspectorControls>
74 <div {...blockProps}>
75 <FieldLabel {...props} />
76
77 {isSelected ? (
78 <FieldOptions
79 options={options}
80 onChange={(val) => setAttributes({ options: val })}
81 />
82 ) : (
83 <div className="ghostkit-form-field-radio-items">
84 {options.map((data, i) => {
85 const fieldName = `${slug}-item-${i}`;
86 return (
87 <label
88 key={fieldName}
89 htmlFor={fieldName}
90 className="ghostkit-form-field-radio-item"
91 >
92 <input
93 type="radio"
94 checked={selectVal === data.value}
95 onChange={() => {}}
96 {...getFieldAttributes(attributes)}
97 />
98 {data.label}
99 </label>
100 );
101 })}
102 </div>
103 )}
104
105 <FieldDescription {...props} />
106 </div>
107 </>
108 );
109 }
110