PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.6
JetFormBuilder — Dynamic Blocks Form Builder v3.1.6
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / editor / blocks / range-field / edit.js
jetformbuilder / assets / src / editor / blocks / range-field Last commit date
edit.js 2 years ago index.js 2 years ago preview.js 2 years ago
edit.js
191 lines
1 import preview from './preview';
2
3 const {
4 BlockLabel,
5 BlockDescription,
6 BlockAdvancedValue,
7 BlockName,
8 AdvancedFields,
9 FieldWrapper,
10 ValidationToggleGroup,
11 ValidationBlockMessage,
12 AdvancedInspectorControl,
13 AttributeHelp,
14 } = JetFBComponents;
15 const {
16 useIsAdvancedValidation,
17 useUniqueNameOnDuplicate,
18 } = JetFBHooks;
19 const {
20 __,
21 } = wp.i18n;
22 const {
23 InspectorControls,
24 useBlockProps,
25 } = wp.blockEditor;
26 const {
27 TextControl,
28 PanelBody,
29 __experimentalNumberControl,
30 __experimentalInputControl,
31 } = wp.components;
32 const {
33 useState,
34 } = wp.element;
35
36 let { NumberControl, InputControl } = wp.components;
37
38 if ( typeof NumberControl === 'undefined' ) {
39 NumberControl = __experimentalNumberControl;
40 }
41
42 if ( typeof InputControl === 'undefined' ) {
43 InputControl = __experimentalInputControl;
44 }
45
46 export default function RangeEdit( props ) {
47
48 const blockProps = useBlockProps();
49 const isAdvancedValidation = useIsAdvancedValidation();
50
51 useUniqueNameOnDuplicate();
52
53 const [ rangeValue, setRangeValue ] = useState( 50 );
54
55 const {
56 attributes,
57 setAttributes,
58 editProps: { uniqKey, attrHelp },
59 } = props;
60
61 if ( attributes.isPreview ) {
62 return <div style={ {
63 width: '100%',
64 display: 'flex',
65 justifyContent: 'center',
66 } }>
67 { preview }
68 </div>;
69 }
70
71 return [
72 props.isSelected && (
73 <InspectorControls
74 key={ uniqKey( 'InspectorControls' ) }
75 >
76 <PanelBody title={ __( 'General', 'jet-form-builder' ) }>
77 <BlockLabel/>
78 <BlockName/>
79 <BlockDescription/>
80 </PanelBody>
81 <PanelBody title={ __( 'Value', 'jet-form-builder' ) }>
82 <BlockAdvancedValue/>
83 </PanelBody>
84 <PanelBody
85 title={ __( 'Field', 'jet-form-builder' ) }
86 key={ uniqKey( 'PanelBody' ) }
87 >
88 <AdvancedInspectorControl
89 value={ attributes.min }
90 label={ __( 'Min Value', 'jet-form-builder' ) }
91 onChangePreset={ min => setAttributes( { min } ) }
92 >
93 { ( { instanceId } ) => <TextControl
94 id={ instanceId }
95 className="jet-fb m-unset"
96 value={ attributes.min }
97 onChange={ min => setAttributes( { min } ) }
98 /> }
99 </AdvancedInspectorControl>
100 <AttributeHelp name="min"/>
101 <AdvancedInspectorControl
102 value={ attributes.max }
103 label={ __( 'Max Value', 'jet-form-builder' ) }
104 onChangePreset={ max => setAttributes( { max } ) }
105 >
106 { ( { instanceId } ) => <TextControl
107 id={ instanceId }
108 className="jet-fb m-unset"
109 value={ attributes.max }
110 onChange={ max => setAttributes( { max } ) }
111 /> }
112 </AdvancedInspectorControl>
113 <AttributeHelp name="max"/>
114 <AdvancedInspectorControl
115 value={ attributes.step }
116 label={ __( 'Step', 'jet-form-builder' ) }
117 onChangePreset={ step => setAttributes( { step } ) }
118 >
119 { ( { instanceId } ) => <TextControl
120 id={ instanceId }
121 className="jet-fb m-unset"
122 value={ attributes.step }
123 onChange={ step => setAttributes( { step } ) }
124 /> }
125 </AdvancedInspectorControl>
126 <AttributeHelp name="step"/>
127 <TextControl
128 key="prefix"
129 label={ __( 'Value prefix' ) }
130 value={ attributes.prefix }
131 help={ attrHelp( 'prefix_suffix' ) }
132 onChange={ ( newValue ) => {
133 setAttributes( { prefix: newValue } );
134 } }
135 />
136 <TextControl
137 key="suffix"
138 label={ __( 'Value suffix' ) }
139 value={ attributes.suffix }
140 help={ attrHelp( 'prefix_suffix' ) }
141 onChange={ ( newValue ) => {
142 setAttributes( { suffix: newValue } );
143 } }
144 />
145
146 </PanelBody>
147 <PanelBody
148 title={ __( 'Validation', 'jet-form-builder' ) }
149 >
150 <ValidationToggleGroup/>
151 { isAdvancedValidation && <>
152 <ValidationBlockMessage name="empty"/>
153 <ValidationBlockMessage name="number_max"/>
154 <ValidationBlockMessage name="number_min"/>
155 </> }
156 </PanelBody>
157 <AdvancedFields
158 key={ uniqKey( 'AdvancedFields' ) }
159 { ...props }
160 />
161 </InspectorControls>
162 ),
163 <div { ...blockProps } key={ uniqKey( 'viewBlock' ) }>
164 <FieldWrapper
165 key={ uniqKey( 'FieldWrapper' ) }
166 wrapClasses={ [
167 'range-wrap',
168 ] }
169 { ...props }
170 >
171 <div className="range-flex-wrap">
172 <InputControl
173 key={ uniqKey( 'placeholder_block' ) }
174 type={ 'range' }
175 min={ attributes.min || 0 }
176 max={ attributes.max || 100 }
177 step={ attributes.step || 1 }
178 onChange={ setRangeValue }
179 />
180 <div className={ 'jet-form-builder__field-value' }>
181 <span
182 className={ 'jet-form-builder__field-value-prefix' }>{ attributes.prefix }</span>
183 <span>{ rangeValue }</span>
184 <span
185 className={ 'jet-form-builder__field-value-suffix' }>{ attributes.suffix }</span>
186 </div>
187 </div>
188 </FieldWrapper>
189 </div>,
190 ];
191 }