@patternfly/react-core 4.221.13 → 4.221.16
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 +24 -0
- package/dist/esm/components/DualListSelector/DualListSelector.d.ts +4 -0
- package/dist/esm/components/DualListSelector/DualListSelector.d.ts.map +1 -1
- package/dist/esm/components/DualListSelector/DualListSelector.js +13 -2
- package/dist/esm/components/DualListSelector/DualListSelector.js.map +1 -1
- package/dist/js/components/DualListSelector/DualListSelector.d.ts +4 -0
- package/dist/js/components/DualListSelector/DualListSelector.d.ts.map +1 -1
- package/dist/js/components/DualListSelector/DualListSelector.js +13 -2
- package/dist/js/components/DualListSelector/DualListSelector.js.map +1 -1
- package/dist/umd/react-core.js +13 -2
- package/dist/umd/react-core.min.css +69 -69
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +5 -5
- package/src/components/DualListSelector/DualListSelector.tsx +14 -2
- package/src/components/DualListSelector/examples/DualListSelector.md +38 -767
- package/src/components/DualListSelector/examples/DualListSelectorBasic.tsx +26 -0
- package/src/components/DualListSelector/examples/DualListSelectorBasicSearch.tsx +27 -0
- package/src/components/DualListSelector/examples/DualListSelectorBasicTooltips.tsx +34 -0
- package/src/components/DualListSelector/examples/DualListSelectorComplexOptionsActions.tsx +146 -0
- package/src/components/DualListSelector/examples/DualListSelectorComposable.tsx +214 -0
- package/src/components/DualListSelector/examples/DualListSelectorComposableDragDrop.tsx +190 -0
- package/src/components/DualListSelector/examples/{ComposableTree.tsx → DualListSelectorComposableTree.tsx} +3 -3
- package/src/components/DualListSelector/examples/DualListSelectorTree.tsx +91 -0
- package/src/components/FileUpload/examples/FileUpload.md +6 -270
- package/src/components/FileUpload/examples/FileUploadCustomPreview.tsx +40 -0
- package/src/components/FileUpload/examples/FileUploadCustomUpload.tsx +116 -0
- package/src/components/FileUpload/examples/FileUploadSimpleFile.tsx +31 -0
- package/src/components/FileUpload/examples/FileUploadSimpleText.tsx +51 -0
- package/src/components/FileUpload/examples/FileUploadTextWithEdits.tsx +51 -0
- package/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx +71 -0
- package/src/components/FormSelect/examples/FormSelect.md +5 -291
- package/src/components/FormSelect/examples/FormSelectBasic.tsx +28 -0
- package/src/components/FormSelect/examples/FormSelectDisabled.tsx +28 -0
- package/src/components/FormSelect/examples/FormSelectGrouped.tsx +49 -0
- package/src/components/FormSelect/examples/FormSelectIconSpriteVariant.tsx +57 -0
- package/src/components/FormSelect/examples/FormSelectValidated.tsx +69 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileUpload, Form, FormGroup } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
|
|
5
|
+
const [value, setValue] = React.useState('');
|
|
6
|
+
const [filename, setFilename] = React.useState('');
|
|
7
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
8
|
+
const [isRejected, setIsRejected] = React.useState(false);
|
|
9
|
+
|
|
10
|
+
const handleFileInputChange = (
|
|
11
|
+
_event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLElement>,
|
|
12
|
+
file: File
|
|
13
|
+
) => {
|
|
14
|
+
setFilename(file.name);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const handleTextOrDataChange = (value: string) => {
|
|
18
|
+
setValue(value);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const handleClear = (_event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
22
|
+
setFilename('');
|
|
23
|
+
setValue('');
|
|
24
|
+
setIsRejected(false);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const handleFileRejected = (_rejectedFiles: File[], _event: React.DragEvent<HTMLElement>) => {
|
|
28
|
+
setIsRejected(true);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const handleFileReadStarted = (_fileHandle: File) => {
|
|
32
|
+
setIsLoading(true);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const handleFileReadFinished = (_fileHandle: File) => {
|
|
36
|
+
setIsLoading(false);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Form>
|
|
41
|
+
<FormGroup
|
|
42
|
+
fieldId="text-file-with-restrictions"
|
|
43
|
+
helperText="Upload a CSV file"
|
|
44
|
+
helperTextInvalid="Must be a CSV file no larger than 1 KB"
|
|
45
|
+
validated={isRejected ? 'error' : 'default'}
|
|
46
|
+
>
|
|
47
|
+
<FileUpload
|
|
48
|
+
id="text-file-with-restrictions"
|
|
49
|
+
type="text"
|
|
50
|
+
value={value}
|
|
51
|
+
filename={filename}
|
|
52
|
+
filenamePlaceholder="Drag and drop a file or upload one"
|
|
53
|
+
onFileInputChange={handleFileInputChange}
|
|
54
|
+
onDataChange={handleTextOrDataChange}
|
|
55
|
+
onTextChange={handleTextOrDataChange}
|
|
56
|
+
onReadStarted={handleFileReadStarted}
|
|
57
|
+
onReadFinished={handleFileReadFinished}
|
|
58
|
+
onClearClick={handleClear}
|
|
59
|
+
isLoading={isLoading}
|
|
60
|
+
dropzoneProps={{
|
|
61
|
+
accept: '.csv',
|
|
62
|
+
maxSize: 1024,
|
|
63
|
+
onDropRejected: handleFileRejected
|
|
64
|
+
}}
|
|
65
|
+
validated={isRejected ? 'error' : 'default'}
|
|
66
|
+
browseButtonText="Upload"
|
|
67
|
+
/>
|
|
68
|
+
</FormGroup>
|
|
69
|
+
</Form>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -9,310 +9,24 @@ ouia: true
|
|
|
9
9
|
## Examples
|
|
10
10
|
|
|
11
11
|
### Basic
|
|
12
|
-
```
|
|
13
|
-
import React from 'react';
|
|
14
|
-
import { FormSelect, FormSelectOption, FormSelectOptionGroup } from '@patternfly/react-core';
|
|
15
|
-
|
|
16
|
-
class FormSelectInput extends React.Component {
|
|
17
|
-
constructor(props) {
|
|
18
|
-
super(props);
|
|
19
|
-
this.state = {
|
|
20
|
-
value: 'mrs'
|
|
21
|
-
};
|
|
22
|
-
this.onChange = (value, event) => {
|
|
23
|
-
this.setState({ value });
|
|
24
|
-
};
|
|
25
|
-
this.options = [
|
|
26
|
-
{ value: 'please choose', label: 'Select one', disabled: true },
|
|
27
|
-
{ value: 'mr', label: 'Mr', disabled: false },
|
|
28
|
-
{ value: 'miss', label: 'Miss', disabled: false },
|
|
29
|
-
{ value: 'mrs', label: 'Mrs', disabled: false },
|
|
30
|
-
{ value: 'ms', label: 'Ms', disabled: false },
|
|
31
|
-
{ value: 'dr', label: 'Dr', disabled: false },
|
|
32
|
-
{ value: 'other', label: 'Other', disabled: false }
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
render() {
|
|
37
|
-
return (
|
|
38
|
-
<FormSelect value={this.state.value} onChange={this.onChange} aria-label="FormSelect Input">
|
|
39
|
-
{this.options.map((option, index) => (
|
|
40
|
-
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} />
|
|
41
|
-
))}
|
|
42
|
-
</FormSelect>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Invalid
|
|
49
|
-
```js
|
|
50
|
-
import React from 'react';
|
|
51
|
-
import { FormSelect, FormSelectOption, FormSelectOptionGroup, ValidatedOptions } from '@patternfly/react-core';
|
|
52
|
-
|
|
53
|
-
class FormSelectInputInvalid extends React.Component {
|
|
54
|
-
constructor(props) {
|
|
55
|
-
super(props);
|
|
56
|
-
this.state = {
|
|
57
|
-
value: '',
|
|
58
|
-
validated: ValidatedOptions.default
|
|
59
|
-
};
|
|
60
|
-
this.isEmpty = () => this.state.value !== '';
|
|
61
|
-
this.onChange = (value, event) => {
|
|
62
|
-
const validated = this.isEmpty() && ValidatedOptions.error
|
|
63
|
-
this.setState({ value, validated });
|
|
64
|
-
};
|
|
65
|
-
this.options = [
|
|
66
|
-
{ value: '', label: 'Select a number', disabled: false, isPlaceholder: true },
|
|
67
|
-
{ value: '1', label: 'One', disabled: false, isPlaceholder: false },
|
|
68
|
-
{ value: '2', label: 'Two', disabled: false, isPlaceholder: false },
|
|
69
|
-
{ value: '3', label: 'Three', disabled: false, isPlaceholder: false }
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
render() {
|
|
74
|
-
const { value, validated } = this.state;
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<FormSelect
|
|
78
|
-
validated={validated}
|
|
79
|
-
value={value}
|
|
80
|
-
onChange={this.onChange}
|
|
81
|
-
aria-label="FormSelect Input"
|
|
82
|
-
>
|
|
83
|
-
{this.options.map((option, index) => (
|
|
84
|
-
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} isPlaceholder={option.isPlaceholder} />
|
|
85
|
-
))}
|
|
86
|
-
</FormSelect>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
12
|
+
```ts file='./FormSelectBasic.tsx'
|
|
90
13
|
```
|
|
91
14
|
|
|
92
15
|
### Validated
|
|
93
|
-
```
|
|
94
|
-
import React from 'react';
|
|
95
|
-
import { Form, FormGroup, FormSelect, FormSelectOption, FormSelectOptionGroup, ValidatedOptions } from '@patternfly/react-core';
|
|
96
|
-
|
|
97
|
-
class FormSelectInputInvalid extends React.Component {
|
|
98
|
-
constructor(props) {
|
|
99
|
-
super(props);
|
|
100
|
-
this.state = {
|
|
101
|
-
value: '',
|
|
102
|
-
invalidText: 'You must choose something',
|
|
103
|
-
validated: ValidatedOptions.default
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
this.simulateNetworkCall = callback => {
|
|
107
|
-
setTimeout(callback, 2000);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
this.onChange = (value, event) => {
|
|
111
|
-
this.setState(
|
|
112
|
-
{ value, validated: ValidatedOptions.default, helperText: 'Validating...' },
|
|
113
|
-
this.simulateNetworkCall(() => {
|
|
114
|
-
if (value === '3') {
|
|
115
|
-
this.setState({ validated: ValidatedOptions.success, helperText: 'You chose wisely' });
|
|
116
|
-
} else if (value === '') {
|
|
117
|
-
this.setState({ validated: ValidatedOptions.warning, helperText: 'You must select a value' });
|
|
118
|
-
} else {
|
|
119
|
-
this.setState({ validated: ValidatedOptions.error, invalidText: 'You must chose Three (thought that was obvious)' });
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
this.options = [
|
|
126
|
-
{ value: '', label: 'Select a number', disabled: false, isPlaceholder: true },
|
|
127
|
-
{ value: '1', label: 'One', disabled: false, isPlaceholder: false },
|
|
128
|
-
{ value: '2', label: 'Two', disabled: false, isPlaceholder: false },
|
|
129
|
-
{ value: '3', label: 'Three - the only valid option', disabled: false, isPlaceholder: false }
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
render() {
|
|
134
|
-
const { value, validated, helperText, invalidText } = this.state;
|
|
135
|
-
return (
|
|
136
|
-
<Form>
|
|
137
|
-
<FormGroup
|
|
138
|
-
label="Selection:"
|
|
139
|
-
type="string"
|
|
140
|
-
helperText={helperText}
|
|
141
|
-
helperTextInvalid={invalidText}
|
|
142
|
-
fieldId="selection"
|
|
143
|
-
validated={validated}
|
|
144
|
-
>
|
|
145
|
-
<FormSelect
|
|
146
|
-
id="selection"
|
|
147
|
-
validated={validated}
|
|
148
|
-
value={value}
|
|
149
|
-
onChange={this.onChange}
|
|
150
|
-
aria-label="FormSelect Input"
|
|
151
|
-
>
|
|
152
|
-
{this.options.map((option, index) => (
|
|
153
|
-
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} isPlaceholder={option.isPlaceholder} />
|
|
154
|
-
))}
|
|
155
|
-
</FormSelect>
|
|
156
|
-
</FormGroup>
|
|
157
|
-
</Form>
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
16
|
+
```ts file='./FormSelectValidated.tsx'
|
|
161
17
|
```
|
|
162
18
|
|
|
163
19
|
### Disabled
|
|
164
|
-
```
|
|
165
|
-
import React from 'react';
|
|
166
|
-
import { FormSelect, FormSelectOption, FormSelectOptionGroup } from '@patternfly/react-core';
|
|
167
|
-
|
|
168
|
-
class FormSelectInputDisabled extends React.Component {
|
|
169
|
-
constructor(props) {
|
|
170
|
-
super(props);
|
|
171
|
-
this.state = {
|
|
172
|
-
value: 'mrs'
|
|
173
|
-
};
|
|
174
|
-
this.onChange = (value, event) => {
|
|
175
|
-
this.setState({ value });
|
|
176
|
-
};
|
|
177
|
-
this.options = [
|
|
178
|
-
{ value: 'please choose', label: 'Select one', disabled: true },
|
|
179
|
-
{ value: 'mr', label: 'Mr', disabled: false },
|
|
180
|
-
{ value: 'miss', label: 'Miss', disabled: false },
|
|
181
|
-
{ value: 'mrs', label: 'Mrs', disabled: false },
|
|
182
|
-
{ value: 'ms', label: 'Ms', disabled: false },
|
|
183
|
-
{ value: 'dr', label: 'Dr', disabled: false },
|
|
184
|
-
{ value: 'other', label: 'Other', disabled: false }
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
render() {
|
|
189
|
-
return (
|
|
190
|
-
<FormSelect value={this.state.value} onChange={this.onChange} isDisabled aria-label="FormSelect Input">
|
|
191
|
-
{this.options.map((option, index) => (
|
|
192
|
-
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} />
|
|
193
|
-
))}
|
|
194
|
-
</FormSelect>
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
20
|
+
```ts file='./FormSelectDisabled.tsx'
|
|
198
21
|
```
|
|
199
22
|
|
|
200
23
|
### Grouped
|
|
201
|
-
```
|
|
202
|
-
import React from 'react';
|
|
203
|
-
import { FormSelect, FormSelectOption, FormSelectOptionGroup } from '@patternfly/react-core';
|
|
204
|
-
|
|
205
|
-
class FormSelectInputGrouped extends React.Component {
|
|
206
|
-
constructor(props) {
|
|
207
|
-
super(props);
|
|
208
|
-
this.state = {
|
|
209
|
-
value: '2'
|
|
210
|
-
};
|
|
211
|
-
this.onChange = (value, event) => {
|
|
212
|
-
this.setState({ value });
|
|
213
|
-
};
|
|
214
|
-
this.groups = [
|
|
215
|
-
{
|
|
216
|
-
groupLabel: 'Group1',
|
|
217
|
-
disabled: false,
|
|
218
|
-
options: [
|
|
219
|
-
{ value: '1', label: 'The first option', disabled: false },
|
|
220
|
-
{ value: '2', label: 'Second option is selected by default', disabled: false }
|
|
221
|
-
]
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
groupLabel: 'Group2',
|
|
225
|
-
disabled: false,
|
|
226
|
-
options: [
|
|
227
|
-
{ value: '3', label: 'The third option', disabled: false },
|
|
228
|
-
{ value: '4', label: 'The fourth option', disabled: false }
|
|
229
|
-
]
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
groupLabel: 'Group3',
|
|
233
|
-
disabled: true,
|
|
234
|
-
options: [
|
|
235
|
-
{ value: '5', label: 'The fifth option', disabled: false },
|
|
236
|
-
{ value: '6', label: 'The sixth option', disabled: false }
|
|
237
|
-
]
|
|
238
|
-
}
|
|
239
|
-
];
|
|
240
|
-
this.getOptionLbl = option => option.label;
|
|
241
|
-
this.getOptionVal = option => option.value;
|
|
242
|
-
this.getOptionsGroupLbl = group => group && group.groupLabel;
|
|
243
|
-
this.getGroupOptions = group => group && group.options;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
render() {
|
|
247
|
-
return (
|
|
248
|
-
<FormSelect value={this.state.value} onChange={this.onChange} aria-label="FormSelect Input">
|
|
249
|
-
{this.groups.map((group, index) => (
|
|
250
|
-
<FormSelectOptionGroup isDisabled={group.disabled} key={index} label={group.groupLabel}>
|
|
251
|
-
{group.options.map((option, i) => (
|
|
252
|
-
<FormSelectOption isDisabled={option.disabled} key={i} value={option.value} label={option.label} />
|
|
253
|
-
))}
|
|
254
|
-
</FormSelectOptionGroup>
|
|
255
|
-
))}
|
|
256
|
-
</FormSelect>
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
24
|
+
```ts file='./FormSelectGrouped.tsx'
|
|
260
25
|
```
|
|
261
26
|
|
|
262
27
|
### Icon sprite variant
|
|
263
28
|
|
|
264
29
|
**Note:** The dropdown toggle icon is applied as a background image 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.
|
|
265
30
|
|
|
266
|
-
```
|
|
267
|
-
import React from 'react';
|
|
268
|
-
import { FormSelect, FormSelectOption, FormSelectOptionGroup } from '@patternfly/react-core';
|
|
269
|
-
|
|
270
|
-
class FormSelectIconSpriteInput extends React.Component {
|
|
271
|
-
constructor(props) {
|
|
272
|
-
super(props);
|
|
273
|
-
this.state = {
|
|
274
|
-
value: '',
|
|
275
|
-
validated: ValidatedOptions.default
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
this.onChange = (value, event) => {
|
|
279
|
-
if (value === '3') {
|
|
280
|
-
this.setState({ value, validated: ValidatedOptions.success, helperText: 'You chose wisely' });
|
|
281
|
-
} else if (value === '') {
|
|
282
|
-
this.setState({ value, validated: ValidatedOptions.warning, helperText: 'You must select a value' });
|
|
283
|
-
} else {
|
|
284
|
-
this.setState({
|
|
285
|
-
value,
|
|
286
|
-
validated: ValidatedOptions.error,
|
|
287
|
-
invalidText: 'You must chose Three (thought that was obvious)'
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
this.options = [
|
|
293
|
-
{ value: '', label: 'Select a number', disabled: false, isPlaceholder: true },
|
|
294
|
-
{ value: '1', label: 'One', disabled: false, isPlaceholder: false },
|
|
295
|
-
{ value: '2', label: 'Two', disabled: false, isPlaceholder: false },
|
|
296
|
-
{ value: '3', label: 'Three - the only valid option', disabled: false, isPlaceholder: false }
|
|
297
|
-
];
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
render() {
|
|
301
|
-
const { value, validated, helperText, invalidText } = this.state;
|
|
302
|
-
|
|
303
|
-
return (
|
|
304
|
-
<FormSelect
|
|
305
|
-
validated={validated}
|
|
306
|
-
isIconSprite
|
|
307
|
-
value={value}
|
|
308
|
-
onChange={this.onChange}
|
|
309
|
-
aria-label="FormSelect Input"
|
|
310
|
-
>
|
|
311
|
-
{this.options.map((option, index) => (
|
|
312
|
-
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} />
|
|
313
|
-
))}
|
|
314
|
-
</FormSelect>
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
31
|
+
```ts file='./FormSelectIconSpriteVariant.tsx' isBeta
|
|
318
32
|
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormSelect, FormSelectOption } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const FormSelectBasic: React.FunctionComponent = () => {
|
|
5
|
+
const [formSelectValue, setFormSelectValue] = React.useState('mrs');
|
|
6
|
+
|
|
7
|
+
const onChange = (value: string) => {
|
|
8
|
+
setFormSelectValue(value);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const options = [
|
|
12
|
+
{ value: 'please choose', label: 'Select one', disabled: true },
|
|
13
|
+
{ value: 'mr', label: 'Mr', disabled: false },
|
|
14
|
+
{ value: 'miss', label: 'Miss', disabled: false },
|
|
15
|
+
{ value: 'mrs', label: 'Mrs', disabled: false },
|
|
16
|
+
{ value: 'ms', label: 'Ms', disabled: false },
|
|
17
|
+
{ value: 'dr', label: 'Dr', disabled: false },
|
|
18
|
+
{ value: 'other', label: 'Other', disabled: false }
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<FormSelect value={formSelectValue} onChange={onChange} aria-label="FormSelect Input">
|
|
23
|
+
{options.map((option, index) => (
|
|
24
|
+
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} />
|
|
25
|
+
))}
|
|
26
|
+
</FormSelect>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormSelect, FormSelectOption } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const FormSelectDisabled: React.FunctionComponent = () => {
|
|
5
|
+
const [formSelectValue, setFormSelectValue] = React.useState('mrs');
|
|
6
|
+
|
|
7
|
+
const onChange = (value: string) => {
|
|
8
|
+
setFormSelectValue(value);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const options = [
|
|
12
|
+
{ value: 'please choose', label: 'Select one', disabled: true },
|
|
13
|
+
{ value: 'mr', label: 'Mr', disabled: false },
|
|
14
|
+
{ value: 'miss', label: 'Miss', disabled: false },
|
|
15
|
+
{ value: 'mrs', label: 'Mrs', disabled: false },
|
|
16
|
+
{ value: 'ms', label: 'Ms', disabled: false },
|
|
17
|
+
{ value: 'dr', label: 'Dr', disabled: false },
|
|
18
|
+
{ value: 'other', label: 'Other', disabled: false }
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<FormSelect value={formSelectValue} onChange={onChange} isDisabled aria-label="FormSelect Input">
|
|
23
|
+
{options.map((option, index) => (
|
|
24
|
+
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} />
|
|
25
|
+
))}
|
|
26
|
+
</FormSelect>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormSelect, FormSelectOption, FormSelectOptionGroup } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const FormSelectGrouped: React.FunctionComponent = () => {
|
|
5
|
+
const [formSelectValue, setFormSelectValue] = React.useState('2');
|
|
6
|
+
|
|
7
|
+
const onChange = (value: string) => {
|
|
8
|
+
setFormSelectValue(value);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const groups = [
|
|
12
|
+
{
|
|
13
|
+
groupLabel: 'Group1',
|
|
14
|
+
disabled: false,
|
|
15
|
+
options: [
|
|
16
|
+
{ value: '1', label: 'The first option', disabled: false },
|
|
17
|
+
{ value: '2', label: 'Second option is selected by default', disabled: false }
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
groupLabel: 'Group2',
|
|
22
|
+
disabled: false,
|
|
23
|
+
options: [
|
|
24
|
+
{ value: '3', label: 'The third option', disabled: false },
|
|
25
|
+
{ value: '4', label: 'The fourth option', disabled: false }
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
groupLabel: 'Group3',
|
|
30
|
+
disabled: true,
|
|
31
|
+
options: [
|
|
32
|
+
{ value: '5', label: 'The fifth option', disabled: false },
|
|
33
|
+
{ value: '6', label: 'The sixth option', disabled: false }
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<FormSelect value={formSelectValue} onChange={onChange} aria-label="FormSelect Input">
|
|
40
|
+
{groups.map((group, index) => (
|
|
41
|
+
<FormSelectOptionGroup isDisabled={group.disabled} key={index} label={group.groupLabel}>
|
|
42
|
+
{group.options.map((option, i) => (
|
|
43
|
+
<FormSelectOption isDisabled={option.disabled} key={i} value={option.value} label={option.label} />
|
|
44
|
+
))}
|
|
45
|
+
</FormSelectOptionGroup>
|
|
46
|
+
))}
|
|
47
|
+
</FormSelect>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Form, FormGroup, FormSelect, FormSelectOption, ValidatedOptions } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const FormSelectIconSpriteVariant: React.FunctionComponent = () => {
|
|
5
|
+
const [formSelectValue, setFormSelectValue] = React.useState('');
|
|
6
|
+
const [validated, setValidated] = React.useState<ValidatedOptions>(ValidatedOptions.default);
|
|
7
|
+
const [invalidText, setInvalidText] = React.useState('You must choose something');
|
|
8
|
+
const [helperText, setHelperText] = React.useState('');
|
|
9
|
+
|
|
10
|
+
const onChange = (value: string) => {
|
|
11
|
+
if (value === '3') {
|
|
12
|
+
setFormSelectValue(value);
|
|
13
|
+
setValidated(ValidatedOptions.success);
|
|
14
|
+
setHelperText('You chose wisely');
|
|
15
|
+
} else if (value === '') {
|
|
16
|
+
setFormSelectValue(value);
|
|
17
|
+
setValidated(ValidatedOptions.warning);
|
|
18
|
+
setHelperText('You must select a value');
|
|
19
|
+
} else {
|
|
20
|
+
setFormSelectValue(value);
|
|
21
|
+
setValidated(ValidatedOptions.error);
|
|
22
|
+
setInvalidText('You must chose Three (thought that was obvious)');
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const options = [
|
|
27
|
+
{ value: '', label: 'Select a number', disabled: false, isPlaceholder: true },
|
|
28
|
+
{ value: '1', label: 'One', disabled: false, isPlaceholder: false },
|
|
29
|
+
{ value: '2', label: 'Two', disabled: false, isPlaceholder: false },
|
|
30
|
+
{ value: '3', label: 'Three - the only valid option', disabled: false, isPlaceholder: false }
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Form>
|
|
35
|
+
<FormGroup
|
|
36
|
+
label="Selection:"
|
|
37
|
+
type="string"
|
|
38
|
+
helperText={helperText}
|
|
39
|
+
helperTextInvalid={invalidText}
|
|
40
|
+
fieldId="selection"
|
|
41
|
+
validated={validated}
|
|
42
|
+
>
|
|
43
|
+
<FormSelect
|
|
44
|
+
validated={validated}
|
|
45
|
+
isIconSprite
|
|
46
|
+
value={formSelectValue}
|
|
47
|
+
onChange={onChange}
|
|
48
|
+
aria-label="FormSelect Input"
|
|
49
|
+
>
|
|
50
|
+
{options.map((option, index) => (
|
|
51
|
+
<FormSelectOption isDisabled={option.disabled} key={index} value={option.value} label={option.label} />
|
|
52
|
+
))}
|
|
53
|
+
</FormSelect>
|
|
54
|
+
</FormGroup>
|
|
55
|
+
</Form>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Form, FormGroup, FormSelect, FormSelectOption, ValidatedOptions } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const FormSelectValidated: React.FunctionComponent = () => {
|
|
5
|
+
const [formValue, setFormValue] = React.useState('');
|
|
6
|
+
const [invalidText, setInvalidText] = React.useState('You must choose something');
|
|
7
|
+
const [helperText, setHelperText] = React.useState('');
|
|
8
|
+
const [validated, setValidated] = React.useState<ValidatedOptions>(ValidatedOptions.default);
|
|
9
|
+
|
|
10
|
+
const simulateNetworkCall = (callback: () => void) => {
|
|
11
|
+
setTimeout(callback, 2000);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const onChange = (value: string) => {
|
|
15
|
+
setFormValue(value);
|
|
16
|
+
setValidated(ValidatedOptions.default);
|
|
17
|
+
setHelperText('Validating...');
|
|
18
|
+
simulateNetworkCall(() => {
|
|
19
|
+
if (value === '3') {
|
|
20
|
+
setValidated(ValidatedOptions.success);
|
|
21
|
+
setHelperText('You chose wisely');
|
|
22
|
+
} else if (value === '') {
|
|
23
|
+
setValidated(ValidatedOptions.warning);
|
|
24
|
+
setHelperText('You must select a value');
|
|
25
|
+
} else {
|
|
26
|
+
setValidated(ValidatedOptions.error);
|
|
27
|
+
setInvalidText('You must chose Three (thought that was obvious)');
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const options = [
|
|
33
|
+
{ value: '', label: 'Select a number', disabled: false, isPlaceholder: true },
|
|
34
|
+
{ value: '1', label: 'One', disabled: false, isPlaceholder: false },
|
|
35
|
+
{ value: '2', label: 'Two', disabled: false, isPlaceholder: false },
|
|
36
|
+
{ value: '3', label: 'Three - the only valid option', disabled: false, isPlaceholder: false }
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Form>
|
|
41
|
+
<FormGroup
|
|
42
|
+
label="Selection:"
|
|
43
|
+
type="string"
|
|
44
|
+
helperText={helperText}
|
|
45
|
+
helperTextInvalid={invalidText}
|
|
46
|
+
fieldId="selection"
|
|
47
|
+
validated={validated}
|
|
48
|
+
>
|
|
49
|
+
<FormSelect
|
|
50
|
+
id="selection"
|
|
51
|
+
validated={validated}
|
|
52
|
+
value={formValue}
|
|
53
|
+
onChange={onChange}
|
|
54
|
+
aria-label="FormSelect Input"
|
|
55
|
+
>
|
|
56
|
+
{options.map((option, index) => (
|
|
57
|
+
<FormSelectOption
|
|
58
|
+
isDisabled={option.disabled}
|
|
59
|
+
key={index}
|
|
60
|
+
value={option.value}
|
|
61
|
+
label={option.label}
|
|
62
|
+
isPlaceholder={option.isPlaceholder}
|
|
63
|
+
/>
|
|
64
|
+
))}
|
|
65
|
+
</FormSelect>
|
|
66
|
+
</FormGroup>
|
|
67
|
+
</Form>
|
|
68
|
+
);
|
|
69
|
+
};
|