@patternfly/react-core 4.174.1 → 4.174.2
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 +8 -0
- package/dist/umd/react-core.css +97 -3
- package/dist/umd/react-core.js +2 -0
- package/dist/umd/react-core.min.css +97 -3
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +6 -6
- package/src/demos/DateTimePicker.md +103 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.174.
|
|
3
|
+
"version": "4.174.2",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.25.
|
|
38
|
-
"@patternfly/react-styles": "^4.24.
|
|
39
|
-
"@patternfly/react-tokens": "^4.26.
|
|
37
|
+
"@patternfly/react-icons": "^4.25.2",
|
|
38
|
+
"@patternfly/react-styles": "^4.24.2",
|
|
39
|
+
"@patternfly/react-tokens": "^4.26.2",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "10.2.2",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@patternfly/patternfly": "4.
|
|
46
|
+
"@patternfly/patternfly": "4.159.0",
|
|
47
47
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
48
48
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
49
49
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "e3eb3038c1f23818774f99280f2a4485ee4a2be2"
|
|
64
64
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Date and time picker
|
|
3
|
+
section: demos
|
|
4
|
+
beta: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
import OutlinedCalendarAltIcon from '@patternfly/react-icons/dist/esm/icons/outlined-calendar-alt-icon';
|
|
8
|
+
import OutlinedClockIcon from '@patternfly/react-icons/dist/esm/icons/outlined-clock-icon';
|
|
9
|
+
|
|
10
|
+
## Demos
|
|
11
|
+
|
|
12
|
+
In this demo, learn how to use a [CalendarMonth](/components/calendar-month) component and a [Dropdown](/components/dropdown) component to compose a simple DateTimePicker. The input is read only, meaning that the following example does not cover pasting a copied date and time. Also, you can pick the time only from the predefined options and cannot change it in the input.
|
|
13
|
+
|
|
14
|
+
### Date and time picker
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { Dropdown, DropdownToggle, DropdownItem, CalendarMonth, InputGroup, TextInput, Button, Popover } from '@patternfly/react-core';
|
|
19
|
+
import OutlinedCalendarAltIcon from '@patternfly/react-icons/dist/esm/icons/outlined-calendar-alt-icon';
|
|
20
|
+
import OutlinedClockIcon from '@patternfly/react-icons/dist/esm/icons/outlined-clock-icon';
|
|
21
|
+
|
|
22
|
+
DateTimePicker = () => {
|
|
23
|
+
const [isCalendarOpen, setIsCalendarOpen] = React.useState(false);
|
|
24
|
+
const [isTimeOpen, setIsTimeOpen] = React.useState(false);
|
|
25
|
+
const [valueDate, setValueDate] = React.useState("YYYY-MM-DD");
|
|
26
|
+
const [valueTime, setValueTime] = React.useState("HH:MM");
|
|
27
|
+
const times = Array.from(new Array(10), (_, i) => i + 8);
|
|
28
|
+
const defaultTime = "0:00";
|
|
29
|
+
const dateFormat = date => date.toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g,'-');
|
|
30
|
+
|
|
31
|
+
const onToggleCalendar = () => {
|
|
32
|
+
setIsCalendarOpen(!isCalendarOpen);
|
|
33
|
+
setIsTimeOpen(false);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const onToggleTime = ev => {
|
|
37
|
+
setIsTimeOpen(!isTimeOpen);
|
|
38
|
+
setIsCalendarOpen(false);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const onSelectCalendar = newValueDate => {
|
|
42
|
+
const newValue = dateFormat(newValueDate);
|
|
43
|
+
setValueDate(newValue);
|
|
44
|
+
setIsCalendarOpen(!isCalendarOpen);
|
|
45
|
+
// setting default time when it is not picked
|
|
46
|
+
if (valueTime === "HH:MM") {
|
|
47
|
+
setValueTime(defaultTime);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const onSelectTime = ev => {
|
|
52
|
+
setValueTime(ev.target.value);
|
|
53
|
+
setIsTimeOpen(!isTimeOpen);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const timeOptions = times.map(time => (
|
|
57
|
+
<DropdownItem key={time} component="button" value={`${time}:00`}>
|
|
58
|
+
{`${time}:00`}
|
|
59
|
+
</DropdownItem>
|
|
60
|
+
))
|
|
61
|
+
const calendar = (
|
|
62
|
+
<CalendarMonth
|
|
63
|
+
date={valueDate}
|
|
64
|
+
onChange={onSelectCalendar}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
const time = (
|
|
68
|
+
<Dropdown
|
|
69
|
+
onSelect={onSelectTime}
|
|
70
|
+
toggle={
|
|
71
|
+
<DropdownToggle toggleIndicator={null} onToggle={onToggleTime} style={{ padding: '6px 16px' }}>
|
|
72
|
+
<OutlinedClockIcon />
|
|
73
|
+
</DropdownToggle>
|
|
74
|
+
}
|
|
75
|
+
isOpen={isTimeOpen}
|
|
76
|
+
dropdownItems={timeOptions}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
const calendarButton = (
|
|
80
|
+
<Button variant="control" onClick={onToggleCalendar}>
|
|
81
|
+
<OutlinedCalendarAltIcon />
|
|
82
|
+
</Button>
|
|
83
|
+
);
|
|
84
|
+
return (
|
|
85
|
+
<div style={{ width: '300px' }}>
|
|
86
|
+
<Popover
|
|
87
|
+
position="bottom"
|
|
88
|
+
bodyContent={calendar}
|
|
89
|
+
showClose={false}
|
|
90
|
+
isVisible={isCalendarOpen}
|
|
91
|
+
hasNoPadding
|
|
92
|
+
hasAutoWidth
|
|
93
|
+
>
|
|
94
|
+
<InputGroup>
|
|
95
|
+
<TextInput type="'datetime-local" id="date-time" value={valueDate + ' ' + valueTime} isReadOnly/>
|
|
96
|
+
{calendarButton}
|
|
97
|
+
{time}
|
|
98
|
+
</InputGroup>
|
|
99
|
+
</Popover>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
```
|