@patternfly/react-core 5.0.0-alpha.51 → 5.0.0-alpha.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "5.0.0-alpha.51",
3
+ "version": "5.0.0-alpha.53",
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": "^17 || ^18",
71
71
  "react-dom": "^17 || ^18"
72
72
  },
73
- "gitHead": "1b1bde2cf964d501b24a499274099e1de0b60425"
73
+ "gitHead": "c4f0e8983765fbf06c61c96ff4ed29731087355f"
74
74
  }
@@ -373,9 +373,22 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
373
373
  onToggle = (isOpen: boolean) => {
374
374
  // on close, parse and validate input
375
375
  this.setState(prevState => {
376
- const { timeRegex, isInvalid } = prevState;
377
- const { delimiter, is24Hour, includeSeconds } = this.props;
378
- const time = parseTime(prevState.timeState, timeRegex, delimiter, !is24Hour, includeSeconds);
376
+ const { timeRegex, isInvalid, timeState } = prevState;
377
+ const { delimiter, is24Hour, includeSeconds, onChange } = this.props;
378
+ const time = parseTime(timeState, timeRegex, delimiter, !is24Hour, includeSeconds);
379
+
380
+ // Call onChange when Enter is pressed in input and timeoption does not exist in menu
381
+ if (onChange && !isOpen && time !== timeState) {
382
+ onChange(
383
+ null,
384
+ time,
385
+ getHours(time, timeRegex),
386
+ getMinutes(time, timeRegex),
387
+ getSeconds(time, timeRegex),
388
+ this.isValid(time)
389
+ );
390
+ }
391
+
379
392
  return {
380
393
  isTimeOptionsOpen: isOpen,
381
394
  timeState: time,
@@ -414,7 +427,6 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
414
427
  onInputChange = (newTime: string, event: React.FormEvent<HTMLInputElement>) => {
415
428
  const { onChange } = this.props;
416
429
  const { timeRegex } = this.state;
417
-
418
430
  if (onChange) {
419
431
  onChange(
420
432
  event,
@@ -86,6 +86,28 @@ describe('TimePicker', () => {
86
86
  expects: { hour: 23, minutes: 59, seconds: null }
87
87
  });
88
88
  });
89
+
90
+ // Disabling because this test does not work on CI
91
+ xtest('should call onChange when pressing Enter', async () => {
92
+ const onChange = jest.fn();
93
+ const user = userEvent.setup();
94
+
95
+ render(<TimePicker onChange={onChange} aria-label="time picker" />);
96
+
97
+ // Take into account timezones when tests are ran
98
+ const isPM = new Date().getHours() > 12;
99
+
100
+ await user.type(screen.getByLabelText('time picker'), `11:11`);
101
+ await user.keyboard('[Enter]');
102
+ expect(onChange).toHaveBeenLastCalledWith(
103
+ expect.any(Object),
104
+ `11:11 ${isPM ? 'PM' : 'AM'}`,
105
+ isPM ? 23 : 11,
106
+ 11,
107
+ null,
108
+ true
109
+ );
110
+ });
89
111
  });
90
112
 
91
113
  describe('test isInvalid', () => {
@@ -8,7 +8,7 @@ import InfoCircleIcon from '@patternfly/react-icons/dist/js/icons/info-circle-ic
8
8
  import ArrowRightIcon from '@patternfly/react-icons/dist/js/icons/arrow-right-icon';
9
9
  import ExternalLinkAltIcon from '@patternfly/react-icons/dist/js/icons/external-link-alt-icon';
10
10
  import { CheckCircleIcon, ExclamationCircleIcon, ExclamationTriangleIcon, TimesCircleIcon, BellIcon } from '@patternfly/react-icons';
11
- import { TableComposable, Thead, Tbody, Tr, Th, Td, ExpandableRowContent } from '@patternfly/react-table';
11
+ import { Table, Thead, Tbody, Tr, Th, Td, ExpandableRowContent } from '@patternfly/react-table';
12
12
  import { Chart, ChartAxis, ChartGroup, ChartVoronoiContainer, ChartStack, ChartBar, ChartTooltip, ChartDonutThreshold, ChartDonutUtilization, ChartArea, ChartContainer, ChartLabel } from '@patternfly/react-charts';
13
13
  import chart_color_gold_100 from '@patternfly/react-tokens/dist/esm/chart_color_gold_100';
14
14
  import chart_color_gold_300 from '@patternfly/react-tokens/dist/esm/chart_color_gold_300';
@@ -655,7 +655,7 @@ import {
655
655
  Popover,
656
656
  Title
657
657
  } from '@patternfly/react-core';
658
- import { TableComposable, Thead, Tbody, Tr, Th, Td, ExpandableRowContent } from '@patternfly/react-table';
658
+ import { Table, Thead, Tbody, Tr, Th, Td, ExpandableRowContent } from '@patternfly/react-table';
659
659
  import BellIcon from '@patternfly/react-icons/dist/js/icons/bell-icon';
660
660
  import CheckCircleIcon from '@patternfly/react-icons/dist/js/icons/check-circle-icon';
661
661
  import ExclamationCircleIcon from '@patternfly/react-icons/dist/js/icons/exclamation-circle-icon';
@@ -723,7 +723,7 @@ const StatusPlain: React.FunctionComponent = () => {
723
723
  <div>
724
724
  Components of the Control Panel are responsible for maintaining and reconciling the state of the cluster.
725
725
  </div>
726
- <TableComposable variant="compact">
726
+ <Table variant="compact">
727
727
  <Thead>
728
728
  <Tr>
729
729
  <Th />
@@ -762,7 +762,7 @@ const StatusPlain: React.FunctionComponent = () => {
762
762
  </Tbody>
763
763
  );
764
764
  })}
765
- </TableComposable>
765
+ </Table>
766
766
  </>
767
767
  );
768
768
 
@@ -18,34 +18,35 @@ DateRangePicker = () => {
18
18
  const [from, setFrom] = React.useState();
19
19
  const [to, setTo] = React.useState();
20
20
 
21
- const toValidator = date => isValidDate(from) && date >= from ? '' : 'To date must be less than from date';
22
- const onFromChange = (_str, date) => {
21
+ const toValidator = (date) =>
22
+ isValidDate(from) && date >= from ? '' : 'The "to" date must be after the "from" date';
23
+
24
+ const onFromChange = (_event, _value, date) => {
23
25
  setFrom(new Date(date));
24
26
  if (isValidDate(date)) {
25
27
  date.setDate(date.getDate() + 1);
26
28
  setTo(yyyyMMddFormat(date));
27
- }
28
- else {
29
+ } else {
29
30
  setTo('');
30
31
  }
31
32
  };
32
33
 
34
+ const onToChange = (_event, _value, date) => {
35
+ if (isValidDate(date)) {
36
+ setTo(yyyyMMddFormat(date));
37
+ }
38
+ };
39
+
33
40
  return (
34
41
  <Split>
35
42
  <SplitItem>
36
- <DatePicker
37
- onChange={onFromChange}
38
- aria-label="Start date"
39
- placeholder="YYYY-MM-DD"
40
- />
41
- </SplitItem>
42
- <SplitItem style={{ padding: '6px 12px 0 12px' }}>
43
- to
43
+ <DatePicker onChange={onFromChange} aria-label="Start date" placeholder="YYYY-MM-DD" />
44
44
  </SplitItem>
45
+ <SplitItem style={{ padding: '6px 12px 0 12px' }}>to</SplitItem>
45
46
  <SplitItem>
46
47
  <DatePicker
47
48
  value={to}
48
- onChange={date => setTo(date)}
49
+ onChange={onToChange}
49
50
  isDisabled={!isValidDate(from)}
50
51
  rangeStart={from}
51
52
  validators={[toValidator]}
@@ -55,23 +56,34 @@ DateRangePicker = () => {
55
56
  </SplitItem>
56
57
  </Split>
57
58
  );
58
- }
59
+ };
59
60
  ```
60
61
 
61
62
  ### Date and time range picker
62
63
 
63
64
  ```js
64
- import { Flex, FlexItem, InputGroup, DatePicker, isValidDate, TimePicker, yyyyMMddFormat, updateDateTime } from '@patternfly/react-core';
65
+ import {
66
+ Flex,
67
+ FlexItem,
68
+ InputGroup,
69
+ DatePicker,
70
+ isValidDate,
71
+ TimePicker,
72
+ yyyyMMddFormat,
73
+ updateDateTime
74
+ } from '@patternfly/react-core';
65
75
 
66
76
  DateTimeRangePicker = () => {
67
77
  const [from, setFrom] = React.useState();
68
78
  const [to, setTo] = React.useState();
69
79
 
70
- const toValidator = date => {
71
- return isValidDate(from) && yyyyMMddFormat(date) >= yyyyMMddFormat(from) ? '' : 'To date must after from date';
80
+ const toValidator = (date) => {
81
+ return isValidDate(from) && yyyyMMddFormat(date) >= yyyyMMddFormat(from)
82
+ ? ''
83
+ : 'The "to" date must be after the "from" date';
72
84
  };
73
-
74
- const onFromDateChange = (inputDate, newFromDate) => {
85
+
86
+ const onFromDateChange = (_event, inputDate, newFromDate) => {
75
87
  if (isValidDate(from) && isValidDate(newFromDate) && inputDate === yyyyMMddFormat(newFromDate)) {
76
88
  newFromDate.setHours(from.getHours());
77
89
  newFromDate.setMinutes(from.getMinutes());
@@ -80,7 +92,7 @@ DateTimeRangePicker = () => {
80
92
  setFrom(new Date(newFromDate));
81
93
  }
82
94
  };
83
-
95
+
84
96
  const onFromTimeChange = (_event, time, hour, minute) => {
85
97
  if (isValidDate(from)) {
86
98
  const updatedFromDate = new Date(from);
@@ -90,16 +102,16 @@ DateTimeRangePicker = () => {
90
102
  }
91
103
  };
92
104
 
93
- const onToDateChange = (inputDate, newToDate) => {
105
+ const onToDateChange = (_event, inputDate, newToDate) => {
94
106
  if (isValidDate(to) && isValidDate(newToDate) && inputDate === yyyyMMddFormat(newToDate)) {
95
107
  newToDate.setHours(to.getHours());
96
108
  newToDate.setMinutes(to.getMinutes());
97
109
  }
98
- if (isValidDate(newToDate) && inputDate === yyyyMMddFormat(newToDate)){
110
+ if (isValidDate(newToDate) && inputDate === yyyyMMddFormat(newToDate)) {
99
111
  setTo(newToDate);
100
112
  }
101
113
  };
102
-
114
+
103
115
  const onToTimeChange = (_event, time, hour, minute) => {
104
116
  if (isValidDate(to)) {
105
117
  const updatedToDate = new Date(to);
@@ -110,24 +122,14 @@ DateTimeRangePicker = () => {
110
122
  };
111
123
 
112
124
  return (
113
- <Flex direction={{default: 'column', lg: 'row'}}>
125
+ <Flex direction={{ default: 'column', lg: 'row' }}>
114
126
  <FlexItem>
115
127
  <InputGroup>
116
- <DatePicker
117
- onChange={onFromDateChange}
118
- aria-label="Start date"
119
- placeholder="YYYY-MM-DD"
120
- />
121
- <TimePicker
122
- aria-label="Start time"
123
- style={{width: '150px'}}
124
- onChange={onFromTimeChange}
125
- />
128
+ <DatePicker onChange={onFromDateChange} aria-label="Start date" placeholder="YYYY-MM-DD" />
129
+ <TimePicker aria-label="Start time" style={{ width: '150px' }} onChange={onFromTimeChange} />
126
130
  </InputGroup>
127
131
  </FlexItem>
128
- <FlexItem>
129
- to
130
- </FlexItem>
132
+ <FlexItem>to</FlexItem>
131
133
  <FlexItem>
132
134
  <InputGroup>
133
135
  <DatePicker
@@ -139,19 +141,22 @@ DateTimeRangePicker = () => {
139
141
  aria-label="End date"
140
142
  placeholder="YYYY-MM-DD"
141
143
  />
142
- <TimePicker style={{width: '150px'}} onChange={onToTimeChange} isDisabled={!isValidDate(from)}/>
144
+ <TimePicker style={{ width: '150px' }} onChange={onToTimeChange} isDisabled={!isValidDate(from)} />
143
145
  </InputGroup>
144
146
  </FlexItem>
145
147
  </Flex>
146
148
  );
147
- }
149
+ };
148
150
  ```
149
151
 
150
-
151
152
  ### Date and time pickers in modal
153
+
152
154
  Modals trap focus and watch a few document level events. In order to place a date picker in a modal:
155
+
153
156
  - To avoid the modal's escape press event handler from overruling the date picker's escape press handlers, use the `DatePickerRef` to close the calendar when it is open and the escape key is pressed.
154
157
  - Append the calendar to the modal to keep it as close to the date picker in the DOM while maintaining correct layouts visually
155
158
  In order to place a time picker in the modal, its menu must be appended to the time picker's parent.
159
+
156
160
  ```ts file="./examples/DateTimePickerInModal.tsx"
161
+
157
162
  ```
@@ -32,7 +32,7 @@ ToolbarToggleGroup
32
32
  } from '@patternfly/react-core';
33
33
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
34
34
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
35
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
35
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
36
36
 
37
37
  ## Filtering demos
38
38
 
@@ -25,7 +25,7 @@ import {
25
25
  EmptyStateActions,
26
26
  EmptyStateIcon
27
27
  } from '@patternfly/react-core';
28
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
28
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
29
29
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
30
30
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
31
31
 
@@ -649,7 +649,7 @@ export const FilterAttributeSearch: React.FunctionComponent = () => {
649
649
  return (
650
650
  <React.Fragment>
651
651
  {toolbar}
652
- <TableComposable aria-label="Selectable table">
652
+ <Table aria-label="Selectable table">
653
653
  <Thead>
654
654
  <Tr>
655
655
  <Th />
@@ -701,7 +701,7 @@ export const FilterAttributeSearch: React.FunctionComponent = () => {
701
701
  </Tr>
702
702
  )}
703
703
  </Tbody>
704
- </TableComposable>
704
+ </Table>
705
705
  </React.Fragment>
706
706
  );
707
707
  };
@@ -15,7 +15,7 @@ import {
15
15
  Badge,
16
16
  Pagination
17
17
  } from '@patternfly/react-core';
18
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
18
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
19
19
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
20
20
 
21
21
  interface Repository {
@@ -375,7 +375,7 @@ export const FilterCheckboxSelect: React.FunctionComponent = () => {
375
375
  return (
376
376
  <React.Fragment>
377
377
  {toolbar}
378
- <TableComposable aria-label="Selectable table">
378
+ <Table aria-label="Selectable table">
379
379
  <Thead>
380
380
  <Tr>
381
381
  <Th />
@@ -419,7 +419,7 @@ export const FilterCheckboxSelect: React.FunctionComponent = () => {
419
419
  </Tr>
420
420
  ))}
421
421
  </Tbody>
422
- </TableComposable>
422
+ </Table>
423
423
  </React.Fragment>
424
424
  );
425
425
  };
@@ -24,7 +24,7 @@ import {
24
24
  EmptyStateIcon,
25
25
  EmptyStateActions
26
26
  } from '@patternfly/react-core';
27
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
27
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
28
28
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
29
29
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
30
30
 
@@ -465,7 +465,7 @@ export const FilterFaceted: React.FunctionComponent = () => {
465
465
  return (
466
466
  <React.Fragment>
467
467
  {toolbar}
468
- <TableComposable aria-label="Selectable table">
468
+ <Table aria-label="Selectable table">
469
469
  <Thead>
470
470
  <Tr>
471
471
  <Th />
@@ -517,7 +517,7 @@ export const FilterFaceted: React.FunctionComponent = () => {
517
517
  </Tr>
518
518
  )}
519
519
  </Tbody>
520
- </TableComposable>
520
+ </Table>
521
521
  </React.Fragment>
522
522
  );
523
523
  };
@@ -23,7 +23,7 @@ import {
23
23
  EmptyStateIcon,
24
24
  EmptyStateActions
25
25
  } from '@patternfly/react-core';
26
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
26
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
27
27
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
28
28
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
29
29
 
@@ -515,7 +515,7 @@ export const FilterMixedSelectGroup: React.FunctionComponent = () => {
515
515
  return (
516
516
  <React.Fragment>
517
517
  {toolbar}
518
- <TableComposable aria-label="Selectable table">
518
+ <Table aria-label="Selectable table">
519
519
  <Thead>
520
520
  <Tr>
521
521
  <Th />
@@ -567,7 +567,7 @@ export const FilterMixedSelectGroup: React.FunctionComponent = () => {
567
567
  </Tr>
568
568
  )}
569
569
  </Tbody>
570
- </TableComposable>
570
+ </Table>
571
571
  </React.Fragment>
572
572
  );
573
573
  };
@@ -21,7 +21,7 @@ import {
21
21
  EmptyStateIcon,
22
22
  EmptyStateActions
23
23
  } from '@patternfly/react-core';
24
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
24
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
25
25
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
26
26
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
27
27
 
@@ -488,7 +488,7 @@ export const FilterSameSelectGroup: React.FunctionComponent = () => {
488
488
  return (
489
489
  <React.Fragment>
490
490
  {toolbar}
491
- <TableComposable aria-label="Selectable table">
491
+ <Table aria-label="Selectable table">
492
492
  <Thead>
493
493
  <Tr>
494
494
  <Th />
@@ -540,7 +540,7 @@ export const FilterSameSelectGroup: React.FunctionComponent = () => {
540
540
  </Tr>
541
541
  )}
542
542
  </Tbody>
543
- </TableComposable>
543
+ </Table>
544
544
  </React.Fragment>
545
545
  );
546
546
  };
@@ -21,7 +21,7 @@ import {
21
21
  EmptyStateIcon,
22
22
  EmptyStateActions
23
23
  } from '@patternfly/react-core';
24
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
24
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
25
25
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
26
26
 
27
27
  interface Repository {
@@ -296,7 +296,7 @@ export const FilterSearchInput: React.FunctionComponent = () => {
296
296
  return (
297
297
  <React.Fragment>
298
298
  {toolbar}
299
- <TableComposable aria-label="Selectable table">
299
+ <Table aria-label="Selectable table">
300
300
  <Thead>
301
301
  <Tr>
302
302
  <Th />
@@ -348,7 +348,7 @@ export const FilterSearchInput: React.FunctionComponent = () => {
348
348
  </Tr>
349
349
  )}
350
350
  </Tbody>
351
- </TableComposable>
351
+ </Table>
352
352
  </React.Fragment>
353
353
  );
354
354
  };
@@ -12,7 +12,7 @@ import {
12
12
  ToolbarItem,
13
13
  Pagination
14
14
  } from '@patternfly/react-core';
15
- import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
15
+ import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
16
16
  import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
17
17
 
18
18
  interface Repository {
@@ -360,7 +360,7 @@ export const FilterSingleSelect: React.FunctionComponent = () => {
360
360
  return (
361
361
  <React.Fragment>
362
362
  {toolbar}
363
- <TableComposable aria-label="Selectable table">
363
+ <Table aria-label="Selectable table">
364
364
  <Thead>
365
365
  <Tr>
366
366
  <Th />
@@ -404,7 +404,7 @@ export const FilterSingleSelect: React.FunctionComponent = () => {
404
404
  </Tr>
405
405
  ))}
406
406
  </Tbody>
407
- </TableComposable>
407
+ </Table>
408
408
  </React.Fragment>
409
409
  );
410
410
  };
@@ -41,7 +41,7 @@ import {
41
41
  ToolbarToggleGroup
42
42
  } from '@patternfly/react-core';
43
43
  import {
44
- TableComposable,
44
+ Table,
45
45
  Thead,
46
46
  Tbody,
47
47
  Tr,
@@ -209,8 +209,8 @@ export const TablesAndTabs = () => {
209
209
  </Toolbar>
210
210
  );
211
211
 
212
- const tableComposable = (
213
- <TableComposable aria-label="`Composable` table">
212
+ const table = (
213
+ <Table aria-label="`Composable` table">
214
214
  <Thead noWrap>
215
215
  <Tr>
216
216
  <Th
@@ -284,7 +284,7 @@ export const TablesAndTabs = () => {
284
284
  </Tr>
285
285
  ))}
286
286
  </Tbody>
287
- </TableComposable>
287
+ </Table>
288
288
  );
289
289
 
290
290
  const panelContent = (
@@ -375,7 +375,7 @@ export const TablesAndTabs = () => {
375
375
  const tabContent = (
376
376
  <Drawer isExpanded={isExpanded} isInline>
377
377
  <DrawerContent panelContent={panelContent}>
378
- <DrawerContentBody>{tableComposable}</DrawerContentBody>
378
+ <DrawerContentBody>{table}</DrawerContentBody>
379
379
  </DrawerContent>
380
380
  </Drawer>
381
381
  );