PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.2
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 / components / date-time-picker / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.2, at gutenberg/components/date-time-picker/index.js

63 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 BaseControl,
3 Button,
4 DateTimePicker as WPDateTimePicker,
5 Popover,
6 } from '@wordpress/components';
7 import { dateI18n, getSettings } from '@wordpress/date';
8 import { useState } from '@wordpress/element';
9 import { __ } from '@wordpress/i18n';
10
11 const { luxon } = window;
12
13 /**
14 * Component Class
15 *
16 * @param props
17 */
18 export default function DateTimePicker(props) {
19 const [isPickerOpen, setIsPickerOpen] = useState(false);
20
21 const { value, onChange, label, is12Hour = false } = props;
22
23 const settings = getSettings();
24 const resolvedFormat = settings.formats.datetime || 'F j, Y g:i a';
25
26 return (
27 <BaseControl
28 id={label}
29 label={label}
30 className="ghostkit-components-date-time-picker"
31 >
32 <div>
33 <Button isLink onClick={() => setIsPickerOpen(!isPickerOpen)}>
34 {value
35 ? `${dateI18n(resolvedFormat, value)} ${
36 settings.timezone.abbr ||
37 settings.timezone.string ||
38 `UTC${settings.timezone.offset}`
39 }`
40 : __('Select Date', 'ghostkit')}
41 </Button>
42 {isPickerOpen ? (
43 <Popover
44 className="ghostkit-components-date-time-picker-popover"
45 onClose={() => setIsPickerOpen(false)}
46 >
47 <WPDateTimePicker
48 label={label}
49 currentDate={
50 luxon.DateTime.fromISO(value).isValid
51 ? value
52 : ''
53 }
54 onChange={onChange}
55 is12Hour={is12Hour}
56 />
57 </Popover>
58 ) : null}
59 </div>
60 </BaseControl>
61 );
62 }
63