@patternfly/react-core 4.256.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/esm/components/Banner/Banner.d.ts +7 -5
  3. package/dist/esm/components/Banner/Banner.d.ts.map +1 -1
  4. package/dist/esm/components/Banner/Banner.js +2 -2
  5. package/dist/esm/components/Banner/Banner.js.map +1 -1
  6. package/dist/esm/components/CalendarMonth/CalendarMonth.d.ts +0 -1
  7. package/dist/esm/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
  8. package/dist/esm/components/CalendarMonth/CalendarMonth.js +1 -1
  9. package/dist/esm/components/CalendarMonth/CalendarMonth.js.map +1 -1
  10. package/dist/esm/components/DatePicker/DatePicker.d.ts.map +1 -1
  11. package/dist/esm/components/DatePicker/DatePicker.js +2 -1
  12. package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
  13. package/dist/esm/components/Timestamp/Timestamp.d.ts.map +1 -1
  14. package/dist/esm/components/Timestamp/Timestamp.js +23 -5
  15. package/dist/esm/components/Timestamp/Timestamp.js.map +1 -1
  16. package/dist/esm/helpers/datetimeUtils.d.ts +5 -0
  17. package/dist/esm/helpers/datetimeUtils.d.ts.map +1 -0
  18. package/dist/esm/helpers/datetimeUtils.js +5 -0
  19. package/dist/esm/helpers/datetimeUtils.js.map +1 -0
  20. package/dist/esm/helpers/index.d.ts +1 -0
  21. package/dist/esm/helpers/index.d.ts.map +1 -1
  22. package/dist/esm/helpers/index.js +1 -0
  23. package/dist/esm/helpers/index.js.map +1 -1
  24. package/dist/js/components/Banner/Banner.d.ts +7 -5
  25. package/dist/js/components/Banner/Banner.d.ts.map +1 -1
  26. package/dist/js/components/Banner/Banner.js +2 -2
  27. package/dist/js/components/Banner/Banner.js.map +1 -1
  28. package/dist/js/components/CalendarMonth/CalendarMonth.d.ts +0 -1
  29. package/dist/js/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
  30. package/dist/js/components/CalendarMonth/CalendarMonth.js +9 -10
  31. package/dist/js/components/CalendarMonth/CalendarMonth.js.map +1 -1
  32. package/dist/js/components/DatePicker/DatePicker.d.ts.map +1 -1
  33. package/dist/js/components/DatePicker/DatePicker.js +5 -4
  34. package/dist/js/components/DatePicker/DatePicker.js.map +1 -1
  35. package/dist/js/components/Timestamp/Timestamp.d.ts.map +1 -1
  36. package/dist/js/components/Timestamp/Timestamp.js +23 -5
  37. package/dist/js/components/Timestamp/Timestamp.js.map +1 -1
  38. package/dist/js/helpers/datetimeUtils.d.ts +5 -0
  39. package/dist/js/helpers/datetimeUtils.d.ts.map +1 -0
  40. package/dist/js/helpers/datetimeUtils.js +9 -0
  41. package/dist/js/helpers/datetimeUtils.js.map +1 -0
  42. package/dist/js/helpers/index.d.ts +1 -0
  43. package/dist/js/helpers/index.d.ts.map +1 -1
  44. package/dist/js/helpers/index.js +1 -0
  45. package/dist/js/helpers/index.js.map +1 -1
  46. package/dist/umd/react-core.min.css +21367 -21367
  47. package/dist/umd/react-core.min.js +3 -3
  48. package/package.json +2 -2
  49. package/src/components/Banner/Banner.tsx +8 -6
  50. package/src/components/Banner/__tests__/Banner.test.tsx +3 -13
  51. package/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap +0 -5
  52. package/src/components/Banner/examples/Banner.md +19 -0
  53. package/src/components/Banner/examples/BannerBasic.tsx +7 -9
  54. package/src/components/Banner/examples/BannerStatus.tsx +56 -0
  55. package/src/components/CalendarMonth/CalendarMonth.tsx +1 -2
  56. package/src/components/DatePicker/DatePicker.tsx +2 -1
  57. package/src/components/Timestamp/Timestamp.tsx +26 -5
  58. package/src/components/Timestamp/__tests__/Timestamp.test.tsx +22 -5
  59. package/src/components/Timestamp/__tests__/__snapshots__/Timestamp.test.tsx.snap +0 -1
  60. package/src/helpers/datetimeUtils.ts +4 -0
  61. 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.256.0",
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": "b7e13a9702cfe902e190000f1cfe059c830cf881"
73
+ "gitHead": "9aafcbc3a7986f6fb5837f887cf1a25f01a11e8b"
74
74
  }
@@ -3,16 +3,18 @@ import styles from '@patternfly/react-styles/css/components/Banner/banner';
3
3
  import { css } from '@patternfly/react-styles';
4
4
 
5
5
  export interface BannerProps extends React.HTMLProps<HTMLDivElement> {
6
- /** Content rendered inside the banner */
6
+ /** Content rendered inside the banner. */
7
7
  children?: React.ReactNode;
8
- /** Additional classes added to the banner */
8
+ /** Additional classes added to the banner. */
9
9
  className?: string;
10
- /** Variant styles for the banner */
11
- variant?: 'default' | 'info' | 'danger' | 'success' | 'warning';
12
10
  /** If set to true, the banner sticks to the top of its container */
13
11
  isSticky?: boolean;
14
- /** Text announced by screen readers to indicate the type of banner. Defaults to "${variant} banner" if this prop is not passed in */
12
+ /** Text announced by screen readers to indicate the type of banner. This prop should only
13
+ * be passed in when the banner conveys status/severity.
14
+ */
15
15
  screenReaderText?: string;
16
+ /** Variant styles for the banner. */
17
+ variant?: 'default' | 'info' | 'danger' | 'success' | 'warning';
16
18
  }
17
19
 
18
20
  export const Banner: React.FunctionComponent<BannerProps> = ({
@@ -32,8 +34,8 @@ export const Banner: React.FunctionComponent<BannerProps> = ({
32
34
  )}
33
35
  {...props}
34
36
  >
37
+ {screenReaderText && <span className="pf-u-screen-reader">{screenReaderText}</span>}
35
38
  {children}
36
- <span className="pf-u-screen-reader">{screenReaderText || `${variant} banner`}</span>
37
39
  </div>
38
40
  );
39
41
  Banner.displayName = 'Banner';
@@ -51,22 +51,12 @@ test('Renders with class name pf-m-info when "info" is passed to variant prop',
51
51
  expect(screen.getByText('Test')).toHaveClass('pf-m-info');
52
52
  });
53
53
 
54
- test('Renders pf-u-screen-reader class by default for screenReaderText', () => {
54
+ test('Does not render pf-u-screen-reader class by default', () => {
55
55
  render(<Banner>Test</Banner>);
56
- expect(screen.getByText('default banner')).toHaveClass('pf-u-screen-reader', { exact: true });
56
+ expect(screen.getByText('Test')).not.toContainHTML('<span class="pf-u-screen-reader"></span>');
57
57
  });
58
58
 
59
- test('Renders screenReaderText as "default banner" by default', () => {
60
- render(<Banner>Test</Banner>);
61
- expect(screen.getByText('default banner')).toBeInTheDocument();
62
- });
63
-
64
- test('Renders screenReaderText as "success banner" when variant="success"', () => {
65
- render(<Banner variant="success">Test</Banner>);
66
- expect(screen.getByText('success banner')).toBeInTheDocument();
67
- });
68
-
69
- test('Renders custom screenReaderText passed via prop', () => {
59
+ test('Renders screenReaderText passed via prop', () => {
70
60
  render(<Banner screenReaderText="Custom screen reader text">Test</Banner>);
71
61
  expect(screen.getByText('Custom screen reader text')).toBeInTheDocument();
72
62
  });
@@ -6,11 +6,6 @@ exports[`Matches the snapshot 1`] = `
6
6
  class="pf-c-banner"
7
7
  >
8
8
  Test
9
- <span
10
- class="pf-u-screen-reader"
11
- >
12
- default banner
13
- </span>
14
9
  </div>
15
10
  </DocumentFragment>
16
11
  `;
@@ -5,9 +5,28 @@ cssPrefix: pf-c-banner
5
5
  propComponents: ['Banner']
6
6
  ---
7
7
 
8
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
9
+ import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
10
+ import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
11
+ import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
12
+ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
13
+
8
14
  ## Examples
9
15
 
10
16
  ### Basic
11
17
 
18
+ Banners can be styled with one of 5 different colors. A basic banner should only be used when the banner color does not represent status or severity.
19
+
12
20
  ```ts file="./BannerBasic.tsx"
21
+
22
+ ```
23
+
24
+ ### Status
25
+
26
+ When a banner is used to convey status, it is advised to pass in an icon inside the banner to convey the status in a way besides just color. The `screenReaderText` prop should also be passed in to convey the status/severity of the banner to users of certain assistive technologies such as screen readers.
27
+
28
+ In the following example, a flex layout is used inside the banner content to show one possible way to create spacing between the icons and banner text.
29
+
30
+ ```ts file="./BannerStatus.tsx"
31
+
13
32
  ```
@@ -2,17 +2,15 @@ import React from 'react';
2
2
  import { Banner } from '@patternfly/react-core';
3
3
 
4
4
  export const BannerBasic: React.FunctionComponent = () => (
5
- <React.Fragment>
6
- <Banner screenReaderText="This is a default Banner">Default banner</Banner>
5
+ <>
6
+ <Banner>Default banner</Banner>
7
7
  <br />
8
- <Banner variant="info" screenReaderText="This is an info Banner">
9
- Info banner
10
- </Banner>
8
+ <Banner variant="info">Blue banner</Banner>
11
9
  <br />
12
- <Banner variant="danger">Danger banner</Banner>
10
+ <Banner variant="danger">Red banner</Banner>
13
11
  <br />
14
- <Banner variant="success">Success banner</Banner>
12
+ <Banner variant="success">Green banner</Banner>
15
13
  <br />
16
- <Banner variant="warning">Warning banner</Banner>
17
- </React.Fragment>
14
+ <Banner variant="warning">Gold banner</Banner>
15
+ </>
18
16
  );
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import { Banner, Flex, FlexItem } from '@patternfly/react-core';
3
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
4
+ import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
5
+ import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
6
+ import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
7
+ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
8
+
9
+ export const BannerStatus: React.FunctionComponent = () => (
10
+ <>
11
+ <Banner screenReaderText="Default banner">
12
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
13
+ <FlexItem>
14
+ <BellIcon />
15
+ </FlexItem>
16
+ <FlexItem>Default banner</FlexItem>
17
+ </Flex>
18
+ </Banner>
19
+ <br />
20
+ <Banner screenReaderText="Info banner" variant="info">
21
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
22
+ <FlexItem>
23
+ <InfoCircleIcon />
24
+ </FlexItem>
25
+ <FlexItem>Info banner</FlexItem>
26
+ </Flex>
27
+ </Banner>
28
+ <br />
29
+ <Banner screenReaderText="Danger banner" variant="danger">
30
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
31
+ <FlexItem>
32
+ <ExclamationCircleIcon />
33
+ </FlexItem>
34
+ <FlexItem>Danger banner</FlexItem>
35
+ </Flex>
36
+ </Banner>
37
+ <br />
38
+ <Banner screenReaderText="Success banner" variant="success">
39
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
40
+ <FlexItem>
41
+ <CheckCircleIcon />
42
+ </FlexItem>
43
+ <FlexItem>Success banner</FlexItem>
44
+ </Flex>
45
+ </Banner>
46
+ <br />
47
+ <Banner screenReaderText="Warning banner" variant="warning">
48
+ <Flex spaceItems={{ default: 'spaceItemsSm' }}>
49
+ <FlexItem>
50
+ <ExclamationTriangleIcon />
51
+ </FlexItem>
52
+ <FlexItem>Warning banner</FlexItem>
53
+ </Flex>
54
+ </Banner>
55
+ </>
56
+ );
@@ -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, isValidDate } from '../CalendarMonth';
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 = new Date(),
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(dateProp).toLocaleString(locale, {
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(dateProp)).toLocaleString(locale, {
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
- {...props}
136
+ {...propsWithoutDateTime}
116
137
  >
117
- <time className="pf-c-timestamp__text" dateTime={props.dateTime || new Date(dateProp).toISOString()}>
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('1 Jan 2022 00:00:00 EST')} dateFormat={TimestampFormat.full} />);
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('1 Jan 2022 00:00:00 EST')}
182
+ date={new Date(2022, 0, 1, 0, 0, 0)}
166
183
  tooltip={{ variant: TimestampTooltipVariant.default, suffix: 'Coordinated Universal Time' }}
167
184
  />
168
185
  );
@@ -4,7 +4,6 @@ exports[`Matches snapshot 1`] = `
4
4
  <DocumentFragment>
5
5
  <span
6
6
  class="pf-c-timestamp"
7
- datetime="2022-01-01T00:00:00.000Z"
8
7
  >
9
8
  <time
10
9
  class="pf-c-timestamp__text"
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @param {Date} date - A date to check the validity of
3
+ */
4
+ export const isValidDate = (date: Date) => Boolean(date && !isNaN(date as any));
@@ -10,3 +10,4 @@ export * from './useIsomorphicLayout';
10
10
  export * from './KeyboardHandler';
11
11
  export * from './resizeObserver';
12
12
  export * from './useInterval';
13
+ export * from './datetimeUtils';