@patternfly/react-core 4.202.19 → 4.202.22

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": "4.202.19",
3
+ "version": "4.202.22",
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.53.19",
38
- "@patternfly/react-styles": "^4.52.19",
39
- "@patternfly/react-tokens": "^4.54.19",
37
+ "@patternfly/react-icons": "^4.53.22",
38
+ "@patternfly/react-styles": "^4.52.22",
39
+ "@patternfly/react-tokens": "^4.54.22",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
43
43
  "tslib": "^2.0.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@patternfly/patternfly": "4.185.1",
46
+ "@patternfly/patternfly": "4.185.2",
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": "9e9d16ac392a83a7141cd1720079d46bc6bd796b"
63
+ "gitHead": "666820fe0384d9c5cc9c52dee3a7b5fdb836d32d"
64
64
  }
@@ -7,151 +7,38 @@ beta: true
7
7
  ---
8
8
 
9
9
  ## Examples
10
+
10
11
  ### Basic
11
- ```js
12
- import React from 'react';
13
- import { DatePicker } from '@patternfly/react-core';
14
12
 
15
- <DatePicker
16
- onBlur={(str, date) => console.log('onBlur', str, date)}
17
- onChange={(str, date) => console.log('onChange', str, date)}
18
- />
13
+ ```ts file="./DatePickerBasic.tsx"
19
14
  ```
20
15
 
21
16
  ### American format
22
- ```js
23
- import React from 'react';
24
- import { DatePicker } from '@patternfly/react-core';
25
-
26
- AmericanFormat = () => {
27
- const dateFormat = date => date.toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g,'-');
28
- const dateParse = date => {
29
- const split = date.split('-');
30
- if (split.length !== 3) {
31
- return new Date();
32
- }
33
- let month = split[0];
34
- let day = split[1];
35
- let year = split[2];
36
- return new Date(`${year.padStart(4, '0')}-${month.padStart(2, '0')}-${day.padStart(2, '0')}T00:00:00`);
37
- };
38
17
 
39
- return (
40
- <DatePicker
41
- value="03-05-2020"
42
- placeholder="MM-DD-YYYY"
43
- dateFormat={dateFormat}
44
- dateParse={dateParse}
45
- />
46
- );
47
- }
18
+ ```ts file="./DatePickerAmerican.tsx"
48
19
  ```
49
20
 
50
21
  ### Helper text
51
- ```js
52
- import React from 'react';
53
- import { DatePicker } from '@patternfly/react-core';
54
22
 
55
- <DatePicker value="2020-03-05" helperText="Select a date." />
23
+ ```ts file="./DatePickerHelperText.tsx"
56
24
  ```
57
25
 
58
26
  ### Min and max date
59
- ```js
60
- import React from 'react';
61
- import { DatePicker } from '@patternfly/react-core';
62
27
 
63
- MinMaxDate = () => {
64
- const minDate = new Date(2020, 2, 16);
65
- const maxDate = new Date(2020, 2, 20);
66
- const rangeValidator = date => {
67
- if (date < minDate) {
68
- return 'Date is before the allowable range.';
69
- }
70
- else if (date > maxDate) {
71
- return 'Date is after the allowable range.';
72
- }
73
-
74
- return '';
75
- };
76
- return <DatePicker value="2020-03-17" validators={[rangeValidator]} />;
77
- }
28
+ ```ts file="./DatePickerMinMax.tsx"
78
29
  ```
79
30
 
80
31
  ### French
81
32
 
82
- ```js
83
- import React from 'react';
84
- import { DatePicker, Weekday } from '@patternfly/react-core';
85
-
86
- FrenchMinMaxDate = () => {
87
- const minDate = new Date(2020, 2, 16);
88
- const maxDate = new Date(2020, 2, 20);
89
- const rangeValidator = date => {
90
- if (date < minDate) {
91
- return 'Cette date est antérieure à la première date valide.';
92
- }
93
- else if (date > maxDate) {
94
- return 'Cette date est postérieure à la dernière date valide.';
95
- }
96
-
97
- return '';
98
- };
99
- return (
100
- <DatePicker
101
- value="2020-03-17"
102
- validators={[rangeValidator]}
103
- placeholder="aaaa-mm-jj"
104
- invalidFormatText="Cette date est invalide."
105
- locale="fr"
106
- weekStart={Weekday.Monday}
107
- />
108
- );
109
- }
33
+ ```ts file="./DatePickerFrench.tsx"
110
34
  ```
111
35
 
112
36
  ### Controlled
113
37
 
114
- ```js
115
- import React from 'react';
116
- import { Button, DatePicker } from '@patternfly/react-core';
117
-
118
- ControlledDate = () => {
119
- const initialValue = '2020-03-17';
120
- const [value, setValue] = React.useState(initialValue);
121
- return (
122
- <React.Fragment>
123
- <Button onClick={() => setValue(initialValue)}>
124
- Reset date
125
- </Button>
126
- <DatePicker
127
- value={value}
128
- onChange={value => setValue(value)}
129
- />
130
- </React.Fragment>
131
- );
132
- }
38
+ ```ts file="./DatePickerControlled.tsx"
133
39
  ```
134
40
 
135
41
  ### Controlling the date picker calendar state
136
42
 
137
- ```js
138
- import React from 'react';
139
- import { Button, DatePicker } from '@patternfly/react-core';
140
-
141
- ControllingDatePicker = () => {
142
- const dateRef = React.useRef(null);
143
- const onClick = () => {
144
- if (dateRef.current) {
145
- dateRef.current.toggleCalendar()
146
- }
147
- };
148
- return (
149
- <React.Fragment>
150
- <Button onClick={onClick}>
151
- Toggle calendar
152
- </Button>
153
- <DatePicker ref={ dateRef } />
154
- </React.Fragment>
155
- );
156
- }
43
+ ```ts file="./DatePickerControlledCalendar.tsx"
157
44
  ```
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { DatePicker } from '@patternfly/react-core';
3
+
4
+ export const DatePickerAmerican: React.FunctionComponent = () => {
5
+ const dateFormat = (date: Date) =>
6
+ date.toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-');
7
+ const dateParse = (date: string) => {
8
+ const split = date.split('-');
9
+ if (split.length !== 3) {
10
+ return new Date();
11
+ }
12
+ const month = split[0];
13
+ const day = split[1];
14
+ const year = split[2];
15
+ return new Date(`${year.padStart(4, '0')}-${month.padStart(2, '0')}-${day.padStart(2, '0')}T00:00:00`);
16
+ };
17
+
18
+ return <DatePicker value="03-05-2020" placeholder="MM-DD-YYYY" dateFormat={dateFormat} dateParse={dateParse} />;
19
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { DatePicker } from '@patternfly/react-core';
3
+
4
+ export const DatePickerBasic: React.FunctionComponent = () => (
5
+ <DatePicker
6
+ // eslint-disable-next-line no-console
7
+ onBlur={(str, date) => console.log('onBlur', str, date)}
8
+ // eslint-disable-next-line no-console
9
+ onChange={(str, date) => console.log('onChange', str, date)}
10
+ />
11
+ );
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { Button, DatePicker } from '@patternfly/react-core';
3
+
4
+ export const DatePickerControlled: React.FunctionComponent = () => {
5
+ const initialValue = '2020-03-17';
6
+ const [value, setValue] = React.useState(initialValue);
7
+ return (
8
+ <React.Fragment>
9
+ <Button onClick={() => setValue(initialValue)}>Reset date</Button>
10
+ <DatePicker value={value} onChange={value => setValue(value)} />
11
+ </React.Fragment>
12
+ );
13
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { Button, DatePicker } from '@patternfly/react-core';
3
+
4
+ export const DatePickerControlledCalendar: React.FunctionComponent = () => {
5
+ const dateRef = React.useRef(null);
6
+ const onClick = () => {
7
+ if (dateRef.current) {
8
+ dateRef.current.toggleCalendar();
9
+ }
10
+ };
11
+ return (
12
+ <React.Fragment>
13
+ <Button onClick={onClick}>Toggle calendar</Button>
14
+ <DatePicker ref={dateRef} />
15
+ </React.Fragment>
16
+ );
17
+ };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { DatePicker, Weekday } from '@patternfly/react-core';
3
+
4
+ export const DatePickerFrench: React.FunctionComponent = () => {
5
+ const minDate = new Date(2020, 2, 16);
6
+ const maxDate = new Date(2020, 2, 20);
7
+ const rangeValidator = (date: Date) => {
8
+ if (date < minDate) {
9
+ return 'Cette date est antérieure à la première date valide.';
10
+ } else if (date > maxDate) {
11
+ return 'Cette date est postérieure à la dernière date valide.';
12
+ }
13
+
14
+ return '';
15
+ };
16
+ return (
17
+ <DatePicker
18
+ value="2020-03-17"
19
+ validators={[rangeValidator]}
20
+ placeholder="aaaa-mm-jj"
21
+ invalidFormatText="Cette date est invalide."
22
+ locale="fr"
23
+ weekStart={Weekday.Monday}
24
+ />
25
+ );
26
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { DatePicker } from '@patternfly/react-core';
3
+
4
+ export const DatePickerHelperText: React.FunctionComponent = () => (
5
+ <DatePicker value="2020-03-05" helperText="Select a date." />
6
+ );
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { DatePicker } from '@patternfly/react-core';
3
+
4
+ export const DatePickerMinMax: React.FunctionComponent = () => {
5
+ const minDate = new Date(2020, 2, 16);
6
+ const maxDate = new Date(2020, 2, 20);
7
+ const rangeValidator = (date: Date) => {
8
+ if (date < minDate) {
9
+ return 'Date is before the allowable range.';
10
+ } else if (date > maxDate) {
11
+ return 'Date is after the allowable range.';
12
+ }
13
+
14
+ return '';
15
+ };
16
+ return <DatePicker value="2020-03-17" validators={[rangeValidator]} />;
17
+ };
@@ -20,6 +20,8 @@ export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
20
20
  onMinus?: (event: React.MouseEvent, name?: string) => void;
21
21
  /** Callback for the text input changing */
22
22
  onChange?: (event: React.FormEvent<HTMLInputElement>) => void;
23
+ /** Callback function when text input is blurred (focus leaves) */
24
+ onBlur?: (event?: any) => void;
23
25
  /** Callback for the plus button */
24
26
  onPlus?: (event: React.MouseEvent, name?: string) => void;
25
27
  /** Adds the given unit to the number input */
@@ -66,6 +68,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
66
68
  isDisabled = false,
67
69
  onMinus = () => {},
68
70
  onChange,
71
+ onBlur,
69
72
  onPlus = () => {},
70
73
  unit,
71
74
  unitPosition = 'after',
@@ -116,6 +119,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
116
119
  aria-label={inputAriaLabel}
117
120
  {...(isDisabled && { disabled: isDisabled })}
118
121
  {...(onChange && { onChange })}
122
+ {...(onBlur && { onBlur })}
119
123
  {...(!onChange && { readOnly: true })}
120
124
  {...inputProps}
121
125
  onKeyDown={keyDownHandler}
@@ -447,6 +447,13 @@ class CustomStepNumberInput extends React.Component {
447
447
  };
448
448
 
449
449
  this.onChange = event => {
450
+ const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value);
451
+ this.setState({
452
+ value: newValue
453
+ });
454
+ };
455
+
456
+ this.onBlur = event => {
450
457
  const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value);
451
458
  this.setState({
452
459
  value: newValue > this.maxValue ? this.maxValue : newValue < this.minValue ? this.minValue : newValue
@@ -463,6 +470,7 @@ class CustomStepNumberInput extends React.Component {
463
470
  max={this.maxValue}
464
471
  onMinus={this.stepper(-3)}
465
472
  onChange={this.onChange}
473
+ onBlur={this.onBlur}
466
474
  onPlus={this.stepper(3)}
467
475
  inputName="input"
468
476
  inputAriaLabel="number input"