@patternfly/react-core 4.257.0 → 4.257.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 +11 -0
- package/dist/esm/components/CalendarMonth/CalendarMonth.d.ts +0 -1
- package/dist/esm/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
- package/dist/esm/components/CalendarMonth/CalendarMonth.js +1 -1
- package/dist/esm/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.js +2 -1
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/Timestamp/Timestamp.d.ts.map +1 -1
- package/dist/esm/components/Timestamp/Timestamp.js +23 -5
- package/dist/esm/components/Timestamp/Timestamp.js.map +1 -1
- package/dist/esm/helpers/datetimeUtils.d.ts +5 -0
- package/dist/esm/helpers/datetimeUtils.d.ts.map +1 -0
- package/dist/esm/helpers/datetimeUtils.js +5 -0
- package/dist/esm/helpers/datetimeUtils.js.map +1 -0
- package/dist/esm/helpers/index.d.ts +1 -0
- package/dist/esm/helpers/index.d.ts.map +1 -1
- package/dist/esm/helpers/index.js +1 -0
- package/dist/esm/helpers/index.js.map +1 -1
- package/dist/js/components/CalendarMonth/CalendarMonth.d.ts +0 -1
- package/dist/js/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
- package/dist/js/components/CalendarMonth/CalendarMonth.js +9 -10
- package/dist/js/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/dist/js/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/js/components/DatePicker/DatePicker.js +5 -4
- package/dist/js/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/js/components/Timestamp/Timestamp.d.ts.map +1 -1
- package/dist/js/components/Timestamp/Timestamp.js +23 -5
- package/dist/js/components/Timestamp/Timestamp.js.map +1 -1
- package/dist/js/helpers/datetimeUtils.d.ts +5 -0
- package/dist/js/helpers/datetimeUtils.d.ts.map +1 -0
- package/dist/js/helpers/datetimeUtils.js +9 -0
- package/dist/js/helpers/datetimeUtils.js.map +1 -0
- package/dist/js/helpers/index.d.ts +1 -0
- package/dist/js/helpers/index.d.ts.map +1 -1
- package/dist/js/helpers/index.js +1 -0
- package/dist/js/helpers/index.js.map +1 -1
- package/dist/umd/react-core.min.css +21391 -21391
- package/dist/umd/react-core.min.js +3 -3
- package/package.json +2 -2
- package/src/components/CalendarMonth/CalendarMonth.tsx +1 -2
- package/src/components/DatePicker/DatePicker.tsx +2 -1
- package/src/components/Timestamp/Timestamp.tsx +26 -5
- package/src/components/Timestamp/__tests__/Timestamp.test.tsx +22 -5
- package/src/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap +0 -1
- package/src/helpers/datetimeUtils.ts +4 -0
- package/src/helpers/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.257.
|
|
3
|
+
"version": "4.257.1",
|
|
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",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"react": "^16.8 || ^17 || ^18",
|
|
71
71
|
"react-dom": "^16.8 || ^17 || ^18"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "9aafcbc3a7986f6fb5837f887cf1a25f01a11e8b"
|
|
74
74
|
}
|
|
@@ -8,6 +8,7 @@ import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-i
|
|
|
8
8
|
import { css } from '@patternfly/react-styles';
|
|
9
9
|
import styles from '@patternfly/react-styles/css/components/CalendarMonth/calendar-month';
|
|
10
10
|
import { getUniqueId } from '../../helpers/util';
|
|
11
|
+
import { isValidDate } from '../../helpers/datetimeUtils';
|
|
11
12
|
|
|
12
13
|
export enum Weekday {
|
|
13
14
|
Sunday = 0,
|
|
@@ -109,8 +110,6 @@ const buildCalendar = (year: number, month: number, weekStart: number, validator
|
|
|
109
110
|
const isSameDate = (d1: Date, d2: Date) =>
|
|
110
111
|
d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
111
112
|
|
|
112
|
-
export const isValidDate = (date: Date) => Boolean(date && !isNaN(date as any));
|
|
113
|
-
|
|
114
113
|
const today = new Date();
|
|
115
114
|
|
|
116
115
|
/** The main calendar month component. */
|
|
@@ -6,9 +6,10 @@ import { TextInput, TextInputProps } from '../TextInput/TextInput';
|
|
|
6
6
|
import { Popover, PopoverProps } from '../Popover/Popover';
|
|
7
7
|
import { InputGroup } from '../InputGroup/InputGroup';
|
|
8
8
|
import OutlinedCalendarAltIcon from '@patternfly/react-icons/dist/esm/icons/outlined-calendar-alt-icon';
|
|
9
|
-
import { CalendarMonth, CalendarFormat
|
|
9
|
+
import { CalendarMonth, CalendarFormat } from '../CalendarMonth';
|
|
10
10
|
import { useImperativeHandle } from 'react';
|
|
11
11
|
import { KeyTypes } from '../../helpers';
|
|
12
|
+
import { isValidDate } from '../../helpers/datetimeUtils';
|
|
12
13
|
|
|
13
14
|
/** The main date picker component. */
|
|
14
15
|
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import styles from '@patternfly/react-styles/css/components/Timestamp/timestamp';
|
|
3
3
|
import { css } from '@patternfly/react-styles';
|
|
4
4
|
import { Tooltip } from '../Tooltip';
|
|
5
|
+
import { isValidDate } from '../../helpers/datetimeUtils';
|
|
5
6
|
|
|
6
7
|
export enum TimestampFormat {
|
|
7
8
|
full = 'full',
|
|
@@ -78,7 +79,7 @@ export const Timestamp: React.FunctionComponent<TimestampProps> = ({
|
|
|
78
79
|
children,
|
|
79
80
|
className,
|
|
80
81
|
customFormat,
|
|
81
|
-
date: dateProp
|
|
82
|
+
date: dateProp,
|
|
82
83
|
dateFormat,
|
|
83
84
|
displaySuffix = '',
|
|
84
85
|
is12Hour,
|
|
@@ -87,6 +88,24 @@ export const Timestamp: React.FunctionComponent<TimestampProps> = ({
|
|
|
87
88
|
tooltip,
|
|
88
89
|
...props
|
|
89
90
|
}: TimestampProps) => {
|
|
91
|
+
const [date, setDate] = React.useState(() => {
|
|
92
|
+
const initDate = new Date(dateProp);
|
|
93
|
+
if (isValidDate(initDate)) {
|
|
94
|
+
return initDate;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return new Date();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
const dateFromProp = new Date(dateProp);
|
|
102
|
+
if (isValidDate(dateFromProp) && dateFromProp.toString() !== new Date(date).toString()) {
|
|
103
|
+
setDate(dateFromProp);
|
|
104
|
+
} else if (!dateProp) {
|
|
105
|
+
setDate(new Date());
|
|
106
|
+
}
|
|
107
|
+
}, [dateProp]);
|
|
108
|
+
|
|
90
109
|
const hasTimeFormat = timeFormat && !customFormat;
|
|
91
110
|
const formatOptions = {
|
|
92
111
|
...(dateFormat && !customFormat && { dateStyle: dateFormat }),
|
|
@@ -94,7 +113,7 @@ export const Timestamp: React.FunctionComponent<TimestampProps> = ({
|
|
|
94
113
|
...(is12Hour !== undefined && { hour12: is12Hour })
|
|
95
114
|
};
|
|
96
115
|
|
|
97
|
-
const dateAsLocaleString = new Date(
|
|
116
|
+
const dateAsLocaleString = new Date(date).toLocaleString(locale, {
|
|
98
117
|
...formatOptions,
|
|
99
118
|
...(hasTimeFormat && { timeStyle: timeFormat })
|
|
100
119
|
});
|
|
@@ -102,19 +121,21 @@ export const Timestamp: React.FunctionComponent<TimestampProps> = ({
|
|
|
102
121
|
|
|
103
122
|
const utcTimeFormat = timeFormat !== 'short' ? 'medium' : 'short';
|
|
104
123
|
const convertToUTCString = (date: Date) => new Date(date).toUTCString().slice(0, -3);
|
|
105
|
-
const utcDateString = new Date(convertToUTCString(
|
|
124
|
+
const utcDateString = new Date(convertToUTCString(date)).toLocaleString(locale, {
|
|
106
125
|
...formatOptions,
|
|
107
126
|
...(hasTimeFormat && { timeStyle: utcTimeFormat })
|
|
108
127
|
});
|
|
109
128
|
const defaultTooltipContent = `${utcDateString}${tooltip?.suffix ? ' ' + tooltip.suffix : ' UTC'}`;
|
|
110
129
|
|
|
130
|
+
const { dateTime, ...propsWithoutDateTime } = props;
|
|
131
|
+
|
|
111
132
|
const timestamp = (
|
|
112
133
|
<span
|
|
113
134
|
className={css(styles.timestamp, tooltip && styles.modifiers.helpText, className)}
|
|
114
135
|
{...(tooltip && { tabIndex: 0 })}
|
|
115
|
-
{...
|
|
136
|
+
{...propsWithoutDateTime}
|
|
116
137
|
>
|
|
117
|
-
<time className="pf-c-timestamp__text" dateTime={
|
|
138
|
+
<time className="pf-c-timestamp__text" dateTime={dateTime || new Date(date).toISOString()}>
|
|
118
139
|
{!children ? defaultDisplay : children}
|
|
119
140
|
</time>
|
|
120
141
|
</span>
|
|
@@ -36,12 +36,31 @@ test('Renders with current date by default with default formatting', () => {
|
|
|
36
36
|
expect(screen.getByText(new Date().toLocaleString())).toBeInTheDocument();
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
test('Renders with correct datetime attribute with current date by default', () => {
|
|
40
|
+
render(<Timestamp />);
|
|
41
|
+
// Because there could be a .001 ms difference in the expected and received datetime value,
|
|
42
|
+
// we want an ISO value without the ms to expect as the datetime value.
|
|
43
|
+
const isoDateWithoutMS = new Date().toISOString().split('.')[0];
|
|
44
|
+
|
|
45
|
+
expect(screen.getByText(new Date().toLocaleString())).toHaveAttribute(
|
|
46
|
+
'datetime',
|
|
47
|
+
expect.stringMatching(isoDateWithoutMS)
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
39
51
|
test('Renders passed in date with default formatting', () => {
|
|
40
52
|
render(<Timestamp date={new Date(2022, 0, 1)} />);
|
|
41
53
|
|
|
42
54
|
expect(screen.getByText('1/1/2022, 12:00:00 AM')).toBeInTheDocument();
|
|
43
55
|
});
|
|
44
56
|
|
|
57
|
+
test('Renders with correct datetime attribute when date is passed in', () => {
|
|
58
|
+
const passedDate = new Date(2022, 0, 1);
|
|
59
|
+
render(<Timestamp date={passedDate} />);
|
|
60
|
+
|
|
61
|
+
expect(screen.getByText('1/1/2022, 12:00:00 AM')).toHaveAttribute('datetime', passedDate.toISOString());
|
|
62
|
+
});
|
|
63
|
+
|
|
45
64
|
test('Renders with custom formatting when dateFormat and timeFormat are passed in', () => {
|
|
46
65
|
render(
|
|
47
66
|
<Timestamp date={new Date(2022, 0, 1)} dateFormat={TimestampFormat.full} timeFormat={TimestampFormat.short} />
|
|
@@ -51,7 +70,7 @@ test('Renders with custom formatting when dateFormat and timeFormat are passed i
|
|
|
51
70
|
});
|
|
52
71
|
|
|
53
72
|
test('Renders with only date when dateFormat is passed in', () => {
|
|
54
|
-
render(<Timestamp date={new Date(
|
|
73
|
+
render(<Timestamp date={new Date(2022, 0, 1)} dateFormat={TimestampFormat.full} />);
|
|
55
74
|
|
|
56
75
|
expect(screen.getByText('Saturday, January 1, 2022')).toBeInTheDocument();
|
|
57
76
|
});
|
|
@@ -152,9 +171,7 @@ test('Renders with pf-m-help-text class when tooltip is passed in with custom va
|
|
|
152
171
|
});
|
|
153
172
|
|
|
154
173
|
test('Renders with default tooltip content for default variant', () => {
|
|
155
|
-
render(
|
|
156
|
-
<Timestamp date={new Date('1 Jan 2022 00:00:00 EST')} tooltip={{ variant: TimestampTooltipVariant.default }} />
|
|
157
|
-
);
|
|
174
|
+
render(<Timestamp date={new Date(2022, 0, 1, 0, 0, 0)} tooltip={{ variant: TimestampTooltipVariant.default }} />);
|
|
158
175
|
|
|
159
176
|
expect(screen.getByText('1/1/2022, 5:00:00 AM UTC')).toBeInTheDocument();
|
|
160
177
|
});
|
|
@@ -162,7 +179,7 @@ test('Renders with default tooltip content for default variant', () => {
|
|
|
162
179
|
test('Renders with custom tooltip suffix for default variant', () => {
|
|
163
180
|
render(
|
|
164
181
|
<Timestamp
|
|
165
|
-
date={new Date(
|
|
182
|
+
date={new Date(2022, 0, 1, 0, 0, 0)}
|
|
166
183
|
tooltip={{ variant: TimestampTooltipVariant.default, suffix: 'Coordinated Universal Time' }}
|
|
167
184
|
/>
|
|
168
185
|
);
|
package/src/helpers/index.ts
CHANGED