@patternfly/react-core 4.206.6 → 4.208.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/esm/components/CodeBlock/CodeBlockCode.d.ts +4 -0
- package/dist/esm/components/CodeBlock/CodeBlockCode.d.ts.map +1 -1
- package/dist/esm/components/CodeBlock/CodeBlockCode.js +3 -3
- package/dist/esm/components/CodeBlock/CodeBlockCode.js.map +1 -1
- package/dist/esm/components/Divider/Divider.d.ts +10 -1
- package/dist/esm/components/Divider/Divider.d.ts.map +1 -1
- package/dist/esm/components/Divider/Divider.js +2 -2
- package/dist/esm/components/Divider/Divider.js.map +1 -1
- package/dist/js/components/CodeBlock/CodeBlockCode.d.ts +4 -0
- package/dist/js/components/CodeBlock/CodeBlockCode.d.ts.map +1 -1
- package/dist/js/components/CodeBlock/CodeBlockCode.js +3 -3
- package/dist/js/components/CodeBlock/CodeBlockCode.js.map +1 -1
- package/dist/js/components/Divider/Divider.d.ts +10 -1
- package/dist/js/components/Divider/Divider.d.ts.map +1 -1
- package/dist/js/components/Divider/Divider.js +2 -2
- package/dist/js/components/Divider/Divider.js.map +1 -1
- package/dist/umd/react-core.css +62 -54
- package/dist/umd/react-core.js +5 -5
- package/dist/umd/react-core.min.css +8 -0
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +6 -6
- package/src/components/CodeBlock/CodeBlockCode.tsx +8 -2
- package/src/components/Divider/Divider.tsx +12 -1
- package/src/components/Divider/__tests__/Divider.test.tsx +5 -1
- package/src/components/Divider/examples/Divider.md +6 -0
- package/src/components/Divider/examples/DividerOrientationVariousBreakpoints.tsx +19 -0
- package/src/components/Divider/examples/DividerVerticalFlex.tsx +5 -1
- package/src/components/Divider/examples/DividerVerticalFlexInsetMedium.tsx +6 -1
- package/src/components/Divider/examples/DividerVerticalFlexInsetVariousBreakpoints.tsx +4 -2
- package/src/components/Page/examples/Page.md +17 -7
- package/src/demos/CardDemos.md +108 -21
- package/src/demos/DateTimePicker.md +1 -103
- package/src/demos/examples/DateTimePicker/DateTimePicker.tsx +106 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Dropdown,
|
|
4
|
+
DropdownToggle,
|
|
5
|
+
DropdownItem,
|
|
6
|
+
CalendarMonth,
|
|
7
|
+
InputGroup,
|
|
8
|
+
TextInput,
|
|
9
|
+
Button,
|
|
10
|
+
Popover
|
|
11
|
+
} from '@patternfly/react-core';
|
|
12
|
+
import OutlinedCalendarAltIcon from '@patternfly/react-icons/dist/esm/icons/outlined-calendar-alt-icon';
|
|
13
|
+
import OutlinedClockIcon from '@patternfly/react-icons/dist/esm/icons/outlined-clock-icon';
|
|
14
|
+
|
|
15
|
+
export const DateTimePicker: React.FunctionComponent = () => {
|
|
16
|
+
const [isCalendarOpen, setIsCalendarOpen] = React.useState(false);
|
|
17
|
+
const [isTimeOpen, setIsTimeOpen] = React.useState(false);
|
|
18
|
+
const [valueDate, setValueDate] = React.useState('MM-DD-YYYY');
|
|
19
|
+
const [valueTime, setValueTime] = React.useState('HH:MM');
|
|
20
|
+
const times = Array.from(new Array(10), (_, i) => i + 8);
|
|
21
|
+
const defaultTime = '0:00';
|
|
22
|
+
const dateFormat = (date: Date) =>
|
|
23
|
+
date.toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-');
|
|
24
|
+
|
|
25
|
+
const onToggleCalendar = () => {
|
|
26
|
+
setIsCalendarOpen(!isCalendarOpen);
|
|
27
|
+
setIsTimeOpen(false);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const onToggleTime = (_value: boolean, _event: any) => {
|
|
31
|
+
setIsTimeOpen(!isTimeOpen);
|
|
32
|
+
setIsCalendarOpen(false);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const onSelectCalendar = (newValueDate: Date) => {
|
|
36
|
+
const newValue = dateFormat(newValueDate);
|
|
37
|
+
setValueDate(newValue);
|
|
38
|
+
setIsCalendarOpen(!isCalendarOpen);
|
|
39
|
+
// setting default time when it is not picked
|
|
40
|
+
if (valueTime === 'HH:MM') {
|
|
41
|
+
setValueTime(defaultTime);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const onSelectTime = (ev: React.SyntheticEvent<HTMLDivElement>) => {
|
|
46
|
+
setValueTime(ev.currentTarget.textContent);
|
|
47
|
+
setIsTimeOpen(!isTimeOpen);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const timeOptions = times.map(time => (
|
|
51
|
+
<DropdownItem key={time} component="button" value={`${time}:00`}>
|
|
52
|
+
{`${time}:00`}
|
|
53
|
+
</DropdownItem>
|
|
54
|
+
));
|
|
55
|
+
|
|
56
|
+
const calendar = <CalendarMonth date={new Date(valueDate)} onChange={onSelectCalendar} />;
|
|
57
|
+
|
|
58
|
+
const time = (
|
|
59
|
+
<Dropdown
|
|
60
|
+
onSelect={onSelectTime}
|
|
61
|
+
toggle={
|
|
62
|
+
<DropdownToggle
|
|
63
|
+
aria-label="Toggle the time picker menu"
|
|
64
|
+
toggleIndicator={null}
|
|
65
|
+
onToggle={onToggleTime}
|
|
66
|
+
style={{ padding: '6px 16px' }}
|
|
67
|
+
>
|
|
68
|
+
<OutlinedClockIcon />
|
|
69
|
+
</DropdownToggle>
|
|
70
|
+
}
|
|
71
|
+
isOpen={isTimeOpen}
|
|
72
|
+
dropdownItems={timeOptions}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const calendarButton = (
|
|
77
|
+
<Button variant="control" aria-label="Toggle the calendar" onClick={onToggleCalendar}>
|
|
78
|
+
<OutlinedCalendarAltIcon />
|
|
79
|
+
</Button>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div style={{ width: '300px' }}>
|
|
84
|
+
<Popover
|
|
85
|
+
position="bottom"
|
|
86
|
+
bodyContent={calendar}
|
|
87
|
+
showClose={false}
|
|
88
|
+
isVisible={isCalendarOpen}
|
|
89
|
+
hasNoPadding
|
|
90
|
+
hasAutoWidth
|
|
91
|
+
>
|
|
92
|
+
<InputGroup>
|
|
93
|
+
<TextInput
|
|
94
|
+
type="text"
|
|
95
|
+
id="date-time"
|
|
96
|
+
aria-label="date and time picker demo"
|
|
97
|
+
value={valueDate + ' ' + valueTime}
|
|
98
|
+
isReadOnly
|
|
99
|
+
/>
|
|
100
|
+
{calendarButton}
|
|
101
|
+
{time}
|
|
102
|
+
</InputGroup>
|
|
103
|
+
</Popover>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
};
|