@patternfly/react-core 4.258.7 → 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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.258.8](https://github.com/patternfly/patternfly-react/compare/@patternfly/react-core@4.258.7...@patternfly/react-core@4.258.8) (2022-11-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **bulk-select:** fixed toggle spacing ([#8326](https://github.com/patternfly/patternfly-react/issues/8326)) ([fe40f19](https://github.com/patternfly/patternfly-react/commit/fe40f19058a383cfc12e3f7a07d07af8dc579d04))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [4.258.7](https://github.com/patternfly/patternfly-react/compare/@patternfly/react-core@4.258.6...@patternfly/react-core@4.258.7) (2022-11-07)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.258.7",
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": "69c78cfc668577eb1b005710b0c77522cbabe9c6"
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
+ };
@@ -14,207 +14,21 @@ import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square
14
14
  ## Examples
15
15
 
16
16
  ### Default with multiple selectable
17
- ```js
18
- import React from 'react';
19
- import { ToggleGroup, ToggleGroupItem, Button, Stack, StackItem } from '@patternfly/react-core';
20
-
21
- class DefaultToggleGroupExample extends React.Component {
22
- constructor(props) {
23
- super(props);
24
- this.state = {
25
- isSelected: {
26
- first: false,
27
- second: false,
28
- disableAll: false
29
- }
30
- };
31
- this.handleItemClick = (isSelected, event) => {
32
- const id = event.currentTarget.id;
33
- this.setState(prevState => {
34
- prevState.isSelected[id] = isSelected;
35
- return {
36
- isSelected: prevState.isSelected
37
- };
38
- });
39
- };
40
- this.disableAllClick = () => {
41
- this.setState(prevState => ({ disableAll: !prevState.disableAll }));
42
- };
43
- }
44
-
45
- render() {
46
- const { isSelected } = this.state;
47
-
48
- return (
49
- <Stack hasGutter>
50
- <StackItem>
51
- <Button onClick={this.disableAllClick}>
52
- {this.state.disableAll ? "Enable back" : "Disable all"}
53
- </Button>
54
- </StackItem>
55
- <StackItem>
56
- <ToggleGroup areAllGroupsDisabled={this.state.disableAll} aria-label="Default with multiple selectable">
57
- <ToggleGroupItem text="Option 1" key={0} buttonId="first" isSelected={isSelected.first} onChange={this.handleItemClick} />
58
- <ToggleGroupItem text="Option 2" key={1} buttonId="second" isSelected={isSelected.second} onChange={this.handleItemClick} />
59
- <ToggleGroupItem text="Option 3" key={2} isDisabled/>
60
- </ToggleGroup>
61
- </StackItem>
62
- </Stack>
63
- );
64
- }
65
- }
17
+ ```ts file="./ToggleGroupDefaultMultiple.tsx"
66
18
  ```
67
19
 
68
20
  ### Default with single selectable
69
- ```js
70
- import React from 'react';
71
- import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
72
-
73
- class DefaultAsRadioToggleGroupExample extends React.Component {
74
- constructor(props) {
75
- super(props);
76
- this.state = {
77
- isSelected: ""
78
- };
79
- this.handleItemClick = (isSelected, event) => {
80
- const id = event.currentTarget.id;
81
- this.setState({ isSelected: id });
82
- };
83
- }
84
-
85
- render() {
86
- const { isSelected } = this.state;
87
-
88
- return (
89
- <ToggleGroup aria-label="Default with single selectable">
90
- <ToggleGroupItem text="Option 1" buttonId="firstRadio" isSelected={isSelected === "firstRadio"} onChange={this.handleItemClick} />
91
- <ToggleGroupItem text="Option 2" buttonId="secondRadio" isSelected={isSelected === "secondRadio"} onChange={this.handleItemClick} />
92
- <ToggleGroupItem text="Option 3" buttonId="thirdRadio" isSelected={isSelected === "thirdRadio"} onChange={this.handleItemClick} />
93
- </ToggleGroup>
94
- );
95
- }
96
- }
21
+ ```ts file="./ToggleGroupDefaultSingle.tsx"
97
22
  ```
98
23
 
99
24
  ### Icons
100
- ```js
101
- import React from 'react';
102
- import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
103
- import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon';
104
- import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon';
105
- import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon';
106
-
107
- class IconToggleGroupExample extends React.Component {
108
- constructor(props) {
109
- super(props);
110
- this.state = {
111
- isSelected: {
112
- "icons-1": false,
113
- "icons-2": false,
114
- "icons-3": true
115
- }
116
- };
117
- this.handleItemClick = (isSelected, event) => {
118
- const id = event.currentTarget.id;
119
- this.setState(prevState => {
120
- prevState.isSelected[id] = isSelected;
121
- return {
122
- isSelected: prevState.isSelected
123
- };
124
- });
125
- };
126
- }
127
-
128
- render() {
129
- const { isSelected } = this.state;
130
- return (
131
- <ToggleGroup aria-label="Icon variant toggle group">
132
- <ToggleGroupItem icon={<CopyIcon />} aria-label="copy icon button" buttonId="icons-1" isSelected={isSelected["icons-1"]} onChange={this.handleItemClick} />
133
- <ToggleGroupItem icon={<UndoIcon />} aria-label="undo icon button" buttonId="icons-2" isSelected={isSelected["icons-2"]} onChange={this.handleItemClick} />
134
- <ToggleGroupItem icon={<ShareSquareIcon />} aria-label="share square icon button" buttonId="icons-3" isSelected={isSelected["icons-3"]} onChange={this.handleItemClick} />
135
- </ToggleGroup>
136
- );
137
- }
138
- }
25
+ ```ts file="./ToggleGroupIcon.tsx"
139
26
  ```
140
27
 
141
28
  ### Text and icons
142
- ```js
143
- import React from 'react';
144
- import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
145
- import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon';
146
- import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon';
147
- import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon';
148
-
149
- class TextIconToggleGroupExample extends React.Component {
150
- constructor(props) {
151
- super(props);
152
- this.state = {
153
- isSelected: {
154
- "text-icons-1": false,
155
- "text-icons-2": false,
156
- "text-icons-3": true
157
- }
158
- };
159
- this.handleItemClick = (isSelected, event) => {
160
- const id = event.currentTarget.id;
161
- this.setState(prevState => {
162
- prevState.isSelected[id] = isSelected;
163
- return {
164
- isSelected: prevState.isSelected
165
- };
166
- });
167
- };
168
- }
169
-
170
- render() {
171
- const { isSelected } = this.state;
172
- return (
173
- <ToggleGroup aria-label="Icon variant toggle group">
174
- <ToggleGroupItem icon={<CopyIcon />} text="Copy" aria-label="copy icon button" buttonId="text-icons-1" isSelected={isSelected["text-icons-1"]} onChange={this.handleItemClick} />
175
- <ToggleGroupItem icon={<UndoIcon />} text="Undo" aria-label="undo icon button" buttonId="text-icons-2" isSelected={isSelected["text-icons-2"]} onChange={this.handleItemClick} />
176
- <ToggleGroupItem icon={<ShareSquareIcon />} text="Share" aria-label="share square icon button" buttonId="text-icons-3" isSelected={isSelected["text-icons-3"]} onChange={this.handleItemClick} />
177
- </ToggleGroup>
178
- );
179
- }
180
- }
29
+ ```ts file="./ToggleGroupTextIcon.tsx"
181
30
  ```
182
31
 
183
32
  ### Compact variant
184
- ```js
185
- import React from 'react';
186
- import { ToggleGroup, ToggleGroupItem, ToggleGroupVariant } from '@patternfly/react-core';
187
-
188
- class CompactToggleGroupExample extends React.Component {
189
- constructor(props) {
190
- super(props);
191
- this.state = {
192
- isSelected: {
193
- "compact-1": false,
194
- "compact-2": false
195
- }
196
- };
197
- this.handleItemClick = (isSelected, event) => {
198
- const id = event.currentTarget.id;
199
- this.setState(prevState => {
200
- prevState.isSelected[id] = isSelected;
201
- return {
202
- isSelected: prevState.isSelected
203
- };
204
- });
205
- };
206
- }
207
-
208
- render() {
209
- const { isSelected } = this.state;
210
-
211
- return (
212
- <ToggleGroup isCompact aria-label="Compact variant toggle group">
213
- <ToggleGroupItem text="Option 1" buttonId="compact-1" isSelected={isSelected["compact-1"]} onChange={this.handleItemClick} />
214
- <ToggleGroupItem text="Option 2" buttonId="compact-2" isSelected={isSelected["compact-2"]} onChange={this.handleItemClick} />
215
- <ToggleGroupItem text="Option 3" isDisabled />
216
- </ToggleGroup>
217
- );
218
- }
219
- }
33
+ ```ts file="./ToggleGroupCompact.tsx"
220
34
  ```
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
3
+
4
+ export const ToggleGroupCompact: React.FunctionComponent = () => {
5
+ const [isSelected, setIsSelected] = React.useState({
6
+ 'toggle-group-compact-1': false,
7
+ 'toggle-group-compact-2': false
8
+ });
9
+ const handleItemClick = (isSelected: boolean, event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
10
+ const id = event.currentTarget.id;
11
+ setIsSelected(prevIsSelected => ({ ...prevIsSelected, [id]: isSelected }));
12
+ };
13
+ return (
14
+ <ToggleGroup isCompact aria-label="Compact variant toggle group">
15
+ <ToggleGroupItem
16
+ text="Option 1"
17
+ buttonId="toggle-group-compact-1"
18
+ isSelected={isSelected['toggle-group-compact-1']}
19
+ onChange={handleItemClick}
20
+ />
21
+ <ToggleGroupItem
22
+ text="Option 2"
23
+ buttonId="toggle-group-compact-2"
24
+ isSelected={isSelected['toggle-group-compact-2']}
25
+ onChange={handleItemClick}
26
+ />
27
+ <ToggleGroupItem text="Option 3" isDisabled />
28
+ </ToggleGroup>
29
+ );
30
+ };
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { ToggleGroup, ToggleGroupItem, Button, Stack, StackItem } from '@patternfly/react-core';
3
+
4
+ export const ToggleGroupDefaultMultiple: React.FunctionComponent = () => {
5
+ const [isSelected, setIsSelected] = React.useState({
6
+ 'toggle-group-multiple-1': false,
7
+ 'toggle-group-multiple-2': false
8
+ });
9
+ const [disableAll, setDisableAll] = React.useState(false);
10
+ const handleItemClick = (isSelected: boolean, event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
11
+ const id = event.currentTarget.id;
12
+ setIsSelected(prevIsSelected => ({ ...prevIsSelected, [id]: isSelected }));
13
+ };
14
+ const disableAllClick = () => {
15
+ setDisableAll(!disableAll);
16
+ };
17
+ return (
18
+ <Stack hasGutter>
19
+ <StackItem>
20
+ <Button onClick={disableAllClick}>{disableAll ? 'Enable back' : 'Disable all'}</Button>
21
+ </StackItem>
22
+ <StackItem>
23
+ <ToggleGroup areAllGroupsDisabled={disableAll} aria-label="Default with multiple selectable">
24
+ <ToggleGroupItem
25
+ text="Option 1"
26
+ key={0}
27
+ buttonId="toggle-group-multiple-1"
28
+ isSelected={isSelected['toggle-group-multiple-1']}
29
+ onChange={handleItemClick}
30
+ />
31
+ <ToggleGroupItem
32
+ text="Option 2"
33
+ key={1}
34
+ buttonId="toggle-group-multiple-2"
35
+ isSelected={isSelected['toggle-group-multiple-2']}
36
+ onChange={handleItemClick}
37
+ />
38
+ <ToggleGroupItem text="Option 3" key={2} isDisabled />
39
+ </ToggleGroup>
40
+ </StackItem>
41
+ </Stack>
42
+ );
43
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
3
+
4
+ export const ToggleGroupDefaultSingle: React.FunctionComponent = () => {
5
+ const [isSelected, setIsSelected] = React.useState('');
6
+ const handleItemClick = (isSelected: boolean, event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
7
+ const id = event.currentTarget.id;
8
+ setIsSelected(id);
9
+ };
10
+ return (
11
+ <ToggleGroup aria-label="Default with single selectable">
12
+ <ToggleGroupItem
13
+ text="Option 1"
14
+ buttonId="toggle-group-single-1"
15
+ isSelected={isSelected === 'toggle-group-single-1'}
16
+ onChange={handleItemClick}
17
+ />
18
+ <ToggleGroupItem
19
+ text="Option 2"
20
+ buttonId="toggle-group-single-2"
21
+ isSelected={isSelected === 'toggle-group-single-2'}
22
+ onChange={handleItemClick}
23
+ />
24
+ <ToggleGroupItem
25
+ text="Option 3"
26
+ buttonId="toggle-group-single-3"
27
+ isSelected={isSelected === 'toggle-group-single-3'}
28
+ onChange={handleItemClick}
29
+ />
30
+ </ToggleGroup>
31
+ );
32
+ };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
3
+ import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon';
4
+ import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon';
5
+ import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon';
6
+
7
+ export const ToggleGroupIcon: React.FunctionComponent = () => {
8
+ const [isSelected, setIsSelected] = React.useState({
9
+ 'toggle-group-icons-1': false,
10
+ 'toggle-group-icons-2': false,
11
+ 'toggle-group-icons-3': true
12
+ });
13
+ const handleItemClick = (isSelected: boolean, event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
14
+ const id = event.currentTarget.id;
15
+ setIsSelected(prevIsSelected => ({ ...prevIsSelected, [id]: isSelected }));
16
+ };
17
+ return (
18
+ <ToggleGroup aria-label="Icon variant toggle group">
19
+ <ToggleGroupItem
20
+ icon={<CopyIcon />}
21
+ aria-label="copy"
22
+ buttonId="toggle-group-icons-1"
23
+ isSelected={isSelected['toggle-group-icons-1']}
24
+ onChange={handleItemClick}
25
+ />
26
+ <ToggleGroupItem
27
+ icon={<UndoIcon />}
28
+ aria-label="undo"
29
+ buttonId="toggle-group-icons-2"
30
+ isSelected={isSelected['toggle-group-icons-2']}
31
+ onChange={handleItemClick}
32
+ />
33
+ <ToggleGroupItem
34
+ icon={<ShareSquareIcon />}
35
+ aria-label="share square"
36
+ buttonId="toggle-group-icons-3"
37
+ isSelected={isSelected['toggle-group-icons-3']}
38
+ onChange={handleItemClick}
39
+ />
40
+ </ToggleGroup>
41
+ );
42
+ };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
3
+ import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon';
4
+ import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon';
5
+ import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon';
6
+
7
+ export const ToggleGroupIcon: React.FunctionComponent = () => {
8
+ const [isSelected, setIsSelected] = React.useState({
9
+ 'text-icons-1': false,
10
+ 'text-icons-2': false,
11
+ 'text-icons-3': true
12
+ });
13
+ const handleItemClick = (isSelected: boolean, event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent) => {
14
+ const id = event.currentTarget.id;
15
+ setIsSelected(prevIsSelected => ({ ...prevIsSelected, [id]: isSelected }));
16
+ };
17
+ return (
18
+ <ToggleGroup aria-label="Text and icon toggle group">
19
+ <ToggleGroupItem
20
+ icon={<CopyIcon />}
21
+ text="Copy"
22
+ buttonId="toggle-group-text-icons-1"
23
+ isSelected={isSelected['toggle-group-text-icons-1']}
24
+ onChange={handleItemClick}
25
+ />
26
+ <ToggleGroupItem
27
+ icon={<UndoIcon />}
28
+ text="Undo"
29
+ buttonId="toggle-group-text-icons-2"
30
+ isSelected={isSelected['toggle-group-text-icons-2']}
31
+ onChange={handleItemClick}
32
+ />
33
+ <ToggleGroupItem
34
+ icon={<ShareSquareIcon />}
35
+ text="Share"
36
+ buttonId="toggle-group-text-icons-3"
37
+ isSelected={isSelected['toggle-group-text-icons-3']}
38
+ onChange={handleItemClick}
39
+ />
40
+ </ToggleGroup>
41
+ );
42
+ };
@@ -426,11 +426,12 @@ class CardViewBasic extends React.Component {
426
426
  aria-label={anySelected ? 'Deselect all' : 'Select all'}
427
427
  isChecked={areAllSelected}
428
428
  onClick={this.splitCheckboxSelectAll.bind(this)}
429
- ></DropdownToggleCheckbox>
429
+ >
430
+ {numSelected !== 0 && `${numSelected} selected`}
431
+ </DropdownToggleCheckbox>
430
432
  ]}
431
433
  onToggle={this.onSplitButtonToggle}
432
434
  >
433
- {numSelected !== 0 && <React.Fragment>{numSelected} selected</React.Fragment>}
434
435
  </DropdownToggle>
435
436
  }
436
437
  isOpen={splitButtonDropdownIsOpen}
@@ -1369,14 +1369,12 @@ class PrimaryDetailCardView extends React.Component {
1369
1369
  aria-label={anySelected ? 'Deselect all' : 'Select all'}
1370
1370
  isChecked={areAllSelected}
1371
1371
  onClick={this.splitCheckboxSelectAll}
1372
- ></DropdownToggleCheckbox>
1372
+ >
1373
+ {numSelected !== 0 && `${numSelected} selected`}
1374
+ </DropdownToggleCheckbox>
1373
1375
  ]}
1374
1376
  onToggle={this.onSplitButtonToggle}
1375
- >
1376
- {numSelected !== 0 && (
1377
- <React.Fragment>{allSelected ? this.state.totalItemCount : numSelected} selected</React.Fragment>
1378
- )}
1379
- </DropdownToggle>
1377
+ ></DropdownToggle>
1380
1378
  }
1381
1379
  isOpen={splitButtonDropdownIsOpen}
1382
1380
  dropdownItems={splitButtonDropdownItems}