@patternfly/react-templates 6.0.0-alpha.2 → 6.0.0-alpha.21
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 +80 -0
- package/README.md +4 -17
- package/components/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -0
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic-modules.json +15 -0
- package/dist/esm/components/Dropdown/DropdownSimple.d.ts +43 -0
- package/dist/esm/components/Dropdown/DropdownSimple.d.ts.map +1 -0
- package/dist/esm/components/Dropdown/DropdownSimple.js +27 -0
- package/dist/esm/components/Dropdown/DropdownSimple.js.map +1 -0
- package/dist/esm/components/Dropdown/index.d.ts +2 -0
- package/dist/esm/components/Dropdown/index.d.ts.map +1 -0
- package/dist/esm/components/Dropdown/index.js +2 -0
- package/dist/esm/components/Dropdown/index.js.map +1 -0
- package/dist/esm/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/esm/components/Select/SelectTypeahead.d.ts +29 -0
- package/dist/esm/components/Select/SelectTypeahead.d.ts.map +1 -0
- package/dist/esm/components/Select/SelectTypeahead.js +179 -0
- package/dist/esm/components/Select/SelectTypeahead.js.map +1 -0
- package/dist/esm/components/Select/index.d.ts +1 -0
- package/dist/esm/components/Select/index.d.ts.map +1 -1
- package/dist/esm/components/Select/index.js +1 -0
- package/dist/esm/components/Select/index.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/js/components/Dropdown/DropdownSimple.d.ts +43 -0
- package/dist/js/components/Dropdown/DropdownSimple.d.ts.map +1 -0
- package/dist/js/components/Dropdown/DropdownSimple.js +30 -0
- package/dist/js/components/Dropdown/DropdownSimple.js.map +1 -0
- package/dist/js/components/Dropdown/index.d.ts +2 -0
- package/dist/js/components/Dropdown/index.d.ts.map +1 -0
- package/dist/js/components/Dropdown/index.js +5 -0
- package/dist/js/components/Dropdown/index.js.map +1 -0
- package/dist/js/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/js/components/Select/SelectSimple.js.map +1 -1
- package/dist/js/components/Select/SelectTypeahead.d.ts +29 -0
- package/dist/js/components/Select/SelectTypeahead.d.ts.map +1 -0
- package/dist/js/components/Select/SelectTypeahead.js +183 -0
- package/dist/js/components/Select/SelectTypeahead.js.map +1 -0
- package/dist/js/components/Select/index.d.ts +1 -0
- package/dist/js/components/Select/index.d.ts.map +1 -1
- package/dist/js/components/Select/index.js +1 -0
- package/dist/js/components/Select/index.js.map +1 -1
- package/dist/js/components/index.d.ts +1 -0
- package/dist/js/components/index.d.ts.map +1 -1
- package/dist/js/components/index.js +1 -0
- package/dist/js/components/index.js.map +1 -1
- package/dist/umd/assets/output-BQEbKtD2.css +24359 -0
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +7 -11
- package/rollup.config.mjs +8 -0
- package/src/components/Dropdown/DropdownSimple.tsx +122 -0
- package/src/components/Dropdown/__tests__/DropdownSimple.test.tsx +254 -0
- package/src/components/Dropdown/__tests__/__snapshots__/DropdownSimple.test.tsx.snap +147 -0
- package/src/components/Dropdown/examples/DropdownSimpleExample.tsx +53 -0
- package/src/components/Dropdown/examples/DropdownTemplates.md +36 -0
- package/src/components/Dropdown/index.ts +1 -0
- package/src/components/Select/SelectTypeahead.tsx +321 -0
- package/src/components/Select/__snapshots__/CheckboxSelectSnapshots.test.tsx.snap +4 -4
- package/src/components/Select/examples/SelectTemplates.md +9 -2
- package/src/components/Select/examples/SelectTypeaheadDemo.tsx +21 -0
- package/src/components/Select/index.ts +1 -0
- package/src/components/index.ts +1 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Select,
|
|
4
|
+
SelectOption,
|
|
5
|
+
SelectList,
|
|
6
|
+
SelectOptionProps,
|
|
7
|
+
MenuToggle,
|
|
8
|
+
MenuToggleElement,
|
|
9
|
+
TextInputGroup,
|
|
10
|
+
TextInputGroupMain,
|
|
11
|
+
TextInputGroupUtilities,
|
|
12
|
+
Button
|
|
13
|
+
} from '@patternfly/react-core';
|
|
14
|
+
import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
|
|
15
|
+
|
|
16
|
+
export interface SelectTypeaheadOption extends Omit<SelectOptionProps, 'content'> {
|
|
17
|
+
/** Content of the select option. */
|
|
18
|
+
content: string | number;
|
|
19
|
+
/** Value of the select option. */
|
|
20
|
+
value: string | number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SelectTypeaheadProps {
|
|
24
|
+
/** @hide Forwarded ref */
|
|
25
|
+
innerRef?: React.Ref<any>;
|
|
26
|
+
/** Initial options of the select. */
|
|
27
|
+
initialOptions: SelectTypeaheadOption[];
|
|
28
|
+
/** Callback triggered on selection. */
|
|
29
|
+
onSelect?: (
|
|
30
|
+
_event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<HTMLInputElement>,
|
|
31
|
+
selection: string | number
|
|
32
|
+
) => void;
|
|
33
|
+
/** Callback triggered when the select opens or closes. */
|
|
34
|
+
onToggle?: (nextIsOpen: boolean) => void;
|
|
35
|
+
/** Callback triggered when the text in the input field changes. */
|
|
36
|
+
onInputChange?: (newValue: string) => void;
|
|
37
|
+
/** Placeholder text for the select input. */
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
/** Message to display when no options match the filter. */
|
|
40
|
+
noOptionsFoundMessage?: string | ((filter: string) => string);
|
|
41
|
+
/** Flag indicating the select should be disabled. */
|
|
42
|
+
isDisabled?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const SelectTypeaheadBase: React.FunctionComponent<SelectTypeaheadProps> = ({
|
|
46
|
+
innerRef,
|
|
47
|
+
initialOptions,
|
|
48
|
+
onSelect,
|
|
49
|
+
onToggle,
|
|
50
|
+
onInputChange,
|
|
51
|
+
placeholder = 'Select an option',
|
|
52
|
+
noOptionsFoundMessage = (filter) => `No results found for "${filter}"`,
|
|
53
|
+
isDisabled,
|
|
54
|
+
...props
|
|
55
|
+
}: SelectTypeaheadProps) => {
|
|
56
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
57
|
+
const [selected, setSelected] = React.useState<string>('');
|
|
58
|
+
const [inputValue, setInputValue] = React.useState<string>('');
|
|
59
|
+
const [filterValue, setFilterValue] = React.useState<string>('');
|
|
60
|
+
const [selectOptions, setSelectOptions] = React.useState<SelectTypeaheadOption[]>(initialOptions);
|
|
61
|
+
const [focusedItemIndex, setFocusedItemIndex] = React.useState<number | null>(null);
|
|
62
|
+
const [activeItemId, setActiveItemId] = React.useState<string | null>(null);
|
|
63
|
+
const textInputRef = React.useRef<HTMLInputElement>();
|
|
64
|
+
|
|
65
|
+
const NO_RESULTS = 'no results';
|
|
66
|
+
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
let newSelectOptions: SelectTypeaheadOption[] = initialOptions;
|
|
69
|
+
|
|
70
|
+
// Filter menu items based on the text input value when one exists
|
|
71
|
+
if (filterValue) {
|
|
72
|
+
newSelectOptions = initialOptions.filter((option) =>
|
|
73
|
+
String(option.content).toLowerCase().includes(filterValue.toLowerCase())
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// When no options are found after filtering, display 'No results found'
|
|
77
|
+
if (!newSelectOptions.length) {
|
|
78
|
+
newSelectOptions = [
|
|
79
|
+
{
|
|
80
|
+
isAriaDisabled: true,
|
|
81
|
+
content:
|
|
82
|
+
typeof noOptionsFoundMessage === 'string' ? noOptionsFoundMessage : noOptionsFoundMessage(filterValue),
|
|
83
|
+
value: NO_RESULTS
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Open the menu when the input value changes and the new value is not empty
|
|
89
|
+
if (!isOpen) {
|
|
90
|
+
openMenu();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setSelectOptions(newSelectOptions);
|
|
95
|
+
}, [filterValue]);
|
|
96
|
+
|
|
97
|
+
const createItemId = (value: string | number) => `select-typeahead-${String(value).replace(' ', '-')}`;
|
|
98
|
+
|
|
99
|
+
const setActiveAndFocusedItem = (itemIndex: number) => {
|
|
100
|
+
setFocusedItemIndex(itemIndex);
|
|
101
|
+
const focusedItem = selectOptions[itemIndex];
|
|
102
|
+
setActiveItemId(createItemId(focusedItem.value));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const resetActiveAndFocusedItem = () => {
|
|
106
|
+
setFocusedItemIndex(null);
|
|
107
|
+
setActiveItemId(null);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const openMenu = () => {
|
|
111
|
+
onToggle && onToggle(true);
|
|
112
|
+
setIsOpen(true);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const closeMenu = () => {
|
|
116
|
+
onToggle && onToggle(false);
|
|
117
|
+
setIsOpen(false);
|
|
118
|
+
resetActiveAndFocusedItem();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const onInputClick = () => {
|
|
122
|
+
if (!isOpen) {
|
|
123
|
+
openMenu();
|
|
124
|
+
} else if (!inputValue) {
|
|
125
|
+
closeMenu();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const selectOption = (
|
|
130
|
+
_event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<HTMLInputElement> | undefined,
|
|
131
|
+
option: SelectTypeaheadOption
|
|
132
|
+
) => {
|
|
133
|
+
onSelect && onSelect(_event, option.value);
|
|
134
|
+
|
|
135
|
+
setInputValue(String(option.content));
|
|
136
|
+
setFilterValue('');
|
|
137
|
+
setSelected(String(option.value));
|
|
138
|
+
|
|
139
|
+
closeMenu();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const _onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
|
|
143
|
+
if (value && value !== NO_RESULTS) {
|
|
144
|
+
const optionToSelect = selectOptions.find((option) => option.value === value);
|
|
145
|
+
selectOption(_event, optionToSelect);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const onTextInputChange = (_event: React.FormEvent<HTMLInputElement>, value: string) => {
|
|
150
|
+
setInputValue(value);
|
|
151
|
+
onInputChange && onInputChange(value);
|
|
152
|
+
setFilterValue(value);
|
|
153
|
+
|
|
154
|
+
resetActiveAndFocusedItem();
|
|
155
|
+
|
|
156
|
+
if (value !== selected) {
|
|
157
|
+
setSelected('');
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const handleMenuArrowKeys = (key: string) => {
|
|
162
|
+
let indexToFocus = 0;
|
|
163
|
+
|
|
164
|
+
if (!isOpen) {
|
|
165
|
+
openMenu();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (selectOptions.every((option) => option.isDisabled)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (key === 'ArrowUp') {
|
|
173
|
+
// When no index is set or at the first index, focus to the last, otherwise decrement focus index
|
|
174
|
+
if (focusedItemIndex === null || focusedItemIndex === 0) {
|
|
175
|
+
indexToFocus = selectOptions.length - 1;
|
|
176
|
+
} else {
|
|
177
|
+
indexToFocus = focusedItemIndex - 1;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Skip disabled options
|
|
181
|
+
while (selectOptions[indexToFocus].isDisabled) {
|
|
182
|
+
indexToFocus--;
|
|
183
|
+
if (indexToFocus === -1) {
|
|
184
|
+
indexToFocus = selectOptions.length - 1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (key === 'ArrowDown') {
|
|
190
|
+
// When no index is set or at the last index, focus to the first, otherwise increment focus index
|
|
191
|
+
if (focusedItemIndex === null || focusedItemIndex === selectOptions.length - 1) {
|
|
192
|
+
indexToFocus = 0;
|
|
193
|
+
} else {
|
|
194
|
+
indexToFocus = focusedItemIndex + 1;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Skip disabled options
|
|
198
|
+
while (selectOptions[indexToFocus].isDisabled) {
|
|
199
|
+
indexToFocus++;
|
|
200
|
+
if (indexToFocus === selectOptions.length) {
|
|
201
|
+
indexToFocus = 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setActiveAndFocusedItem(indexToFocus);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const onInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
210
|
+
const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
211
|
+
|
|
212
|
+
switch (event.key) {
|
|
213
|
+
case 'Enter':
|
|
214
|
+
if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
|
|
215
|
+
selectOption(event, focusedItem);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!isOpen) {
|
|
219
|
+
setIsOpen(true);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
break;
|
|
223
|
+
case 'ArrowUp':
|
|
224
|
+
case 'ArrowDown':
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
handleMenuArrowKeys(event.key);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const onToggleClick = () => {
|
|
232
|
+
onToggle && onToggle(!isOpen);
|
|
233
|
+
setIsOpen(!isOpen);
|
|
234
|
+
textInputRef?.current?.focus();
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const onClearButtonClick = () => {
|
|
238
|
+
setSelected('');
|
|
239
|
+
setInputValue('');
|
|
240
|
+
onInputChange && onInputChange('');
|
|
241
|
+
setFilterValue('');
|
|
242
|
+
resetActiveAndFocusedItem();
|
|
243
|
+
textInputRef?.current?.focus();
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
|
|
247
|
+
<MenuToggle
|
|
248
|
+
ref={toggleRef}
|
|
249
|
+
variant="typeahead"
|
|
250
|
+
aria-label="Typeahead menu toggle"
|
|
251
|
+
onClick={onToggleClick}
|
|
252
|
+
isExpanded={isOpen}
|
|
253
|
+
isDisabled={isDisabled}
|
|
254
|
+
isFullWidth
|
|
255
|
+
>
|
|
256
|
+
<TextInputGroup isPlain>
|
|
257
|
+
<TextInputGroupMain
|
|
258
|
+
value={inputValue}
|
|
259
|
+
onClick={onInputClick}
|
|
260
|
+
onChange={onTextInputChange}
|
|
261
|
+
onKeyDown={onInputKeyDown}
|
|
262
|
+
id="typeahead-select-input"
|
|
263
|
+
autoComplete="off"
|
|
264
|
+
innerRef={textInputRef}
|
|
265
|
+
placeholder={placeholder}
|
|
266
|
+
{...(activeItemId && { 'aria-activedescendant': activeItemId })}
|
|
267
|
+
role="combobox"
|
|
268
|
+
isExpanded={isOpen}
|
|
269
|
+
aria-controls="select-typeahead-listbox"
|
|
270
|
+
/>
|
|
271
|
+
|
|
272
|
+
<TextInputGroupUtilities {...(!inputValue ? { style: { display: 'none' } } : {})}>
|
|
273
|
+
<Button variant="plain" onClick={onClearButtonClick} aria-label="Clear input value">
|
|
274
|
+
<TimesIcon aria-hidden />
|
|
275
|
+
</Button>
|
|
276
|
+
</TextInputGroupUtilities>
|
|
277
|
+
</TextInputGroup>
|
|
278
|
+
</MenuToggle>
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<Select
|
|
283
|
+
id="typeahead-select"
|
|
284
|
+
isOpen={isOpen}
|
|
285
|
+
selected={selected}
|
|
286
|
+
onSelect={_onSelect}
|
|
287
|
+
onOpenChange={(isOpen) => {
|
|
288
|
+
!isOpen && closeMenu();
|
|
289
|
+
}}
|
|
290
|
+
toggle={toggle}
|
|
291
|
+
shouldFocusFirstItemOnOpen={false}
|
|
292
|
+
ref={innerRef}
|
|
293
|
+
{...props}
|
|
294
|
+
>
|
|
295
|
+
<SelectList id="select-typeahead-listbox">
|
|
296
|
+
{selectOptions.map((option, index) => {
|
|
297
|
+
const { content, value, ...props } = option;
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<SelectOption
|
|
301
|
+
{...props}
|
|
302
|
+
key={value}
|
|
303
|
+
value={value}
|
|
304
|
+
isFocused={focusedItemIndex === index}
|
|
305
|
+
id={createItemId(value)}
|
|
306
|
+
>
|
|
307
|
+
{content}
|
|
308
|
+
</SelectOption>
|
|
309
|
+
);
|
|
310
|
+
})}
|
|
311
|
+
</SelectList>
|
|
312
|
+
</Select>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
SelectTypeaheadBase.displayName = 'SelectTypeaheadBase';
|
|
316
|
+
|
|
317
|
+
export const SelectTypeahead = React.forwardRef((props: SelectTypeaheadProps, ref: React.Ref<any>) => (
|
|
318
|
+
<SelectTypeaheadBase {...props} innerRef={ref} />
|
|
319
|
+
));
|
|
320
|
+
|
|
321
|
+
SelectTypeahead.displayName = 'SelectTypeahead';
|
|
@@ -76,7 +76,7 @@ exports[`opened checkbox select snapshot 1`] = `
|
|
|
76
76
|
<div
|
|
77
77
|
class="pf-v6-c-menu"
|
|
78
78
|
data-ouia-component-id="OUIA-Generated-Select-3"
|
|
79
|
-
data-ouia-component-type="
|
|
79
|
+
data-ouia-component-type="PF6/Select"
|
|
80
80
|
data-ouia-safe="true"
|
|
81
81
|
data-popper-escaped="true"
|
|
82
82
|
data-popper-placement="bottom-start"
|
|
@@ -114,7 +114,7 @@ exports[`opened checkbox select snapshot 1`] = `
|
|
|
114
114
|
aria-invalid="false"
|
|
115
115
|
class="pf-v6-c-check__input"
|
|
116
116
|
data-ouia-component-id="OUIA-Generated-Checkbox-1"
|
|
117
|
-
data-ouia-component-type="
|
|
117
|
+
data-ouia-component-type="PF6/Checkbox"
|
|
118
118
|
data-ouia-safe="true"
|
|
119
119
|
id="generated-id"
|
|
120
120
|
type="checkbox"
|
|
@@ -152,7 +152,7 @@ exports[`opened checkbox select snapshot 1`] = `
|
|
|
152
152
|
aria-invalid="false"
|
|
153
153
|
class="pf-v6-c-check__input"
|
|
154
154
|
data-ouia-component-id="OUIA-Generated-Checkbox-2"
|
|
155
|
-
data-ouia-component-type="
|
|
155
|
+
data-ouia-component-type="PF6/Checkbox"
|
|
156
156
|
data-ouia-safe="true"
|
|
157
157
|
id="generated-id"
|
|
158
158
|
type="checkbox"
|
|
@@ -190,7 +190,7 @@ exports[`opened checkbox select snapshot 1`] = `
|
|
|
190
190
|
aria-invalid="false"
|
|
191
191
|
class="pf-v6-c-check__input"
|
|
192
192
|
data-ouia-component-id="OUIA-Generated-Checkbox-3"
|
|
193
|
-
data-ouia-component-type="
|
|
193
|
+
data-ouia-component-type="PF6/Checkbox"
|
|
194
194
|
data-ouia-safe="true"
|
|
195
195
|
id="generated-id"
|
|
196
196
|
type="checkbox"
|
|
@@ -4,7 +4,7 @@ section: components
|
|
|
4
4
|
subsection: menus
|
|
5
5
|
template: true
|
|
6
6
|
beta: true
|
|
7
|
-
propComponents: ['SelectSimple', 'CheckboxSelect']
|
|
7
|
+
propComponents: ['SelectSimple', 'CheckboxSelect', 'SelectTypeahead']
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
Note: Templates live in their own package at [@patternfly/react-templates](https://www.npmjs.com/package/@patternfly/react-templates)!
|
|
@@ -12,7 +12,7 @@ Note: Templates live in their own package at [@patternfly/react-templates](https
|
|
|
12
12
|
For custom use cases, please see the select component suite from [@patternfly/react-core](https://www.npmjs.com/package/@patternfly/react-core).
|
|
13
13
|
|
|
14
14
|
import { SelectOption, Checkbox } from '@patternfly/react-core';
|
|
15
|
-
import { SelectSimple, CheckboxSelect } from '@patternfly/react-templates';
|
|
15
|
+
import { SelectSimple, CheckboxSelect, SelectTypeahead } from '@patternfly/react-templates';
|
|
16
16
|
|
|
17
17
|
## Select template examples
|
|
18
18
|
|
|
@@ -25,4 +25,11 @@ import { SelectSimple, CheckboxSelect } from '@patternfly/react-templates';
|
|
|
25
25
|
### Checkbox
|
|
26
26
|
|
|
27
27
|
```ts file="CheckboxSelectDemo.tsx"
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Typeahead
|
|
32
|
+
|
|
33
|
+
```ts file="SelectTypeaheadDemo.tsx"
|
|
34
|
+
|
|
28
35
|
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectTypeahead, SelectTypeaheadOption } from '@patternfly/react-templates';
|
|
3
|
+
|
|
4
|
+
export const SelectTypeaheadDemo: React.FunctionComponent = () => {
|
|
5
|
+
const initialOptions: SelectTypeaheadOption[] = [
|
|
6
|
+
{ content: 'Alabama', value: 'option1' },
|
|
7
|
+
{ content: 'Florida', value: 'option2' },
|
|
8
|
+
{ content: 'New Jersey', value: 'option3' },
|
|
9
|
+
{ content: 'New Mexico', value: 'option4' },
|
|
10
|
+
{ content: 'New York', value: 'option5' },
|
|
11
|
+
{ content: 'North Carolina', value: 'option6' }
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<SelectTypeahead
|
|
16
|
+
initialOptions={initialOptions}
|
|
17
|
+
placeholder="Select a state"
|
|
18
|
+
noOptionsFoundMessage={(filter) => `No state was found for "${filter}"`}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
};
|
package/src/components/index.ts
CHANGED