-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimePickerControl.js
More file actions
executable file
·53 lines (48 loc) · 1.64 KB
/
DateTimePickerControl.js
File metadata and controls
executable file
·53 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// WordPress dependencies.
const { useContext } = wp.element;
const { dateI18n, __experimentalGetSettings } = wp.date;
const { PanelRow, Dropdown, BaseControl, Button, DateTimePicker, DatePicker, TimePicker } = wp.components;
const { withInstanceId } = wp.compose;
const DateTimePickerControl = ({ label, time = true, date = true, value, ...props }) => {
const id = 'inspector-date-time-picker-control-' + props.instanceId;
const settings = __experimentalGetSettings();
let Picker = DateTimePicker;
let format = `${settings.formats.date} ${settings.formats.time}`;
if (date && !time) {
Picker = DatePicker;
format = settings.formats.date;
}
if (time && !date) {
Picker = TimePicker;
format = settings.formats.time;
}
return (
<BaseControl>
<PanelRow className="edit-post-post-schedule">
<label htmlFor={ id } className="components-base-control__label">{ label }</label>
<Dropdown
position="bottom left"
contentClassName="edit-post-post-schedule__dialog"
renderToggle={ ( { onToggle, isOpen } ) => (
<>
<Button
id={ id }
className="edit-post-post-schedule__toggle"
onClick={ onToggle }
aria-expanded={ isOpen }
isLink
>
{ dateI18n(format, value || new Date())}
</Button>
</>
) }
renderContent={ () => <Picker
currentDate={ value || new Date() }
{ ...props }
/> }
/>
</PanelRow>
</BaseControl>
);
};
export default withInstanceId(DateTimePickerControl);