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 / date-field / edit.js
jetformbuilder / assets / src / editor / blocks / date-field Last commit date
edit.js 2 years ago index.js 2 years ago preview.js 2 years ago
edit.js
181 lines
1 import preview from './preview';
2
3 const {
4 ToolBarFields,
5 BlockLabel,
6 BlockName,
7 BlockDescription,
8 BlockAdvancedValue,
9 AdvancedFields,
10 FieldWrapper,
11 FieldSettingsWrapper,
12 AdvancedInspectorControl,
13 ClientSideMacros,
14 ValidationToggleGroup,
15 ValidationBlockMessage,
16 AttributeHelp,
17 } = JetFBComponents;
18 const {
19 useInsertMacro,
20 useIsAdvancedValidation,
21 useUniqueNameOnDuplicate,
22 } = JetFBHooks;
23 const {
24 __,
25 } = wp.i18n;
26 const {
27 InspectorControls,
28 useBlockProps,
29 } = wp.blockEditor;
30 const {
31 TextControl,
32 ToggleControl,
33 PanelBody,
34 __experimentalInputControl,
35 ExternalLink,
36 } = wp.components;
37
38 let { InputControl } = wp.components;
39
40 if ( typeof InputControl === 'undefined' ) {
41 InputControl = __experimentalInputControl;
42 }
43
44 export default function DateEdit( props ) {
45 const blockProps = useBlockProps();
46
47 const [ minInput, updateMin ] = useInsertMacro( 'min' );
48 const [ maxInput, updateMax ] = useInsertMacro( 'max' );
49
50 const {
51 attributes,
52 isSelected,
53 setAttributes,
54 editProps: { uniqKey, blockName, attrHelp },
55 } = props;
56
57 const isAdvancedValidation = useIsAdvancedValidation();
58 useUniqueNameOnDuplicate();
59
60 if ( attributes.isPreview ) {
61 return <div style={ {
62 width: '100%',
63 display: 'flex',
64 justifyContent: 'center',
65 } }>
66 { preview }
67 </div>;
68 }
69
70 const help = <>
71 { __(
72 'Plain date should be in yyyy-mm-dd format.',
73 'jet-form-builder',
74 ) }
75 &nbsp;
76 { __( 'Or you can use', 'jet-form-builder' ) }
77 &nbsp;
78 <ExternalLink
79 href="https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate"
80 >
81 { __( 'macros', 'jet-form-builder' ) }
82 </ExternalLink>.
83 </>;
84
85 return [
86 <ToolBarFields
87 key={ uniqKey( 'JetForm-toolbar' ) }
88 { ...props }
89 />,
90 isSelected && <InspectorControls
91 key={ uniqKey( 'InspectorControls' ) }
92 >
93 <PanelBody title={ __( 'General', 'jet-form-builder' ) }>
94 <BlockLabel/>
95 <BlockName/>
96 <BlockDescription/>
97 </PanelBody>
98 <PanelBody title={ __( 'Value', 'jet-form-builder' ) }>
99 <BlockAdvancedValue
100 help={ help }
101 style={ { marginBottom: '1em' } }
102 />
103 <ClientSideMacros>
104 <AdvancedInspectorControl
105 value={ attributes.min }
106 label={ __( 'Starting from date', 'jet-form-builder' ) }
107 onChangePreset={ min => setAttributes( { min } ) }
108 onChangeMacros={ updateMin }
109 >
110 { ( { instanceId } ) => <>
111 <TextControl
112 id={ instanceId }
113 ref={ minInput }
114 className="jet-fb m-unset"
115 value={ attributes.min }
116 onChange={ min => setAttributes( { min } ) }
117 />
118 <AttributeHelp>{ help }</AttributeHelp>
119 </> }
120 </AdvancedInspectorControl>
121 <AdvancedInspectorControl
122 value={ attributes.max }
123 label={ __( 'Limit dates to', 'jet-form-builder' ) }
124 onChangePreset={ max => setAttributes( { max } ) }
125 onChangeMacros={ updateMax }
126 >
127 { ( { instanceId } ) => <>
128 <TextControl
129 id={ instanceId }
130 ref={ maxInput }
131 className="jet-fb m-unset"
132 value={ attributes.max }
133 onChange={ max => setAttributes( { max } ) }
134 />
135 <AttributeHelp>{ help }</AttributeHelp>
136 </> }
137 </AdvancedInspectorControl>
138 </ClientSideMacros>
139 </PanelBody>
140 <FieldSettingsWrapper { ...props }>
141 <ToggleControl
142 key="is_timestamp"
143 label={ __( 'Is Timestamp' ) }
144 checked={ attributes.is_timestamp }
145 help={ attrHelp( 'is_timestamp' ) }
146 onChange={ ( newValue ) => {
147 setAttributes( { is_timestamp: Boolean( newValue ) } );
148 } }
149 />
150 </FieldSettingsWrapper>
151 <PanelBody
152 title={ __( 'Validation', 'jet-form-builder' ) }
153 >
154 <ValidationToggleGroup/>
155 { isAdvancedValidation && <>
156 { Boolean( attributes.min ) && <>
157 <ValidationBlockMessage name="date_min"/>
158 </> }
159 { Boolean( attributes.max ) && <>
160 <ValidationBlockMessage name="date_max"/>
161 </> }
162 <ValidationBlockMessage name="empty"/>
163 </> }
164 </PanelBody>
165 <AdvancedFields/>
166 </InspectorControls>,
167 <div { ...blockProps } key={ uniqKey( 'viewBlock' ) }>
168 <FieldWrapper
169 key={ uniqKey( 'FieldWrapper' ) }
170 { ...props }
171 >
172 <TextControl
173 onChange={ () => {
174 } }
175 key={ `place_holder_block_${ blockName }` }
176 placeholder={ 'Input type="date"' }
177 />
178 </FieldWrapper>
179 </div>,
180 ];
181 }