@patternfly/react-templates 6.4.0-prerelease.4 → 6.4.0-prerelease.6
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 +10 -0
- package/components/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/esm/components/Dropdown/SimpleDropdown.js.map +1 -1
- package/dist/esm/components/Select/CheckboxSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts +2 -2
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.js +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.js.map +1 -1
- package/dist/esm/components/Select/SimpleSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/SimpleSelect.js.map +1 -1
- package/dist/esm/components/Select/TypeaheadSelect.d.ts +2 -2
- package/dist/esm/components/Select/TypeaheadSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/TypeaheadSelect.js +1 -1
- package/dist/esm/components/Select/TypeaheadSelect.js.map +1 -1
- package/dist/js/components/Dropdown/SimpleDropdown.js.map +1 -1
- package/dist/js/components/Select/CheckboxSelect.d.ts.map +1 -1
- package/dist/js/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts +2 -2
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.js.map +1 -1
- package/dist/js/components/Select/SimpleSelect.d.ts.map +1 -1
- package/dist/js/components/Select/SimpleSelect.js.map +1 -1
- package/dist/js/components/Select/TypeaheadSelect.d.ts +2 -2
- package/dist/js/components/Select/TypeaheadSelect.d.ts.map +1 -1
- package/dist/js/components/Select/TypeaheadSelect.js.map +1 -1
- package/dist/umd/assets/{output-BYKMO9t1.css → output-CE5BeU7_.css} +2531 -2531
- package/package.json +8 -8
- package/src/components/Dropdown/SimpleDropdown.tsx +6 -6
- package/src/components/Dropdown/examples/DropdownTemplates.md +1 -1
- package/src/components/Dropdown/examples/SimpleDropdownExample.tsx +2 -2
- package/src/components/Select/CheckboxSelect.tsx +14 -6
- package/src/components/Select/MultiTypeaheadSelect.tsx +23 -12
- package/src/components/Select/SimpleSelect.tsx +14 -6
- package/src/components/Select/TypeaheadSelect.tsx +21 -10
- package/src/components/Select/examples/CheckboxSelectDemo.tsx +2 -2
- package/src/components/Select/examples/MultiTypeaheadSelectDemo.tsx +2 -2
- package/src/components/Select/examples/SelectTemplates.md +1 -1
- package/src/components/Select/examples/SimpleSelectDemo.tsx +2 -2
- package/src/components/Select/examples/TypeaheadSelectDemo.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-templates",
|
|
3
|
-
"version": "6.4.0-prerelease.
|
|
3
|
+
"version": "6.4.0-prerelease.6",
|
|
4
4
|
"description": "This package provides wrapped component demos for ease of use\n",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@patternfly/react-core": "^6.4.0-prerelease.
|
|
37
|
-
"@patternfly/react-icons": "^6.4.0-prerelease.
|
|
38
|
-
"@patternfly/react-styles": "^6.4.0-prerelease.
|
|
39
|
-
"@patternfly/react-tokens": "^6.4.0-prerelease.
|
|
36
|
+
"@patternfly/react-core": "^6.4.0-prerelease.5",
|
|
37
|
+
"@patternfly/react-icons": "^6.4.0-prerelease.3",
|
|
38
|
+
"@patternfly/react-styles": "^6.4.0-prerelease.3",
|
|
39
|
+
"@patternfly/react-tokens": "^6.4.0-prerelease.3",
|
|
40
40
|
"tslib": "^2.8.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"react": "^17 || ^18",
|
|
44
|
-
"react-dom": "^17 || ^18"
|
|
43
|
+
"react": "^17 || ^18 || ^19",
|
|
44
|
+
"react-dom": "^17 || ^18 || ^19"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "201443e85688ffd5be3bdcd1bd37c9e67cf634e3"
|
|
47
47
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useState } from 'react';
|
|
1
|
+
import { forwardRef, useState, FunctionComponent, Ref, MouseEvent as ReactMouseEvent, CSSProperties } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Dropdown,
|
|
4
4
|
DropdownItem,
|
|
@@ -54,7 +54,7 @@ export interface SimpleDropdownProps extends Omit<DropdownProps, 'toggle' | 'onT
|
|
|
54
54
|
toggleProps?: MenuToggleProps;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
const SimpleDropdownBase:
|
|
57
|
+
const SimpleDropdownBase: FunctionComponent<SimpleDropdownProps> = ({
|
|
58
58
|
innerRef,
|
|
59
59
|
initialItems,
|
|
60
60
|
onSelect: onSelectProp,
|
|
@@ -71,7 +71,7 @@ const SimpleDropdownBase: React.FunctionComponent<SimpleDropdownProps> = ({
|
|
|
71
71
|
}: SimpleDropdownProps) => {
|
|
72
72
|
const [isOpen, setIsOpen] = useState(false);
|
|
73
73
|
|
|
74
|
-
const onSelect = (event:
|
|
74
|
+
const onSelect = (event: ReactMouseEvent<Element, MouseEvent>, value: string | number) => {
|
|
75
75
|
onSelectProp && onSelectProp(event, value);
|
|
76
76
|
onToggleProp && onToggleProp(false);
|
|
77
77
|
setIsOpen(false);
|
|
@@ -82,7 +82,7 @@ const SimpleDropdownBase: React.FunctionComponent<SimpleDropdownProps> = ({
|
|
|
82
82
|
setIsOpen(!isOpen);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
const dropdownToggle = (toggleRef:
|
|
85
|
+
const dropdownToggle = (toggleRef: Ref<MenuToggleElement>) => (
|
|
86
86
|
<MenuToggle
|
|
87
87
|
ref={toggleRef}
|
|
88
88
|
onClick={onToggle}
|
|
@@ -94,7 +94,7 @@ const SimpleDropdownBase: React.FunctionComponent<SimpleDropdownProps> = ({
|
|
|
94
94
|
style={
|
|
95
95
|
{
|
|
96
96
|
width: toggleWidth
|
|
97
|
-
} as
|
|
97
|
+
} as CSSProperties
|
|
98
98
|
}
|
|
99
99
|
{...toggleProps}
|
|
100
100
|
>
|
|
@@ -132,7 +132,7 @@ const SimpleDropdownBase: React.FunctionComponent<SimpleDropdownProps> = ({
|
|
|
132
132
|
);
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
export const SimpleDropdown = forwardRef((props: SimpleDropdownProps, ref:
|
|
135
|
+
export const SimpleDropdown = forwardRef((props: SimpleDropdownProps, ref: Ref<any>) => (
|
|
136
136
|
<SimpleDropdownBase {...props} innerRef={ref} />
|
|
137
137
|
));
|
|
138
138
|
|
|
@@ -11,7 +11,7 @@ Note: Templates live in their own package at [@patternfly/react-templates](https
|
|
|
11
11
|
|
|
12
12
|
For custom use cases, please see the dropdown component suite from [@patternfly/react-core](https://www.npmjs.com/package/@patternfly/react-core).
|
|
13
13
|
|
|
14
|
-
import { Fragment, useState } from 'react';
|
|
14
|
+
import { Fragment, useState, FunctionComponent } from 'react';
|
|
15
15
|
import { Checkbox, Flex, FlexItem } from '@patternfly/react-core';
|
|
16
16
|
import { SimpleDropdown } from '@patternfly/react-templates';
|
|
17
17
|
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Fragment, useState } from 'react';
|
|
1
|
+
import { Fragment, useState, FunctionComponent } from 'react';
|
|
2
2
|
import { Checkbox, Flex, FlexItem } from '@patternfly/react-core';
|
|
3
3
|
import { SimpleDropdown, SimpleDropdownItem } from '@patternfly/react-templates';
|
|
4
4
|
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
|
|
5
5
|
|
|
6
|
-
export const SimpleDropdownExample:
|
|
6
|
+
export const SimpleDropdownExample: FunctionComponent = () => {
|
|
7
7
|
const [isDisabled, setIsDisabled] = useState(false);
|
|
8
8
|
|
|
9
9
|
const items: SimpleDropdownItem[] = [
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useState,
|
|
5
|
+
FunctionComponent,
|
|
6
|
+
Ref,
|
|
7
|
+
MouseEvent as ReactMouseEvent,
|
|
8
|
+
CSSProperties
|
|
9
|
+
} from 'react';
|
|
2
10
|
import { Badge } from '@patternfly/react-core/dist/esm/components/Badge';
|
|
3
11
|
import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
4
12
|
import {
|
|
@@ -35,7 +43,7 @@ export interface CheckboxSelectProps extends Omit<SelectProps, 'toggle' | 'onTog
|
|
|
35
43
|
toggleProps?: MenuToggleProps;
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
const CheckboxSelectBase:
|
|
46
|
+
const CheckboxSelectBase: FunctionComponent<CheckboxSelectProps> = ({
|
|
39
47
|
innerRef,
|
|
40
48
|
initialOptions,
|
|
41
49
|
isDisabled,
|
|
@@ -69,7 +77,7 @@ const CheckboxSelectBase: React.FunctionComponent<CheckboxSelectProps> = ({
|
|
|
69
77
|
setIsOpen(!isOpen);
|
|
70
78
|
};
|
|
71
79
|
|
|
72
|
-
const onSelect = (event:
|
|
80
|
+
const onSelect = (event: ReactMouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
|
|
73
81
|
const valueString = `${value}`;
|
|
74
82
|
if (selected.includes(valueString)) {
|
|
75
83
|
setSelected((prevSelected) => prevSelected.filter((item) => item !== valueString));
|
|
@@ -86,7 +94,7 @@ const CheckboxSelectBase: React.FunctionComponent<CheckboxSelectProps> = ({
|
|
|
86
94
|
</>
|
|
87
95
|
);
|
|
88
96
|
|
|
89
|
-
const toggle = (toggleRef:
|
|
97
|
+
const toggle = (toggleRef: Ref<MenuToggleElement>) => (
|
|
90
98
|
<MenuToggle
|
|
91
99
|
ref={toggleRef}
|
|
92
100
|
onClick={onToggleClick}
|
|
@@ -95,7 +103,7 @@ const CheckboxSelectBase: React.FunctionComponent<CheckboxSelectProps> = ({
|
|
|
95
103
|
style={
|
|
96
104
|
{
|
|
97
105
|
width: toggleWidth
|
|
98
|
-
} as
|
|
106
|
+
} as CSSProperties
|
|
99
107
|
}
|
|
100
108
|
{...toggleProps}
|
|
101
109
|
>
|
|
@@ -122,6 +130,6 @@ const CheckboxSelectBase: React.FunctionComponent<CheckboxSelectProps> = ({
|
|
|
122
130
|
);
|
|
123
131
|
};
|
|
124
132
|
|
|
125
|
-
export const CheckboxSelect = forwardRef((props: CheckboxSelectProps, ref:
|
|
133
|
+
export const CheckboxSelect = forwardRef((props: CheckboxSelectProps, ref: Ref<any>) => (
|
|
126
134
|
<CheckboxSelectBase {...props} innerRef={ref} />
|
|
127
135
|
));
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useState,
|
|
5
|
+
useRef,
|
|
6
|
+
FunctionComponent,
|
|
7
|
+
Ref,
|
|
8
|
+
MouseEvent as ReactMouseEvent,
|
|
9
|
+
KeyboardEvent as ReactKeyboardEvent,
|
|
10
|
+
FormEvent as ReactFormEvent,
|
|
11
|
+
CSSProperties
|
|
12
|
+
} from 'react';
|
|
2
13
|
import { Button } from '@patternfly/react-core/dist/esm/components/Button';
|
|
3
14
|
import { Label, LabelGroup, LabelProps } from '@patternfly/react-core/dist/esm/components/Label';
|
|
4
15
|
import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
@@ -57,7 +68,7 @@ export interface MultiTypeaheadSelectProps extends Omit<SelectProps, 'toggle' |
|
|
|
57
68
|
initialInputValue?: string;
|
|
58
69
|
}
|
|
59
70
|
|
|
60
|
-
export const MultiTypeaheadSelectBase:
|
|
71
|
+
export const MultiTypeaheadSelectBase: FunctionComponent<MultiTypeaheadSelectProps> = ({
|
|
61
72
|
innerRef,
|
|
62
73
|
initialOptions,
|
|
63
74
|
onSelectionChange,
|
|
@@ -145,7 +156,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
145
156
|
};
|
|
146
157
|
|
|
147
158
|
const selectOption = (
|
|
148
|
-
_event:
|
|
159
|
+
_event: ReactMouseEvent<Element, MouseEvent> | ReactKeyboardEvent<HTMLInputElement> | undefined,
|
|
149
160
|
option: string | number
|
|
150
161
|
) => {
|
|
151
162
|
const selections = selected.includes(option) ? selected.filter((o) => option !== o) : [...selected, option];
|
|
@@ -155,7 +166,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
155
166
|
};
|
|
156
167
|
|
|
157
168
|
const clearOption = (
|
|
158
|
-
_event:
|
|
169
|
+
_event: ReactMouseEvent<Element, MouseEvent> | ReactKeyboardEvent<HTMLInputElement> | undefined,
|
|
159
170
|
option: string | number
|
|
160
171
|
) => {
|
|
161
172
|
const selections = selected.filter((o) => option !== o);
|
|
@@ -163,13 +174,13 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
163
174
|
setSelected(selections);
|
|
164
175
|
};
|
|
165
176
|
|
|
166
|
-
const _onSelect = (_event:
|
|
177
|
+
const _onSelect = (_event: ReactMouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
|
|
167
178
|
if (value && value !== NO_RESULTS) {
|
|
168
179
|
selectOption(_event, value);
|
|
169
180
|
}
|
|
170
181
|
};
|
|
171
182
|
|
|
172
|
-
const onTextInputChange = (_event:
|
|
183
|
+
const onTextInputChange = (_event: ReactFormEvent<HTMLInputElement>, value: string) => {
|
|
173
184
|
setInputValue(value);
|
|
174
185
|
onInputChange && onInputChange(value);
|
|
175
186
|
|
|
@@ -228,7 +239,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
228
239
|
setActiveAndFocusedItem(indexToFocus);
|
|
229
240
|
};
|
|
230
241
|
|
|
231
|
-
const defaultOnInputKeyDown = (event:
|
|
242
|
+
const defaultOnInputKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
|
|
232
243
|
const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
233
244
|
|
|
234
245
|
switch (event.key) {
|
|
@@ -252,7 +263,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
252
263
|
}
|
|
253
264
|
};
|
|
254
265
|
|
|
255
|
-
const onInputKeyDown = (event:
|
|
266
|
+
const onInputKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
|
|
256
267
|
if (onInputKeyDownProp) {
|
|
257
268
|
onInputKeyDownProp(event);
|
|
258
269
|
} else {
|
|
@@ -266,7 +277,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
266
277
|
textInputRef?.current?.focus();
|
|
267
278
|
};
|
|
268
279
|
|
|
269
|
-
const onClearButtonClick = (ev:
|
|
280
|
+
const onClearButtonClick = (ev: ReactMouseEvent) => {
|
|
270
281
|
setSelected([]);
|
|
271
282
|
onInputChange && onInputChange('');
|
|
272
283
|
resetActiveAndFocusedItem();
|
|
@@ -274,7 +285,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
274
285
|
onSelectionChange && onSelectionChange(ev, []);
|
|
275
286
|
};
|
|
276
287
|
|
|
277
|
-
const toggle = (toggleRef:
|
|
288
|
+
const toggle = (toggleRef: Ref<MenuToggleElement>) => (
|
|
278
289
|
<MenuToggle
|
|
279
290
|
ref={toggleRef}
|
|
280
291
|
variant="typeahead"
|
|
@@ -286,7 +297,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
286
297
|
style={
|
|
287
298
|
{
|
|
288
299
|
width: toggleWidth
|
|
289
|
-
} as
|
|
300
|
+
} as CSSProperties
|
|
290
301
|
}
|
|
291
302
|
{...toggleProps}
|
|
292
303
|
>
|
|
@@ -359,7 +370,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
|
|
|
359
370
|
|
|
360
371
|
MultiTypeaheadSelectBase.displayName = 'MultiTypeaheadSelectBase';
|
|
361
372
|
|
|
362
|
-
export const MultiTypeaheadSelect = forwardRef((props: MultiTypeaheadSelectProps, ref:
|
|
373
|
+
export const MultiTypeaheadSelect = forwardRef((props: MultiTypeaheadSelectProps, ref: Ref<any>) => (
|
|
363
374
|
<MultiTypeaheadSelectBase {...props} innerRef={ref} />
|
|
364
375
|
));
|
|
365
376
|
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useState,
|
|
5
|
+
FunctionComponent,
|
|
6
|
+
Ref,
|
|
7
|
+
MouseEvent as ReactMouseEvent,
|
|
8
|
+
CSSProperties
|
|
9
|
+
} from 'react';
|
|
2
10
|
import {
|
|
3
11
|
Select,
|
|
4
12
|
SelectList,
|
|
@@ -36,7 +44,7 @@ export interface SimpleSelectProps extends Omit<SelectProps, 'toggle' | 'onToggl
|
|
|
36
44
|
toggleProps?: MenuToggleProps;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
const SimpleSelectBase:
|
|
47
|
+
const SimpleSelectBase: FunctionComponent<SimpleSelectProps> = ({
|
|
40
48
|
innerRef,
|
|
41
49
|
initialOptions,
|
|
42
50
|
isDisabled,
|
|
@@ -71,14 +79,14 @@ const SimpleSelectBase: React.FunctionComponent<SimpleSelectProps> = ({
|
|
|
71
79
|
setIsOpen(!isOpen);
|
|
72
80
|
};
|
|
73
81
|
|
|
74
|
-
const _onSelect = (_event:
|
|
82
|
+
const _onSelect = (_event: ReactMouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
|
|
75
83
|
onSelect && onSelect(_event, value);
|
|
76
84
|
setSelected(initialOptions.find((o) => o.value === value));
|
|
77
85
|
onToggle && onToggle(true);
|
|
78
86
|
setIsOpen(false);
|
|
79
87
|
};
|
|
80
88
|
|
|
81
|
-
const toggle = (toggleRef:
|
|
89
|
+
const toggle = (toggleRef: Ref<MenuToggleElement>) => (
|
|
82
90
|
<MenuToggle
|
|
83
91
|
ref={toggleRef}
|
|
84
92
|
onClick={onToggleClick}
|
|
@@ -87,7 +95,7 @@ const SimpleSelectBase: React.FunctionComponent<SimpleSelectProps> = ({
|
|
|
87
95
|
style={
|
|
88
96
|
{
|
|
89
97
|
width: toggleWidth
|
|
90
|
-
} as
|
|
98
|
+
} as CSSProperties
|
|
91
99
|
}
|
|
92
100
|
{...toggleProps}
|
|
93
101
|
>
|
|
@@ -114,7 +122,7 @@ const SimpleSelectBase: React.FunctionComponent<SimpleSelectProps> = ({
|
|
|
114
122
|
);
|
|
115
123
|
};
|
|
116
124
|
|
|
117
|
-
export const SimpleSelect = forwardRef((props: SimpleSelectProps, ref:
|
|
125
|
+
export const SimpleSelect = forwardRef((props: SimpleSelectProps, ref: Ref<any>) => (
|
|
118
126
|
<SimpleSelectBase {...props} innerRef={ref} />
|
|
119
127
|
));
|
|
120
128
|
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useState,
|
|
5
|
+
useRef,
|
|
6
|
+
FunctionComponent,
|
|
7
|
+
Ref,
|
|
8
|
+
MouseEvent as ReactMouseEvent,
|
|
9
|
+
KeyboardEvent as ReactKeyboardEvent,
|
|
10
|
+
FormEvent as ReactFormEvent,
|
|
11
|
+
CSSProperties
|
|
12
|
+
} from 'react';
|
|
2
13
|
import { Button } from '@patternfly/react-core/dist/esm/components/Button';
|
|
3
14
|
import { MenuToggle, MenuToggleElement, MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
4
15
|
import {
|
|
@@ -65,7 +76,7 @@ export interface TypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSe
|
|
|
65
76
|
const defaultNoOptionsFoundMessage = (filter: string) => `No results found for "${filter}"`;
|
|
66
77
|
const defaultCreateOptionMessage = (newValue: string) => `Create "${newValue}"`;
|
|
67
78
|
|
|
68
|
-
export const TypeaheadSelectBase:
|
|
79
|
+
export const TypeaheadSelectBase: FunctionComponent<TypeaheadSelectProps> = ({
|
|
69
80
|
innerRef,
|
|
70
81
|
initialOptions,
|
|
71
82
|
onSelect,
|
|
@@ -203,7 +214,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
203
214
|
};
|
|
204
215
|
|
|
205
216
|
const selectOption = (
|
|
206
|
-
_event:
|
|
217
|
+
_event: ReactMouseEvent<Element, MouseEvent> | ReactKeyboardEvent<HTMLInputElement> | undefined,
|
|
207
218
|
option: TypeaheadSelectOption
|
|
208
219
|
) => {
|
|
209
220
|
onSelect && onSelect(_event, option.value);
|
|
@@ -215,14 +226,14 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
215
226
|
closeMenu();
|
|
216
227
|
};
|
|
217
228
|
|
|
218
|
-
const _onSelect = (_event:
|
|
229
|
+
const _onSelect = (_event: ReactMouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
|
|
219
230
|
if (value && value !== NO_RESULTS) {
|
|
220
231
|
const optionToSelect = selectOptions.find((option) => option.value === value);
|
|
221
232
|
selectOption(_event, optionToSelect);
|
|
222
233
|
}
|
|
223
234
|
};
|
|
224
235
|
|
|
225
|
-
const onTextInputChange = (_event:
|
|
236
|
+
const onTextInputChange = (_event: ReactFormEvent<HTMLInputElement>, value: string) => {
|
|
226
237
|
setInputValue(value);
|
|
227
238
|
onInputChange && onInputChange(value);
|
|
228
239
|
setFilterValue(value);
|
|
@@ -276,7 +287,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
276
287
|
setActiveAndFocusedItem(indexToFocus);
|
|
277
288
|
};
|
|
278
289
|
|
|
279
|
-
const defaultOnInputKeyDown = (event:
|
|
290
|
+
const defaultOnInputKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
|
|
280
291
|
const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
281
292
|
|
|
282
293
|
switch (event.key) {
|
|
@@ -297,7 +308,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
297
308
|
}
|
|
298
309
|
};
|
|
299
310
|
|
|
300
|
-
const onInputKeyDown = (event:
|
|
311
|
+
const onInputKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {
|
|
301
312
|
if (onInputKeyDownProp) {
|
|
302
313
|
onInputKeyDownProp(event);
|
|
303
314
|
} else {
|
|
@@ -321,7 +332,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
321
332
|
onClearSelection && onClearSelection();
|
|
322
333
|
};
|
|
323
334
|
|
|
324
|
-
const toggle = (toggleRef:
|
|
335
|
+
const toggle = (toggleRef: Ref<MenuToggleElement>) => (
|
|
325
336
|
<MenuToggle
|
|
326
337
|
ref={toggleRef}
|
|
327
338
|
variant="typeahead"
|
|
@@ -333,7 +344,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
333
344
|
style={
|
|
334
345
|
{
|
|
335
346
|
width: toggleWidth
|
|
336
|
-
} as
|
|
347
|
+
} as CSSProperties
|
|
337
348
|
}
|
|
338
349
|
{...toggleProps}
|
|
339
350
|
>
|
|
@@ -388,7 +399,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
|
|
|
388
399
|
};
|
|
389
400
|
TypeaheadSelectBase.displayName = 'TypeaheadSelectBase';
|
|
390
401
|
|
|
391
|
-
export const TypeaheadSelect = forwardRef((props: TypeaheadSelectProps, ref:
|
|
402
|
+
export const TypeaheadSelect = forwardRef((props: TypeaheadSelectProps, ref: Ref<any>) => (
|
|
392
403
|
<TypeaheadSelectBase {...props} innerRef={ref} />
|
|
393
404
|
));
|
|
394
405
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
1
|
+
import { useMemo, useState, FunctionComponent } from 'react';
|
|
2
2
|
import { CheckboxSelect, CheckboxSelectOption } from '@patternfly/react-templates';
|
|
3
3
|
|
|
4
4
|
const Options: { content: string; value: string; description?: string; isDisabled?: boolean }[] = [
|
|
@@ -8,7 +8,7 @@ const Options: { content: string; value: string; description?: string; isDisable
|
|
|
8
8
|
{ content: 'Option 4', value: 'option-4' }
|
|
9
9
|
];
|
|
10
10
|
|
|
11
|
-
export const SelectBasic:
|
|
11
|
+
export const SelectBasic: FunctionComponent = () => {
|
|
12
12
|
const [selected, setSelected] = useState<string[]>(['option-2']);
|
|
13
13
|
|
|
14
14
|
const initialOptions = useMemo<CheckboxSelectOption[]>(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
1
|
+
import { useMemo, useState, FunctionComponent } from 'react';
|
|
2
2
|
import { MultiTypeaheadSelect, MultiTypeaheadSelectOption } from '@patternfly/react-templates';
|
|
3
3
|
|
|
4
4
|
const Options = [
|
|
@@ -16,7 +16,7 @@ const Options = [
|
|
|
16
16
|
|
|
17
17
|
type SelectionsType = (string | number)[];
|
|
18
18
|
|
|
19
|
-
export const MultiSelectTypeaheadDemo:
|
|
19
|
+
export const MultiSelectTypeaheadDemo: FunctionComponent = () => {
|
|
20
20
|
const [selected, setSelected] = useState<SelectionsType>(['option5']);
|
|
21
21
|
|
|
22
22
|
const initialOptions = useMemo<MultiTypeaheadSelectOption[]>(
|
|
@@ -11,7 +11,7 @@ Note: Templates live in their own package at [@patternfly/react-templates](https
|
|
|
11
11
|
|
|
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
|
-
import { Fragment, useEffect, useMemo, useState } from 'react';
|
|
14
|
+
import { Fragment, useEffect, useMemo, useState, FunctionComponent } from 'react';
|
|
15
15
|
import { Checkbox } from '@patternfly/react-core';
|
|
16
16
|
import { SimpleSelect, CheckboxSelect, TypeaheadSelect, MultiTypeaheadSelect } from '@patternfly/react-templates';
|
|
17
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fragment, useMemo, useState } from 'react';
|
|
1
|
+
import { Fragment, useMemo, useState, FunctionComponent } from 'react';
|
|
2
2
|
import { Checkbox } from '@patternfly/react-core';
|
|
3
3
|
import { SimpleSelect, SimpleSelectOption } from '@patternfly/react-templates';
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ const Options: SimpleSelectOption[] = [
|
|
|
8
8
|
{ content: 'Option 3', value: 'Option3' }
|
|
9
9
|
];
|
|
10
10
|
|
|
11
|
-
export const SelectSimpleDemo:
|
|
11
|
+
export const SelectSimpleDemo: FunctionComponent = () => {
|
|
12
12
|
const [isDisabled, setIsDisabled] = useState<boolean>(false);
|
|
13
13
|
const [selected, setSelected] = useState<string | undefined>('Option1');
|
|
14
14
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState, FunctionComponent } from 'react';
|
|
2
2
|
import { TypeaheadSelect, TypeaheadSelectOption } from '@patternfly/react-templates';
|
|
3
3
|
import { Checkbox } from '@patternfly/react-core';
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@ const Options = [
|
|
|
12
12
|
];
|
|
13
13
|
|
|
14
14
|
/* eslint-disable no-console */
|
|
15
|
-
export const SelectTypeaheadDemo:
|
|
15
|
+
export const SelectTypeaheadDemo: FunctionComponent = () => {
|
|
16
16
|
const [selected, setSelected] = useState<string | undefined>();
|
|
17
17
|
const [options, setOptions] = useState(Options);
|
|
18
18
|
const [isCreatable, setIsCreatable] = useState<boolean>(false);
|