@patternfly/react-core 4.258.6 → 4.258.8

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 (30) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/esm/components/TimePicker/TimePicker.d.ts.map +1 -1
  3. package/dist/esm/components/TimePicker/TimePicker.js +15 -2
  4. package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
  5. package/dist/js/components/TimePicker/TimePicker.d.ts.map +1 -1
  6. package/dist/js/components/TimePicker/TimePicker.js +15 -2
  7. package/dist/js/components/TimePicker/TimePicker.js.map +1 -1
  8. package/dist/umd/react-core.min.js +1 -1
  9. package/package.json +2 -2
  10. package/src/components/TextArea/examples/TextArea.md +12 -260
  11. package/src/components/TextArea/examples/TextAreaAutoResizing.tsx +14 -0
  12. package/src/components/TextArea/examples/TextAreaBasic.tsx +7 -0
  13. package/src/components/TextArea/examples/TextAreaDisabled.tsx +6 -0
  14. package/src/components/TextArea/examples/TextAreaHorizontallyResizable.tsx +14 -0
  15. package/src/components/TextArea/examples/TextAreaIconSprite.tsx +41 -0
  16. package/src/components/TextArea/examples/TextAreaInvalid.tsx +15 -0
  17. package/src/components/TextArea/examples/TextAreaReadOnly.tsx +25 -0
  18. package/src/components/TextArea/examples/TextAreaUncontrolled.tsx +6 -0
  19. package/src/components/TextArea/examples/TextAreaValidated.tsx +52 -0
  20. package/src/components/TextArea/examples/TextAreaVerticallyResizable.tsx +14 -0
  21. package/src/components/TimePicker/TimePicker.tsx +18 -2
  22. package/src/components/TimePicker/__tests__/TimePicker.test.tsx +8 -5
  23. package/src/components/ToggleGroup/examples/ToggleGroup.md +5 -191
  24. package/src/components/ToggleGroup/examples/ToggleGroupCompact.tsx +30 -0
  25. package/src/components/ToggleGroup/examples/ToggleGroupDefaultMultiple.tsx +43 -0
  26. package/src/components/ToggleGroup/examples/ToggleGroupDefaultSingle.tsx +32 -0
  27. package/src/components/ToggleGroup/examples/ToggleGroupIcon.tsx +42 -0
  28. package/src/components/ToggleGroup/examples/ToggleGroupTextIcon.tsx +42 -0
  29. package/src/demos/Card/Card.md +3 -2
  30. package/src/demos/PrimaryDetail.md +4 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.258.6",
3
+ "version": "4.258.8",
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": "418db80c9d90e4a39bac9b24c7869a9ab7d985f5"
73
+ "gitHead": "caf942ac339aec701ec15dfc6cb48d4859b7c3e4"
74
74
  }
@@ -9,300 +9,52 @@ propComponents: ['TextArea']
9
9
 
10
10
  ### Basic
11
11
 
12
- ```js
13
- import React from 'react';
14
- import { TextArea } from '@patternfly/react-core';
15
-
16
- class SimpleTextArea extends React.Component {
17
- constructor(props) {
18
- super(props);
19
- this.state = {
20
- value: ''
21
- };
22
-
23
- this.handleTextAreaChange = value => {
24
- this.setState({ value });
25
- };
26
- }
27
-
28
- render() {
29
- const { value } = this.state;
30
-
31
- return <TextArea value={value} onChange={this.handleTextAreaChange} aria-label="text area example" />;
32
- }
33
- }
12
+ ```ts file="./TextAreaBasic.tsx"
34
13
  ```
35
14
 
36
15
  ### Invalid
37
16
 
38
- ```js
39
- import React from 'react';
40
- import { TextArea } from '@patternfly/react-core';
41
-
42
- class InvalidTextArea extends React.Component {
43
- constructor(props) {
44
- super(props);
45
- this.state = {
46
- value: ''
47
- };
48
-
49
- this.handleInvalidTextAreaChange = value => {
50
- this.setState({ value });
51
- };
52
- }
53
-
54
- render() {
55
- const { value } = this.state;
56
-
57
- return (
58
- <TextArea
59
- value={value}
60
- onChange={this.handleInvalidTextAreaChange}
61
- isRequired
62
- validated={'error'}
63
- aria-label="invalid text area example"
64
- />
65
- );
66
- }
67
- }
17
+ ```ts file="./TextAreaInvalid.tsx"
68
18
  ```
69
19
 
70
20
  ### Validated
71
21
 
72
- ```js
73
- import React from 'react';
74
- import { Form, FormGroup, TextArea } from '@patternfly/react-core';
75
-
76
- class InvalidTextArea extends React.Component {
77
- constructor(props) {
78
- super(props);
79
- this.state = {
80
- value: '',
81
- invalidText: 'You must have something to say',
82
- validated: 'default',
83
- helperText: 'Share your thoughts.'
84
- };
85
-
86
- this.simulateNetworkCall = callback => {
87
- setTimeout(callback, 2000);
88
- };
89
-
90
- this.handleTextAreaChange = value => {
91
- this.setState(
92
- {
93
- value,
94
- validated: 'default',
95
- helperText: 'Validating...'
96
- },
97
- this.simulateNetworkCall(() => {
98
- if (value && value.length > 0) {
99
- if (value.length >= 10) {
100
- this.setState({ validated: 'success', helperText: 'Thanks for your comments!' });
101
- } else {
102
- this.setState({
103
- validated: 'error',
104
- invalidText: 'Your being too brief, please enter at least 10 characters.'
105
- });
106
- }
107
- } else {
108
- this.setState({ validated: 'warning', helperText: 'You must have something to say' });
109
- }
110
- })
111
- );
112
- };
113
- }
114
-
115
- render() {
116
- const { value, validated, helperText, invalidText } = this.state;
117
-
118
- return (
119
- <Form>
120
- <FormGroup
121
- label="Comments:"
122
- type="string"
123
- helperText={helperText}
124
- helperTextInvalid={invalidText}
125
- fieldId="selection"
126
- validated={validated}
127
- >
128
- <TextArea
129
- value={value}
130
- onChange={this.handleTextAreaChange}
131
- isRequired
132
- validated={validated}
133
- aria-label="invalid text area example"
134
- />
135
- </FormGroup>
136
- </Form>
137
- );
138
- }
139
- }
22
+ ```ts file="./TextAreaValidated.tsx"
140
23
  ```
141
24
 
142
- ### Vertically resizable text area
143
-
144
- ```js
145
- import React from 'react';
146
- import { TextArea } from '@patternfly/react-core';
25
+ ### Vertically resizable
147
26
 
148
- class VerticalResizeTextArea extends React.Component {
149
- constructor(props) {
150
- super(props);
151
- this.state = {
152
- value: ''
153
- };
154
-
155
- this.handleTextAreaChange = value => {
156
- this.setState({ value });
157
- };
158
- }
159
-
160
- render() {
161
- const { value } = this.state;
162
-
163
- return (
164
- <TextArea
165
- value={value}
166
- onChange={this.handleTextAreaChange}
167
- resizeOrientation="vertical"
168
- aria-label="text vertical resize example"
169
- />
170
- );
171
- }
172
- }
27
+ ```ts file="./TextAreaVerticallyResizable.tsx"
173
28
  ```
174
29
 
175
- ### Horizontally resizable text area
176
-
177
- ```js
178
- import React from 'react';
179
- import { TextArea } from '@patternfly/react-core';
180
-
181
- class HorizontalResizeTextArea extends React.Component {
182
- constructor(props) {
183
- super(props);
184
- this.state = {
185
- value: ''
186
- };
187
-
188
- this.handleTextAreaChange = value => {
189
- this.setState({ value });
190
- };
191
- }
192
-
193
- render() {
194
- const { value } = this.state;
30
+ ### Horizontally resizable
195
31
 
196
- return (
197
- <TextArea
198
- value={value}
199
- onChange={this.handleTextAreaChange}
200
- resizeOrientation="horizontal"
201
- aria-label="text horizontal resize example"
202
- />
203
- );
204
- }
205
- }
32
+ ```ts file="./TextAreaHorizontallyResizable.tsx"
206
33
  ```
207
34
 
208
35
  ### Uncontrolled
209
36
 
210
- ```js
211
- import React from 'react';
212
- import { TextArea } from '@patternfly/react-core';
213
-
214
- <TextArea defaultValue="default value" aria-label="uncontrolled text area example" />;
37
+ ```ts file="./TextAreaUncontrolled.tsx"
215
38
  ```
216
39
 
217
40
  ### Disabled
218
41
 
219
- ```js
220
- import React from 'react';
221
- import { TextArea } from '@patternfly/react-core';
222
-
223
- <TextArea aria-label="disabled text area example" isDisabled />;
42
+ ```ts file="./TextAreaDisabled.tsx"
224
43
  ```
225
44
 
226
45
  ### Read only
227
46
 
228
- ```js
229
- import React from 'react';
230
- import { Checkbox, TextArea } from '@patternfly/react-core';
231
-
232
- const ReadOnlyTextArea = () => {
233
- const [isPlainChecked, setIsPlainChecked] = React.useState(false);
234
-
235
- return (
236
- <React.Fragment>
237
- <div style={{ marginBottom: '12px' }}>
238
- <Checkbox
239
- id="isPlain"
240
- key="isPlain"
241
- label="Plain read only variant"
242
- isChecked={isPlainChecked}
243
- onChange={checked => setIsPlainChecked(checked)}
244
- />
245
- </div>
246
- <TextArea
247
- aria-label="read only text area example"
248
- value="read only text area example"
249
- readOnlyVariant={isPlainChecked ? 'plain' : 'default'}
250
- />
251
- </React.Fragment>
252
- );
253
- };
47
+ ```ts file="./TextAreaReadOnly.tsx"
254
48
  ```
255
49
 
256
50
  ### Auto resizing
257
51
 
258
- ```js
259
- import React from 'react';
260
- import { TextArea } from '@patternfly/react-core';
261
-
262
- <TextArea aria-label="auto resizing text area example" autoResize />;
52
+ ```ts file="./TextAreaAutoResizing.tsx"
263
53
  ```
264
54
 
265
55
  ### Icon sprite variants
266
56
 
267
57
  **Note:** The icons for the success, invalid, calendar, etc. variations in form control elements are applied as background images to the form element. By default, the image URLs for these icons are data URIs. However, there may be cases where data URIs are not ideal, such as in an application with a content security policy that disallows data URIs for security reasons. The `isIconSprite` variation changes the icon source to an external SVG file that serves as a sprite for all of the supported icons.
268
58
 
269
- ```js
270
- import React from 'react';
271
- import { TextArea } from '@patternfly/react-core';
272
-
273
- IconSpriteTextArea = () => {
274
- const [success, setSuccess] = React.useState('');
275
- const [warning, setWarning] = React.useState('');
276
- const [error, setError] = React.useState('');
277
-
278
- return (
279
- <>
280
- <TextArea
281
- validated={ValidatedOptions.success}
282
- isIconSprite
283
- type="text"
284
- onChange={value => setSuccess(value)}
285
- aria-label="success icon sprite text area example"
286
- />
287
- <br />
288
- <br />
289
- <TextArea
290
- validated={ValidatedOptions.warning}
291
- isIconSprite
292
- type="text"
293
- onChange={value => setWarning(value)}
294
- aria-label="warning icon sprite text input example"
295
- />
296
- <br />
297
- <br />
298
- <TextArea
299
- validated={ValidatedOptions.error}
300
- isIconSprite
301
- type="text"
302
- onChange={value => setError(value)}
303
- aria-label="error icon sprite text area example"
304
- />
305
- </>
306
- );
307
- };
59
+ ```ts isBeta file="./TextAreaIconSprite.tsx"
308
60
  ```
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaAutoResizing: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ return (
7
+ <TextArea
8
+ value={value}
9
+ onChange={value => setValue(value)}
10
+ aria-label="auto resizing text area example"
11
+ autoResize
12
+ />
13
+ );
14
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaBasic: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ return <TextArea value={value} onChange={value => setValue(value)} aria-label="text area example" />;
7
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaDisabled: React.FunctionComponent = () => (
5
+ <TextArea aria-label="disabled text area example" isDisabled />
6
+ );
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaHorizontallyResizable: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ return (
7
+ <TextArea
8
+ value={value}
9
+ onChange={value => setValue(value)}
10
+ resizeOrientation="horizontal"
11
+ aria-label="text area horizontal resize example"
12
+ />
13
+ );
14
+ };
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaIconSprite: React.FunctionComponent = () => {
5
+ const [success, setSuccess] = React.useState('');
6
+ const [warning, setWarning] = React.useState('');
7
+ const [error, setError] = React.useState('');
8
+
9
+ return (
10
+ <>
11
+ <TextArea
12
+ validated={'success'}
13
+ isIconSprite
14
+ type="text"
15
+ onChange={value => setSuccess(value)}
16
+ value={success}
17
+ aria-label="success icon sprite text area example"
18
+ />
19
+ <br />
20
+ <br />
21
+ <TextArea
22
+ validated={'warning'}
23
+ isIconSprite
24
+ type="text"
25
+ onChange={value => setWarning(value)}
26
+ value={warning}
27
+ aria-label="warning icon sprite text area example"
28
+ />
29
+ <br />
30
+ <br />
31
+ <TextArea
32
+ validated={'error'}
33
+ isIconSprite
34
+ type="text"
35
+ onChange={value => setError(value)}
36
+ value={error}
37
+ aria-label="error icon sprite text area example"
38
+ />
39
+ </>
40
+ );
41
+ };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaInvalid: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ return (
7
+ <TextArea
8
+ value={value}
9
+ onChange={value => setValue(value)}
10
+ isRequired
11
+ validated={'error'}
12
+ aria-label="invalid text area example"
13
+ />
14
+ );
15
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { Checkbox, TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaReadOnly: React.FunctionComponent = () => {
5
+ const [isPlainChecked, setIsPlainChecked] = React.useState(false);
6
+
7
+ return (
8
+ <React.Fragment>
9
+ <div style={{ marginBottom: '12px' }}>
10
+ <Checkbox
11
+ id="isPlain"
12
+ key="isPlain"
13
+ label="Plain read only variant"
14
+ isChecked={isPlainChecked}
15
+ onChange={checked => setIsPlainChecked(checked)}
16
+ />
17
+ </div>
18
+ <TextArea
19
+ aria-label="read only text area example"
20
+ value="read only text area example"
21
+ readOnlyVariant={isPlainChecked ? 'plain' : 'default'}
22
+ />
23
+ </React.Fragment>
24
+ );
25
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaUncontrolled: React.FunctionComponent = () => (
5
+ <TextArea defaultValue="default value" aria-label="uncontrolled text area example" />
6
+ );
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { Form, FormGroup, TextArea } from '@patternfly/react-core';
3
+
4
+ export const TextAreaValidated: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ const [invalidText, setInvalidText] = React.useState('You must have something to say');
7
+ const [validated, setValidated] = React.useState<'default' | 'error' | 'warning' | 'success' | undefined>('default');
8
+ const [helperText, setHelperText] = React.useState('Share your thoughts.');
9
+ const simulateNetworkCall = (callback: Function) => {
10
+ setTimeout(callback, 2000);
11
+ };
12
+
13
+ const handleTextAreaChange = (value: string) => {
14
+ setValue(value);
15
+ setValidated('default');
16
+ setHelperText('Validating...');
17
+ simulateNetworkCall(() => {
18
+ if (value.length > 0) {
19
+ if (value.length >= 10) {
20
+ setValidated('success');
21
+ setHelperText('Thanks for your comments!');
22
+ } else {
23
+ setValidated('error');
24
+ setInvalidText("You're being too brief, please enter at least 10 characters.");
25
+ }
26
+ } else {
27
+ setValidated('warning');
28
+ setHelperText('You must have something to say');
29
+ }
30
+ });
31
+ };
32
+ return (
33
+ <Form>
34
+ <FormGroup
35
+ label="Comments:"
36
+ type="string"
37
+ helperText={helperText}
38
+ helperTextInvalid={invalidText}
39
+ fieldId="selection"
40
+ validated={validated}
41
+ >
42
+ <TextArea
43
+ value={value}
44
+ onChange={value => handleTextAreaChange(value)}
45
+ isRequired
46
+ validated={validated}
47
+ aria-label="invalid text area example"
48
+ />
49
+ </FormGroup>
50
+ </Form>
51
+ );
52
+ };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { TextArea } from '@patternfly/react-core';
3
+
4
+ export const VerticalResizeTextArea: React.FunctionComponent = () => {
5
+ const [value, setValue] = React.useState('');
6
+ return (
7
+ <TextArea
8
+ value={value}
9
+ onChange={value => setValue(value)}
10
+ resizeOrientation="vertical"
11
+ aria-label="text area vertical resize example"
12
+ />
13
+ );
14
+ };
@@ -143,6 +143,8 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
143
143
  document.addEventListener('mousedown', this.onDocClick);
144
144
  document.addEventListener('touchstart', this.onDocClick);
145
145
  document.addEventListener('keydown', this.handleGlobalKeys);
146
+
147
+ this.setState({ isInvalid: !this.isValid(this.state.timeState) });
146
148
  }
147
149
 
148
150
  componentWillUnmount() {
@@ -198,7 +200,7 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
198
200
 
199
201
  componentDidUpdate(prevProps: TimePickerProps, prevState: TimePickerState) {
200
202
  const { timeState, isTimeOptionsOpen, isInvalid, timeRegex } = this.state;
201
- const { time, is24Hour, delimiter, includeSeconds, isOpen } = this.props;
203
+ const { time, is24Hour, delimiter, includeSeconds, isOpen, minTime, maxTime } = this.props;
202
204
  if (prevProps.isOpen !== isOpen) {
203
205
  this.onToggle(isOpen);
204
206
  }
@@ -212,8 +214,22 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
212
214
  });
213
215
  }
214
216
  if (time !== '' && time !== prevProps.time) {
217
+ const parsedTime = parseTime(time, timeRegex, delimiter, !is24Hour, includeSeconds);
218
+
219
+ this.setState({
220
+ timeState: parsedTime,
221
+ isInvalid: !this.isValid(parsedTime)
222
+ });
223
+ }
224
+ if (minTime !== '' && minTime !== prevProps.minTime) {
225
+ this.setState({
226
+ minTimeState: parseTime(minTime, timeRegex, delimiter, !is24Hour, includeSeconds)
227
+ });
228
+ }
229
+
230
+ if (maxTime !== '' && maxTime !== prevProps.maxTime) {
215
231
  this.setState({
216
- timeState: parseTime(time, timeRegex, delimiter, !is24Hour, includeSeconds)
232
+ maxTimeState: parseTime(maxTime, timeRegex, delimiter, !is24Hour, includeSeconds)
217
233
  });
218
234
  }
219
235
  }
@@ -107,24 +107,27 @@ describe('TimePicker', () => {
107
107
  });
108
108
 
109
109
  test('should be invalid after onBlur', async () => {
110
- const validateTime = (_time: string) => {
111
- return false;
112
- };
113
110
  const user = userEvent.setup();
114
111
 
115
112
  render(
116
113
  <>
117
114
  <div>Other element</div>
118
- <TimePicker value={'00:00'} validateTime={validateTime} aria-label="time picker" />
115
+ <TimePicker value={'00:00'} aria-label="time picker" />
119
116
  </>
120
117
  );
121
118
 
122
- await user.type(screen.getByLabelText('time picker'), '01:00');
119
+ await user.type(screen.getByLabelText('time picker'), '14:00');
123
120
  expect(screen.queryByText('Invalid time format')).toBeNull();
124
121
 
125
122
  await user.click(screen.getByText('Other element'));
126
123
  expect(screen.getByText('Invalid time format')).toBeInTheDocument();
127
124
  });
125
+
126
+ test('should be invalid when invalid time prop is passed', () => {
127
+ render(<TimePicker time="00:00" aria-label="time picker" />);
128
+
129
+ expect(screen.getByText('Invalid time format')).toBeInTheDocument();
130
+ });
128
131
  });
129
132
 
130
133
  describe('test includeSeconds', () => {