@patternfly/react-templates 1.1.0-prerelease.9 → 6.0.0-alpha.10
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 +12 -22
- package/README.md +17 -2
- package/components/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/esm/components/Select/index.d.ts +0 -1
- package/dist/esm/components/Select/index.d.ts.map +1 -1
- package/dist/esm/components/Select/index.js +0 -1
- package/dist/esm/components/Select/index.js.map +1 -1
- package/dist/esm/components/index.d.ts +0 -1
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +0 -1
- package/dist/esm/components/index.js.map +1 -1
- package/dist/js/components/Select/index.d.ts +0 -1
- package/dist/js/components/Select/index.d.ts.map +1 -1
- package/dist/js/components/Select/index.js +0 -1
- package/dist/js/components/Select/index.js.map +1 -1
- package/dist/js/components/index.d.ts +0 -1
- package/dist/js/components/index.d.ts.map +1 -1
- package/dist/js/components/index.js +0 -1
- package/dist/js/components/index.js.map +1 -1
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +7 -6
- package/src/components/Select/__snapshots__/CheckboxSelectSnapshots.test.tsx.snap +38 -38
- package/src/components/Select/examples/SelectTemplates.md +2 -9
- package/src/components/Select/index.ts +0 -1
- package/src/components/index.ts +0 -1
- package/dist/dynamic/components/Dropdown/package.json +0 -1
- package/dist/dynamic-modules.json +0 -15
- package/dist/esm/components/Dropdown/DropdownSimple.d.ts +0 -43
- package/dist/esm/components/Dropdown/DropdownSimple.d.ts.map +0 -1
- package/dist/esm/components/Dropdown/DropdownSimple.js +0 -27
- package/dist/esm/components/Dropdown/DropdownSimple.js.map +0 -1
- package/dist/esm/components/Dropdown/index.d.ts +0 -2
- package/dist/esm/components/Dropdown/index.d.ts.map +0 -1
- package/dist/esm/components/Dropdown/index.js +0 -2
- package/dist/esm/components/Dropdown/index.js.map +0 -1
- package/dist/esm/components/Select/SelectTypeahead.d.ts +0 -29
- package/dist/esm/components/Select/SelectTypeahead.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectTypeahead.js +0 -179
- package/dist/esm/components/Select/SelectTypeahead.js.map +0 -1
- package/dist/js/components/Dropdown/DropdownSimple.d.ts +0 -43
- package/dist/js/components/Dropdown/DropdownSimple.d.ts.map +0 -1
- package/dist/js/components/Dropdown/DropdownSimple.js +0 -31
- package/dist/js/components/Dropdown/DropdownSimple.js.map +0 -1
- package/dist/js/components/Dropdown/index.d.ts +0 -2
- package/dist/js/components/Dropdown/index.d.ts.map +0 -1
- package/dist/js/components/Dropdown/index.js +0 -5
- package/dist/js/components/Dropdown/index.js.map +0 -1
- package/dist/js/components/Select/SelectTypeahead.d.ts +0 -29
- package/dist/js/components/Select/SelectTypeahead.d.ts.map +0 -1
- package/dist/js/components/Select/SelectTypeahead.js +0 -183
- package/dist/js/components/Select/SelectTypeahead.js.map +0 -1
- package/src/components/Dropdown/DropdownSimple.tsx +0 -122
- package/src/components/Dropdown/__tests__/DropdownSimple.test.tsx +0 -254
- package/src/components/Dropdown/__tests__/__snapshots__/DropdownSimple.test.tsx.snap +0 -147
- package/src/components/Dropdown/examples/DropdownSimpleExample.tsx +0 -53
- package/src/components/Dropdown/examples/DropdownTemplates.md +0 -36
- package/src/components/Dropdown/index.ts +0 -1
- package/src/components/Select/SelectTypeahead.tsx +0 -321
- package/src/components/Select/examples/SelectTypeaheadDemo.tsx +0 -21
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DropdownItemProps } from '@patternfly/react-core/dist/esm/components/Dropdown';
|
|
3
|
-
import { OUIAProps } from '@patternfly/react-core/dist/esm/helpers';
|
|
4
|
-
export interface DropdownSimpleItem extends Omit<DropdownItemProps, 'content'> {
|
|
5
|
-
/** Content of the dropdown item. If the isDivider prop is true, this prop will be ignored. */
|
|
6
|
-
content?: React.ReactNode;
|
|
7
|
-
/** Unique identifier for the dropdown item, which is used in the dropdown onSelect callback */
|
|
8
|
-
value: string | number;
|
|
9
|
-
/** Callback for when the dropdown item is clicked. */
|
|
10
|
-
onClick?: (event?: any) => void;
|
|
11
|
-
/** URL to redirect to when the dropdown item is clicked. */
|
|
12
|
-
to?: string;
|
|
13
|
-
/** Flag indicating whether the dropdown item should render as a divider. If true, the item will be rendered without
|
|
14
|
-
* the dropdown item wrapper.
|
|
15
|
-
*/
|
|
16
|
-
isDivider?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface DropdownSimpleProps extends OUIAProps {
|
|
19
|
-
/** Initial items of the dropdown. */
|
|
20
|
-
initialItems?: DropdownSimpleItem[];
|
|
21
|
-
/** @hide Forwarded ref */
|
|
22
|
-
innerRef?: React.Ref<any>;
|
|
23
|
-
/** Flag indicating the dropdown should be disabled. */
|
|
24
|
-
isDisabled?: boolean;
|
|
25
|
-
/** Flag indicated whether the dropdown toggle should take up the full width of its parent. */
|
|
26
|
-
isToggleFullWidth?: boolean;
|
|
27
|
-
/** Callback triggered when any dropdown item is clicked. */
|
|
28
|
-
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void;
|
|
29
|
-
/** Callback triggered when the dropdown toggle opens or closes. */
|
|
30
|
-
onToggle?: (nextIsOpen: boolean) => void;
|
|
31
|
-
/** Flag indicating the dropdown toggle should be focused after a dropdown item is clicked. */
|
|
32
|
-
shouldFocusToggleOnSelect?: boolean;
|
|
33
|
-
/** Adds an accessible name to the dropdown toggle. Required when the dropdown toggle does not
|
|
34
|
-
* have any text content.
|
|
35
|
-
*/
|
|
36
|
-
toggleAriaLabel?: string;
|
|
37
|
-
/** Content of the toggle. */
|
|
38
|
-
toggleContent: React.ReactNode;
|
|
39
|
-
/** Variant style of the dropdown toggle. */
|
|
40
|
-
toggleVariant?: 'default' | 'plain' | 'plainText';
|
|
41
|
-
}
|
|
42
|
-
export declare const DropdownSimple: React.ForwardRefExoticComponent<DropdownSimpleProps & React.RefAttributes<any>>;
|
|
43
|
-
//# sourceMappingURL=Drop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AC9F,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6BAA6B;IAC7B,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC;IAC/B,4CAA4C;IAC5C,aAAa,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;CACnD;AAoED,eAAO,MAAM,cAAc,iFAEzB,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DropdownSimple = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
-
const Dropdown_1 = require('@patternfly/react-core/dist/js/components/Dropdown');
|
|
7
|
-
const MenuToggle_1 = require('@patternfly/react-core/dist/js/components/MenuToggle');
|
|
8
|
-
const Divider_1 = require('@patternfly/react-core/dist/js/components/Divider');
|
|
9
|
-
const helpers_1 = require('@patternfly/react-core/dist/js/helpers');
|
|
10
|
-
const DropdownSimpleBase = (_a) => {
|
|
11
|
-
var { innerRef, initialItems, onSelect: onSelectProp, onToggle: onToggleProp, isDisabled, toggleAriaLabel, toggleContent, isToggleFullWidth, toggleVariant = 'default', shouldFocusToggleOnSelect } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialItems", "onSelect", "onToggle", "isDisabled", "toggleAriaLabel", "toggleContent", "isToggleFullWidth", "toggleVariant", "shouldFocusToggleOnSelect"]);
|
|
12
|
-
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
13
|
-
const onSelect = (event, value) => {
|
|
14
|
-
onSelectProp && onSelectProp(event, value);
|
|
15
|
-
setIsOpen(false);
|
|
16
|
-
};
|
|
17
|
-
const onToggle = () => {
|
|
18
|
-
onToggleProp && onToggleProp(!isOpen);
|
|
19
|
-
setIsOpen(!isOpen);
|
|
20
|
-
};
|
|
21
|
-
const dropdownToggle = (toggleRef) => (react_1.default.createElement(MenuToggle_1.MenuToggle, { ref: toggleRef, onClick: onToggle, isExpanded: isOpen, isDisabled: isDisabled, variant: toggleVariant, "aria-label": toggleAriaLabel, isFullWidth: isToggleFullWidth }, toggleContent));
|
|
22
|
-
const dropdownSimpleItems = initialItems === null || initialItems === void 0 ? void 0 : initialItems.map((item) => {
|
|
23
|
-
const { content, onClick, to, value, isDivider } = item, itemProps = tslib_1.__rest(item, ["content", "onClick", "to", "value", "isDivider"]);
|
|
24
|
-
return isDivider ? (react_1.default.createElement(Divider_1.Divider, { component: "li", key: value })) : (react_1.default.createElement(Dropdown_1.DropdownItem, Object.assign({ onClick: onClick, to: to, key: value, value: value }, itemProps), content));
|
|
25
|
-
});
|
|
26
|
-
return (react_1.default.createElement(Dropdown_1.Dropdown, Object.assign({ toggle: dropdownToggle, isOpen: isOpen, onSelect: onSelect, shouldFocusToggleOnSelect: shouldFocusToggleOnSelect, onOpenChange: (isOpen) => setIsOpen(isOpen), ref: innerRef }, props),
|
|
27
|
-
react_1.default.createElement(Dropdown_1.DropdownList, null, dropdownSimpleItems)));
|
|
28
|
-
};
|
|
29
|
-
exports.DropdownSimple = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(DropdownSimpleBase, Object.assign({}, props, { innerRef: ref }))));
|
|
30
|
-
exports.DropdownSimple.displayName = 'DropdownSimple';
|
|
31
|
-
//# sourceMappingURL=DropdownSimple.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownSimple.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/DropdownSimple.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,iFAK6D;AAC7D,qFAAsG;AACtG,+EAA6E;AAC7E,oEAAoE;AA0CpE,MAAM,kBAAkB,GAAiD,CAAC,EAYpD,EAAE,EAAE;QAZgD,EACxE,QAAQ,EACR,YAAY,EACZ,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,EACtB,UA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AE,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAM,SAAS,GAC5E,OAAO,CACK,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,CACL,8BAAC,mBAAQ,kBACP,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,yBAAyB,EAAE,yBAAyB,EACpD,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAC3C,GAAG,EAAE,QAAQ,IACT,KAAK;QAET,8BAAC,uBAAY,QAAE,mBAAmB,CAAgB,CACzC,CACZ,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,cAAc,GAAG,eAAK,CAAC,UAAU,CAAC,CAAC,KAA0B,EAAE,GAAmB,EAAE,EAAE,CAAC,CAClG,8BAAC,kBAAkB,oBAAK,KAAK,IAAE,QAAQ,EAAE,GAAG,IAAI,CACjD,CAAC,CAAC;AAEH,sBAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { SelectOptionProps } from '@patternfly/react-core';
|
|
3
|
-
export interface SelectTypeaheadOption extends Omit<SelectOptionProps, 'content'> {
|
|
4
|
-
/** Content of the select option. */
|
|
5
|
-
content: string | number;
|
|
6
|
-
/** Value of the select option. */
|
|
7
|
-
value: string | number;
|
|
8
|
-
}
|
|
9
|
-
export interface SelectTypeaheadProps {
|
|
10
|
-
/** @hide Forwarded ref */
|
|
11
|
-
innerRef?: React.Ref<any>;
|
|
12
|
-
/** Initial options of the select. */
|
|
13
|
-
initialOptions: SelectTypeaheadOption[];
|
|
14
|
-
/** Callback triggered on selection. */
|
|
15
|
-
onSelect?: (_event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<HTMLInputElement>, selection: string | number) => void;
|
|
16
|
-
/** Callback triggered when the select opens or closes. */
|
|
17
|
-
onToggle?: (nextIsOpen: boolean) => void;
|
|
18
|
-
/** Callback triggered when the text in the input field changes. */
|
|
19
|
-
onInputChange?: (newValue: string) => void;
|
|
20
|
-
/** Placeholder text for the select input. */
|
|
21
|
-
placeholder?: string;
|
|
22
|
-
/** Message to display when no options match the filter. */
|
|
23
|
-
noOptionsFoundMessage?: string | ((filter: string) => string);
|
|
24
|
-
/** Flag indicating the select should be disabled. */
|
|
25
|
-
isDisabled?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare const SelectTypeaheadBase: React.FunctionComponent<SelectTypeaheadProps>;
|
|
28
|
-
export declare const SelectTypeahead: React.ForwardRefExoticComponent<SelectTypeaheadProps & React.RefAttributes<any>>;
|
|
29
|
-
//# sourceMappingURL=SelectTypeahead.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SelectTypeahead.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/SelectTypeahead.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,EAOlB,MAAM,wBAAwB,CAAC;AAGhC,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC;IAC/E,oCAAoC;IACpC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,qCAAqC;IACrC,cAAc,EAAE,qBAAqB,EAAE,CAAC;IACxC,uCAAuC;IACvC,QAAQ,CAAC,EAAE,CACT,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAC,EACrF,SAAS,EAAE,MAAM,GAAG,MAAM,KACvB,IAAI,CAAC;IACV,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,mEAAmE;IACnE,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,qBAAqB,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IAC9D,qDAAqD;IACrD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CA6Q7E,CAAC;AAGF,eAAO,MAAM,eAAe,kFAE1B,CAAC"}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SelectTypeahead = exports.SelectTypeaheadBase = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
-
const react_core_1 = require("@patternfly/react-core");
|
|
7
|
-
const times_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/times-icon'));
|
|
8
|
-
const SelectTypeaheadBase = (_a) => {
|
|
9
|
-
var { innerRef, initialOptions, onSelect, onToggle, onInputChange, placeholder = 'Select an option', noOptionsFoundMessage = (filter) => `No results found for "${filter}"`, isDisabled } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialOptions", "onSelect", "onToggle", "onInputChange", "placeholder", "noOptionsFoundMessage", "isDisabled"]);
|
|
10
|
-
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
11
|
-
const [selected, setSelected] = react_1.default.useState('');
|
|
12
|
-
const [inputValue, setInputValue] = react_1.default.useState('');
|
|
13
|
-
const [filterValue, setFilterValue] = react_1.default.useState('');
|
|
14
|
-
const [selectOptions, setSelectOptions] = react_1.default.useState(initialOptions);
|
|
15
|
-
const [focusedItemIndex, setFocusedItemIndex] = react_1.default.useState(null);
|
|
16
|
-
const [activeItemId, setActiveItemId] = react_1.default.useState(null);
|
|
17
|
-
const textInputRef = react_1.default.useRef();
|
|
18
|
-
const NO_RESULTS = 'no results';
|
|
19
|
-
react_1.default.useEffect(() => {
|
|
20
|
-
let newSelectOptions = initialOptions;
|
|
21
|
-
// Filter menu items based on the text input value when one exists
|
|
22
|
-
if (filterValue) {
|
|
23
|
-
newSelectOptions = initialOptions.filter((option) => String(option.content).toLowerCase().includes(filterValue.toLowerCase()));
|
|
24
|
-
// When no options are found after filtering, display 'No results found'
|
|
25
|
-
if (!newSelectOptions.length) {
|
|
26
|
-
newSelectOptions = [
|
|
27
|
-
{
|
|
28
|
-
isAriaDisabled: true,
|
|
29
|
-
content: typeof noOptionsFoundMessage === 'string' ? noOptionsFoundMessage : noOptionsFoundMessage(filterValue),
|
|
30
|
-
value: NO_RESULTS
|
|
31
|
-
}
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
// Open the menu when the input value changes and the new value is not empty
|
|
35
|
-
if (!isOpen) {
|
|
36
|
-
openMenu();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
setSelectOptions(newSelectOptions);
|
|
40
|
-
}, [filterValue]);
|
|
41
|
-
const createItemId = (value) => `select-typeahead-${String(value).replace(' ', '-')}`;
|
|
42
|
-
const setActiveAndFocusedItem = (itemIndex) => {
|
|
43
|
-
setFocusedItemIndex(itemIndex);
|
|
44
|
-
const focusedItem = selectOptions[itemIndex];
|
|
45
|
-
setActiveItemId(createItemId(focusedItem.value));
|
|
46
|
-
};
|
|
47
|
-
const resetActiveAndFocusedItem = () => {
|
|
48
|
-
setFocusedItemIndex(null);
|
|
49
|
-
setActiveItemId(null);
|
|
50
|
-
};
|
|
51
|
-
const openMenu = () => {
|
|
52
|
-
onToggle && onToggle(true);
|
|
53
|
-
setIsOpen(true);
|
|
54
|
-
};
|
|
55
|
-
const closeMenu = () => {
|
|
56
|
-
onToggle && onToggle(false);
|
|
57
|
-
setIsOpen(false);
|
|
58
|
-
resetActiveAndFocusedItem();
|
|
59
|
-
};
|
|
60
|
-
const onInputClick = () => {
|
|
61
|
-
if (!isOpen) {
|
|
62
|
-
openMenu();
|
|
63
|
-
}
|
|
64
|
-
else if (!inputValue) {
|
|
65
|
-
closeMenu();
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const selectOption = (_event, option) => {
|
|
69
|
-
onSelect && onSelect(_event, option.value);
|
|
70
|
-
setInputValue(String(option.content));
|
|
71
|
-
setFilterValue('');
|
|
72
|
-
setSelected(String(option.value));
|
|
73
|
-
closeMenu();
|
|
74
|
-
};
|
|
75
|
-
const _onSelect = (_event, value) => {
|
|
76
|
-
if (value && value !== NO_RESULTS) {
|
|
77
|
-
const optionToSelect = selectOptions.find((option) => option.value === value);
|
|
78
|
-
selectOption(_event, optionToSelect);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const onTextInputChange = (_event, value) => {
|
|
82
|
-
setInputValue(value);
|
|
83
|
-
onInputChange && onInputChange(value);
|
|
84
|
-
setFilterValue(value);
|
|
85
|
-
resetActiveAndFocusedItem();
|
|
86
|
-
if (value !== selected) {
|
|
87
|
-
setSelected('');
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const handleMenuArrowKeys = (key) => {
|
|
91
|
-
let indexToFocus = 0;
|
|
92
|
-
if (!isOpen) {
|
|
93
|
-
openMenu();
|
|
94
|
-
}
|
|
95
|
-
if (selectOptions.every((option) => option.isDisabled)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (key === 'ArrowUp') {
|
|
99
|
-
// When no index is set or at the first index, focus to the last, otherwise decrement focus index
|
|
100
|
-
if (focusedItemIndex === null || focusedItemIndex === 0) {
|
|
101
|
-
indexToFocus = selectOptions.length - 1;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
indexToFocus = focusedItemIndex - 1;
|
|
105
|
-
}
|
|
106
|
-
// Skip disabled options
|
|
107
|
-
while (selectOptions[indexToFocus].isDisabled) {
|
|
108
|
-
indexToFocus--;
|
|
109
|
-
if (indexToFocus === -1) {
|
|
110
|
-
indexToFocus = selectOptions.length - 1;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (key === 'ArrowDown') {
|
|
115
|
-
// When no index is set or at the last index, focus to the first, otherwise increment focus index
|
|
116
|
-
if (focusedItemIndex === null || focusedItemIndex === selectOptions.length - 1) {
|
|
117
|
-
indexToFocus = 0;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
indexToFocus = focusedItemIndex + 1;
|
|
121
|
-
}
|
|
122
|
-
// Skip disabled options
|
|
123
|
-
while (selectOptions[indexToFocus].isDisabled) {
|
|
124
|
-
indexToFocus++;
|
|
125
|
-
if (indexToFocus === selectOptions.length) {
|
|
126
|
-
indexToFocus = 0;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
setActiveAndFocusedItem(indexToFocus);
|
|
131
|
-
};
|
|
132
|
-
const onInputKeyDown = (event) => {
|
|
133
|
-
const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
134
|
-
switch (event.key) {
|
|
135
|
-
case 'Enter':
|
|
136
|
-
if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
|
|
137
|
-
selectOption(event, focusedItem);
|
|
138
|
-
}
|
|
139
|
-
if (!isOpen) {
|
|
140
|
-
setIsOpen(true);
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
case 'ArrowUp':
|
|
144
|
-
case 'ArrowDown':
|
|
145
|
-
event.preventDefault();
|
|
146
|
-
handleMenuArrowKeys(event.key);
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const onToggleClick = () => {
|
|
151
|
-
var _a;
|
|
152
|
-
onToggle && onToggle(!isOpen);
|
|
153
|
-
setIsOpen(!isOpen);
|
|
154
|
-
(_a = textInputRef === null || textInputRef === void 0 ? void 0 : textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
155
|
-
};
|
|
156
|
-
const onClearButtonClick = () => {
|
|
157
|
-
var _a;
|
|
158
|
-
setSelected('');
|
|
159
|
-
setInputValue('');
|
|
160
|
-
onInputChange && onInputChange('');
|
|
161
|
-
setFilterValue('');
|
|
162
|
-
resetActiveAndFocusedItem();
|
|
163
|
-
(_a = textInputRef === null || textInputRef === void 0 ? void 0 : textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
164
|
-
};
|
|
165
|
-
const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, { ref: toggleRef, variant: "typeahead", "aria-label": "Typeahead menu toggle", onClick: onToggleClick, isExpanded: isOpen, isDisabled: isDisabled, isFullWidth: true },
|
|
166
|
-
react_1.default.createElement(react_core_1.TextInputGroup, { isPlain: true },
|
|
167
|
-
react_1.default.createElement(react_core_1.TextInputGroupMain, Object.assign({ value: inputValue, onClick: onInputClick, onChange: onTextInputChange, onKeyDown: onInputKeyDown, id: "typeahead-select-input", autoComplete: "off", innerRef: textInputRef, placeholder: placeholder }, (activeItemId && { 'aria-activedescendant': activeItemId }), { role: "combobox", isExpanded: isOpen, "aria-controls": "select-typeahead-listbox" })),
|
|
168
|
-
react_1.default.createElement(react_core_1.TextInputGroupUtilities, Object.assign({}, (!inputValue ? { style: { display: 'none' } } : {})),
|
|
169
|
-
react_1.default.createElement(react_core_1.Button, { variant: "plain", onClick: onClearButtonClick, "aria-label": "Clear input value" },
|
|
170
|
-
react_1.default.createElement(times_icon_1.default, { "aria-hidden": true }))))));
|
|
171
|
-
return (react_1.default.createElement(react_core_1.Select, Object.assign({ id: "typeahead-select", isOpen: isOpen, selected: selected, onSelect: _onSelect, onOpenChange: (isOpen) => {
|
|
172
|
-
!isOpen && closeMenu();
|
|
173
|
-
}, toggle: toggle, shouldFocusFirstItemOnOpen: false, ref: innerRef }, props),
|
|
174
|
-
react_1.default.createElement(react_core_1.SelectList, { id: "select-typeahead-listbox" }, selectOptions.map((option, index) => {
|
|
175
|
-
const { content, value } = option, props = tslib_1.__rest(option, ["content", "value"]);
|
|
176
|
-
return (react_1.default.createElement(react_core_1.SelectOption, Object.assign({}, props, { key: value, value: value, isFocused: focusedItemIndex === index, id: createItemId(value) }), content));
|
|
177
|
-
}))));
|
|
178
|
-
};
|
|
179
|
-
exports.SelectTypeaheadBase = SelectTypeaheadBase;
|
|
180
|
-
exports.SelectTypeaheadBase.displayName = 'SelectTypeaheadBase';
|
|
181
|
-
exports.SelectTypeahead = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(exports.SelectTypeaheadBase, Object.assign({}, props, { innerRef: ref }))));
|
|
182
|
-
exports.SelectTypeahead.displayName = 'SelectTypeahead';
|
|
183
|
-
//# sourceMappingURL=SelectTypeahead.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SelectTypeahead.js","sourceRoot":"","sources":["../../../../src/components/Select/SelectTypeahead.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,uDAWgC;AAChC,0GAA0E;AA+BnE,MAAM,mBAAmB,GAAkD,CAAC,EAU5D,EAAE,EAAE;QAVwD,EACjF,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,WAAW,GAAG,k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AS,CAAC;YAE5C,OAAO,CACL,8BAAC,yBAAY,oBACP,KAAK,IACT,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,gBAAgB,KAAK,KAAK,EACrC,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,KAEtB,OAAO,CACK,CAChB,CAAC;QACJ,CAAC,CAAC,CACS,CACN,CACV,CAAC;AACJ,CAAC,CAAC;AA7QW,QAAA,mBAAmB,uBA6Q9B;AACF,2BAAmB,CAAC,WAAW,GAAG,qBAAqB,CAAC;AAE3C,QAAA,eAAe,GAAG,eAAK,CAAC,UAAU,CAAC,CAAC,KAA2B,EAAE,GAAmB,EAAE,EAAE,CAAC,CACpG,8BAAC,2BAAmB,oBAAK,KAAK,IAAE,QAAQ,EAAE,GAAG,IAAI,CAClD,CAAC,CAAC;AAEH,uBAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Dropdown,
|
|
4
|
-
DropdownItem,
|
|
5
|
-
DropdownList,
|
|
6
|
-
DropdownItemProps
|
|
7
|
-
} from '@patternfly/react-core/dist/esm/components/Dropdown';
|
|
8
|
-
import { MenuToggle, MenuToggleElement } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
9
|
-
import { Divider } from '@patternfly/react-core/dist/esm/components/Divider';
|
|
10
|
-
import { OUIAProps } from '@patternfly/react-core/dist/esm/helpers';
|
|
11
|
-
|
|
12
|
-
export interface DropdownSimpleItem extends Omit<DropdownItemProps, 'content'> {
|
|
13
|
-
/** Content of the dropdown item. If the isDivider prop is true, this prop will be ignored. */
|
|
14
|
-
content?: React.ReactNode;
|
|
15
|
-
/** Unique identifier for the dropdown item, which is used in the dropdown onSelect callback */
|
|
16
|
-
value: string | number;
|
|
17
|
-
/** Callback for when the dropdown item is clicked. */
|
|
18
|
-
onClick?: (event?: any) => void;
|
|
19
|
-
/** URL to redirect to when the dropdown item is clicked. */
|
|
20
|
-
to?: string;
|
|
21
|
-
/** Flag indicating whether the dropdown item should render as a divider. If true, the item will be rendered without
|
|
22
|
-
* the dropdown item wrapper.
|
|
23
|
-
*/
|
|
24
|
-
isDivider?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface DropdownSimpleProps extends OUIAProps {
|
|
28
|
-
/** Initial items of the dropdown. */
|
|
29
|
-
initialItems?: DropdownSimpleItem[];
|
|
30
|
-
/** @hide Forwarded ref */
|
|
31
|
-
innerRef?: React.Ref<any>;
|
|
32
|
-
/** Flag indicating the dropdown should be disabled. */
|
|
33
|
-
isDisabled?: boolean;
|
|
34
|
-
/** Flag indicated whether the dropdown toggle should take up the full width of its parent. */
|
|
35
|
-
isToggleFullWidth?: boolean;
|
|
36
|
-
/** Callback triggered when any dropdown item is clicked. */
|
|
37
|
-
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void;
|
|
38
|
-
/** Callback triggered when the dropdown toggle opens or closes. */
|
|
39
|
-
onToggle?: (nextIsOpen: boolean) => void;
|
|
40
|
-
/** Flag indicating the dropdown toggle should be focused after a dropdown item is clicked. */
|
|
41
|
-
shouldFocusToggleOnSelect?: boolean;
|
|
42
|
-
/** Adds an accessible name to the dropdown toggle. Required when the dropdown toggle does not
|
|
43
|
-
* have any text content.
|
|
44
|
-
*/
|
|
45
|
-
toggleAriaLabel?: string;
|
|
46
|
-
/** Content of the toggle. */
|
|
47
|
-
toggleContent: React.ReactNode;
|
|
48
|
-
/** Variant style of the dropdown toggle. */
|
|
49
|
-
toggleVariant?: 'default' | 'plain' | 'plainText';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const DropdownSimpleBase: React.FunctionComponent<DropdownSimpleProps> = ({
|
|
53
|
-
innerRef,
|
|
54
|
-
initialItems,
|
|
55
|
-
onSelect: onSelectProp,
|
|
56
|
-
onToggle: onToggleProp,
|
|
57
|
-
isDisabled,
|
|
58
|
-
toggleAriaLabel,
|
|
59
|
-
toggleContent,
|
|
60
|
-
isToggleFullWidth,
|
|
61
|
-
toggleVariant = 'default',
|
|
62
|
-
shouldFocusToggleOnSelect,
|
|
63
|
-
...props
|
|
64
|
-
}: DropdownSimpleProps) => {
|
|
65
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
|
66
|
-
|
|
67
|
-
const onSelect = (event: React.MouseEvent<Element, MouseEvent>, value: string | number) => {
|
|
68
|
-
onSelectProp && onSelectProp(event, value);
|
|
69
|
-
setIsOpen(false);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const onToggle = () => {
|
|
73
|
-
onToggleProp && onToggleProp(!isOpen);
|
|
74
|
-
setIsOpen(!isOpen);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const dropdownToggle = (toggleRef: React.Ref<MenuToggleElement>) => (
|
|
78
|
-
<MenuToggle
|
|
79
|
-
ref={toggleRef}
|
|
80
|
-
onClick={onToggle}
|
|
81
|
-
isExpanded={isOpen}
|
|
82
|
-
isDisabled={isDisabled}
|
|
83
|
-
variant={toggleVariant}
|
|
84
|
-
aria-label={toggleAriaLabel}
|
|
85
|
-
isFullWidth={isToggleFullWidth}
|
|
86
|
-
>
|
|
87
|
-
{toggleContent}
|
|
88
|
-
</MenuToggle>
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const dropdownSimpleItems = initialItems?.map((item) => {
|
|
92
|
-
const { content, onClick, to, value, isDivider, ...itemProps } = item;
|
|
93
|
-
|
|
94
|
-
return isDivider ? (
|
|
95
|
-
<Divider component="li" key={value} />
|
|
96
|
-
) : (
|
|
97
|
-
<DropdownItem onClick={onClick} to={to} key={value} value={value} {...itemProps}>
|
|
98
|
-
{content}
|
|
99
|
-
</DropdownItem>
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<Dropdown
|
|
105
|
-
toggle={dropdownToggle}
|
|
106
|
-
isOpen={isOpen}
|
|
107
|
-
onSelect={onSelect}
|
|
108
|
-
shouldFocusToggleOnSelect={shouldFocusToggleOnSelect}
|
|
109
|
-
onOpenChange={(isOpen) => setIsOpen(isOpen)}
|
|
110
|
-
ref={innerRef}
|
|
111
|
-
{...props}
|
|
112
|
-
>
|
|
113
|
-
<DropdownList>{dropdownSimpleItems}</DropdownList>
|
|
114
|
-
</Dropdown>
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export const DropdownSimple = React.forwardRef((props: DropdownSimpleProps, ref: React.Ref<any>) => (
|
|
119
|
-
<DropdownSimpleBase {...props} innerRef={ref} />
|
|
120
|
-
));
|
|
121
|
-
|
|
122
|
-
DropdownSimple.displayName = 'DropdownSimple';
|