@patternfly/react-templates 1.1.0-prerelease.4 → 1.1.0-prerelease.40
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 +170 -0
- package/README.md +2 -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 +14 -3
- package/dist/esm/components/Dropdown/SimpleDropdown.d.ts +48 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.d.ts.map +1 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.js +33 -0
- package/dist/esm/components/Dropdown/SimpleDropdown.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.d.ts +7 -3
- package/dist/esm/components/Select/CheckboxSelect.d.ts.map +1 -1
- package/dist/esm/components/Select/CheckboxSelect.js +14 -6
- package/dist/esm/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts +33 -0
- package/dist/esm/components/Select/MultiTypeaheadSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/MultiTypeaheadSelect.js +186 -0
- package/dist/esm/components/Select/MultiTypeaheadSelect.js.map +1 -0
- package/dist/esm/components/Select/{SelectSimple.d.ts → SimpleSelect.d.ts} +12 -7
- package/dist/esm/components/Select/SimpleSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/SimpleSelect.js +39 -0
- package/dist/esm/components/Select/SimpleSelect.js.map +1 -0
- package/dist/esm/components/Select/TypeaheadSelect.d.ts +47 -0
- package/dist/esm/components/Select/TypeaheadSelect.d.ts.map +1 -0
- package/dist/esm/components/Select/TypeaheadSelect.js +228 -0
- package/dist/esm/components/Select/TypeaheadSelect.js.map +1 -0
- package/dist/esm/components/Select/index.d.ts +3 -1
- package/dist/esm/components/Select/index.d.ts.map +1 -1
- package/dist/esm/components/Select/index.js +3 -1
- 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/SimpleDropdown.d.ts +48 -0
- package/dist/js/components/Dropdown/SimpleDropdown.d.ts.map +1 -0
- package/dist/js/components/Dropdown/SimpleDropdown.js +36 -0
- package/dist/js/components/Dropdown/SimpleDropdown.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.d.ts +7 -3
- package/dist/js/components/Select/CheckboxSelect.d.ts.map +1 -1
- package/dist/js/components/Select/CheckboxSelect.js +14 -6
- package/dist/js/components/Select/CheckboxSelect.js.map +1 -1
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts +33 -0
- package/dist/js/components/Select/MultiTypeaheadSelect.d.ts.map +1 -0
- package/dist/js/components/Select/MultiTypeaheadSelect.js +190 -0
- package/dist/js/components/Select/MultiTypeaheadSelect.js.map +1 -0
- package/dist/js/components/Select/{SelectSimple.d.ts → SimpleSelect.d.ts} +12 -7
- package/dist/js/components/Select/SimpleSelect.d.ts.map +1 -0
- package/dist/js/components/Select/SimpleSelect.js +42 -0
- package/dist/js/components/Select/SimpleSelect.js.map +1 -0
- package/dist/js/components/Select/TypeaheadSelect.d.ts +47 -0
- package/dist/js/components/Select/TypeaheadSelect.d.ts.map +1 -0
- package/dist/js/components/Select/TypeaheadSelect.js +232 -0
- package/dist/js/components/Select/TypeaheadSelect.js.map +1 -0
- package/dist/js/components/Select/index.d.ts +3 -1
- package/dist/js/components/Select/index.d.ts.map +1 -1
- package/dist/js/components/Select/index.js +3 -1
- 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-Cfyy993h.css +26066 -0
- package/dist/umd/react-templates.min.js +1 -1
- package/package.json +7 -10
- package/rollup.config.mjs +8 -0
- package/src/components/Dropdown/SimpleDropdown.tsx +139 -0
- package/src/components/Dropdown/__tests__/SimpleDropdown.test.tsx +266 -0
- package/src/components/Dropdown/__tests__/__snapshots__/SimpleDropdown.test.tsx.snap +153 -0
- package/src/components/Dropdown/examples/DropdownTemplates.md +24 -0
- package/src/components/Dropdown/examples/SimpleDropdownExample.tsx +53 -0
- package/src/components/Dropdown/index.ts +1 -0
- package/src/components/Select/CheckboxSelect.tsx +23 -7
- package/src/components/Select/MultiTypeaheadSelect.tsx +348 -0
- package/src/components/Select/{SelectSimple.tsx → SimpleSelect.tsx} +39 -18
- package/src/components/Select/TypeaheadSelect.tsx +393 -0
- package/src/components/Select/{CheckboxSelect.test.tsx → __tests__/CheckboxSelect.test.tsx} +32 -3
- package/src/components/Select/{CheckboxSelectSnapshots.test.tsx → __tests__/CheckboxSelectSnapshots.test.tsx} +1 -1
- package/src/components/Select/__tests__/MultiTypeaheadSelect.test.tsx +412 -0
- package/src/components/Select/__tests__/SimpleSelect.test.tsx +242 -0
- package/src/components/Select/__tests__/TypeaheadSelect.test.tsx +372 -0
- package/src/components/Select/{__snapshots__ → __tests__/__snapshots__}/CheckboxSelectSnapshots.test.tsx.snap +7 -2
- package/src/components/Select/__tests__/__snapshots__/MultiTypeaheadSelect.test.tsx.snap +180 -0
- package/src/components/Select/__tests__/__snapshots__/SimpleSelect.test.tsx.snap +170 -0
- package/src/components/Select/__tests__/__snapshots__/TypeaheadSelect.test.tsx.snap +180 -0
- package/src/components/Select/examples/CheckboxSelectDemo.tsx +25 -8
- package/src/components/Select/examples/MultiTypeaheadSelectDemo.tsx +35 -0
- package/src/components/Select/examples/SelectTemplates.md +20 -4
- package/src/components/Select/examples/SimpleSelectDemo.tsx +36 -0
- package/src/components/Select/examples/TypeaheadSelectDemo.tsx +67 -0
- package/src/components/Select/index.ts +3 -1
- package/src/components/index.ts +1 -0
- package/dist/esm/components/Select/SelectSimple.d.ts.map +0 -1
- package/dist/esm/components/Select/SelectSimple.js +0 -31
- package/dist/esm/components/Select/SelectSimple.js.map +0 -1
- package/dist/js/components/Select/SelectSimple.d.ts.map +0 -1
- package/dist/js/components/Select/SelectSimple.js +0 -34
- package/dist/js/components/Select/SelectSimple.js.map +0 -1
- package/rollup.config.js +0 -7
- package/src/components/Select/examples/SelectSimpleDemo.tsx +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DropdownItemProps, DropdownProps } from '@patternfly/react-core/dist/esm/components/Dropdown';
|
|
3
|
+
import { MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
4
|
+
import { OUIAProps } from '@patternfly/react-core/dist/esm/helpers';
|
|
5
|
+
export interface SimpleDropdownItem extends Omit<DropdownItemProps, 'content'> {
|
|
6
|
+
/** Content of the dropdown item. If the isDivider prop is true, this prop will be ignored. */
|
|
7
|
+
content?: React.ReactNode;
|
|
8
|
+
/** Unique identifier for the dropdown item, which is used in the dropdown onSelect callback */
|
|
9
|
+
value: string | number;
|
|
10
|
+
/** Callback for when the dropdown item is clicked. */
|
|
11
|
+
onClick?: (event?: any) => void;
|
|
12
|
+
/** URL to redirect to when the dropdown item is clicked. */
|
|
13
|
+
to?: string;
|
|
14
|
+
/** Flag indicating whether the dropdown item should render as a divider. If true, the item will be rendered without
|
|
15
|
+
* the dropdown item wrapper.
|
|
16
|
+
*/
|
|
17
|
+
isDivider?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface SimpleDropdownProps extends Omit<DropdownProps, 'toggle'>, OUIAProps {
|
|
20
|
+
/** Initial items of the dropdown. */
|
|
21
|
+
initialItems?: SimpleDropdownItem[];
|
|
22
|
+
/** @hide Forwarded ref */
|
|
23
|
+
innerRef?: React.Ref<any>;
|
|
24
|
+
/** Flag indicating the dropdown should be disabled. */
|
|
25
|
+
isDisabled?: boolean;
|
|
26
|
+
/** Flag indicated whether the dropdown toggle should take up the full width of its parent. */
|
|
27
|
+
isToggleFullWidth?: boolean;
|
|
28
|
+
/** Callback triggered when any dropdown item is clicked. */
|
|
29
|
+
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void;
|
|
30
|
+
/** Callback triggered when the dropdown toggle opens or closes. */
|
|
31
|
+
onToggle?: (nextIsOpen: boolean) => void;
|
|
32
|
+
/** Flag indicating the dropdown toggle should be focused after a dropdown item is clicked. */
|
|
33
|
+
shouldFocusToggleOnSelect?: boolean;
|
|
34
|
+
/** Adds an accessible name to the dropdown toggle. Required when the dropdown toggle does not
|
|
35
|
+
* have any text content.
|
|
36
|
+
*/
|
|
37
|
+
toggleAriaLabel?: string;
|
|
38
|
+
/** Content of the toggle. */
|
|
39
|
+
toggleContent: React.ReactNode;
|
|
40
|
+
/** Variant style of the dropdown toggle. */
|
|
41
|
+
toggleVariant?: 'default' | 'plain' | 'plainText';
|
|
42
|
+
/** Width of the toggle. */
|
|
43
|
+
toggleWidth?: string;
|
|
44
|
+
/** Additional props passed to the toggle. */
|
|
45
|
+
toggleProps?: MenuToggleProps;
|
|
46
|
+
}
|
|
47
|
+
export declare const SimpleDropdown: React.ForwardRefExoticComponent<SimpleDropdownProps & React.RefAttributes<any>>;
|
|
48
|
+
//# sourceMappingURL=SimpleDropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleDropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/SimpleDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,EACjB,aAAa,EACd,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAiC,eAAe,EAAE,MAAM,uDAAuD,CAAC;AAEvH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC;IAC5E,8FAA8F;IAC9F,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,+FAA+F;IAC/F,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,sDAAsD;IACtD,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,4DAA4D;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,SAAS;IACnF,qCAAqC;IACrC,YAAY,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACpC,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,8FAA8F;IAC9F,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;IAC5F,mEAAmE;IACnE,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,8FAA8F;IAC9F,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;IAClD,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAgFD,eAAO,MAAM,cAAc,iFAEzB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleDropdown = 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 SimpleDropdownBase = (_a) => {
|
|
10
|
+
var { innerRef, initialItems, onSelect: onSelectProp, onToggle: onToggleProp, isDisabled, toggleAriaLabel, toggleContent, isToggleFullWidth, toggleVariant = 'default', toggleWidth, toggleProps, shouldFocusToggleOnSelect } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialItems", "onSelect", "onToggle", "isDisabled", "toggleAriaLabel", "toggleContent", "isToggleFullWidth", "toggleVariant", "toggleWidth", "toggleProps", "shouldFocusToggleOnSelect"]);
|
|
11
|
+
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
12
|
+
const onSelect = (event, value) => {
|
|
13
|
+
onSelectProp && onSelectProp(event, value);
|
|
14
|
+
onToggleProp && onToggleProp(false);
|
|
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, Object.assign({ ref: toggleRef, onClick: onToggle, isExpanded: isOpen, isDisabled: isDisabled, variant: toggleVariant, "aria-label": toggleAriaLabel, isFullWidth: isToggleFullWidth, style: {
|
|
22
|
+
width: toggleWidth
|
|
23
|
+
} }, toggleProps), toggleContent));
|
|
24
|
+
const dropdownSimpleItems = initialItems === null || initialItems === void 0 ? void 0 : initialItems.map((item) => {
|
|
25
|
+
const { content, onClick, to, value, isDivider } = item, itemProps = tslib_1.__rest(item, ["content", "onClick", "to", "value", "isDivider"]);
|
|
26
|
+
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));
|
|
27
|
+
});
|
|
28
|
+
return (react_1.default.createElement(Dropdown_1.Dropdown, Object.assign({ toggle: dropdownToggle, isOpen: isOpen, onSelect: onSelect, shouldFocusToggleOnSelect: shouldFocusToggleOnSelect, onOpenChange: (isOpen) => {
|
|
29
|
+
onToggleProp && onToggleProp(isOpen);
|
|
30
|
+
setIsOpen(isOpen);
|
|
31
|
+
}, ref: innerRef }, props),
|
|
32
|
+
react_1.default.createElement(Dropdown_1.DropdownList, null, dropdownSimpleItems)));
|
|
33
|
+
};
|
|
34
|
+
exports.SimpleDropdown = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(SimpleDropdownBase, Object.assign({}, props, { innerRef: ref }))));
|
|
35
|
+
exports.SimpleDropdown.displayName = 'SimpleDropdown';
|
|
36
|
+
//# sourceMappingURL=SimpleDropdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleDropdown.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/SimpleDropdown.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;;;;AAwD1B,MAAM,kBAAkB,GAAiD,CAAC,EAcpD,EAAE,EAAE;QAdgD,EACxE,QAAQ,EACR,YAAY,EACZ,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,EACtB,UAAU,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,aAAa,GAAG,SAAS,EACzB,WAAW,EACX,WAAW,EACX,yBAAyB,OAEL,EADjB,KAAK,sBAbgE,uMAczE,CADS;IAER,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElD,MAAM,QAAQ,GAAG,CAAC,KAA4C,EAAE,KAAsB,EAAE,EAAE;QACxF,YAAY,IAAI,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3C,YAAY,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QACpC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,YAAY,IAAI,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;QACtC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAC,SAAuC,EAAE,EAAE,CAAC,CAClE,8BAAC,uBAAU,kBACT,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,QAAQ,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,aAAa,gBACV,eAAe,EAC3B,WAAW,EAAE,iBAAiB,EAC9B,KAAK,EACH;YACE,KAAK,EAAE,WAAW;SACI,IA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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SelectOptionProps } from '@patternfly/react-core';
|
|
2
|
+
import { MenuToggleProps, SelectOptionProps, SelectProps } from '@patternfly/react-core';
|
|
3
3
|
export interface CheckboxSelectOption extends Omit<SelectOptionProps, 'content'> {
|
|
4
4
|
/** Content of the select option. */
|
|
5
5
|
content: React.ReactNode;
|
|
6
6
|
/** Value of the select option. */
|
|
7
7
|
value: string | number;
|
|
8
8
|
}
|
|
9
|
-
export interface CheckboxSelectProps {
|
|
9
|
+
export interface CheckboxSelectProps extends Omit<SelectProps, 'toggle'> {
|
|
10
10
|
/** @hide Forwarded ref */
|
|
11
11
|
innerRef?: React.Ref<any>;
|
|
12
12
|
/** Initial options of the select. */
|
|
@@ -17,8 +17,12 @@ export interface CheckboxSelectProps {
|
|
|
17
17
|
onToggle?: (nextIsOpen: boolean) => void;
|
|
18
18
|
/** Flag indicating the select should be disabled. */
|
|
19
19
|
isDisabled?: boolean;
|
|
20
|
-
/** Content of the toggle. Defaults to
|
|
20
|
+
/** Content of the toggle. Defaults to a string with badge count of selected options. */
|
|
21
21
|
toggleContent?: React.ReactNode;
|
|
22
|
+
/** Width of the toggle. */
|
|
23
|
+
toggleWidth?: string;
|
|
24
|
+
/** Additional props passed to the toggle. */
|
|
25
|
+
toggleProps?: MenuToggleProps;
|
|
22
26
|
}
|
|
23
27
|
export declare const CheckboxSelect: React.ForwardRefExoticComponent<CheckboxSelectProps & React.RefAttributes<any>>;
|
|
24
28
|
//# sourceMappingURL=CheckboxSelect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/CheckboxSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"CheckboxSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/CheckboxSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,eAAe,EAIf,iBAAiB,EACjB,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC;IAC9E,oCAAoC;IACpC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC;IACtE,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,qCAAqC;IACrC,cAAc,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACxC,uCAAuC;IACvC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;IAC5F,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,qDAAqD;IACrD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,wFAAwF;IACxF,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAyFD,eAAO,MAAM,cAAc,iFAEzB,CAAC"}
|
|
@@ -5,13 +5,18 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const react_core_1 = require("@patternfly/react-core");
|
|
7
7
|
const CheckboxSelectBase = (_a) => {
|
|
8
|
-
var { innerRef, initialOptions, isDisabled, onSelect: passedOnSelect, onToggle, toggleContent } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialOptions", "isDisabled", "onSelect", "onToggle", "toggleContent"]);
|
|
8
|
+
var { innerRef, initialOptions, isDisabled, onSelect: passedOnSelect, onToggle, toggleContent, toggleWidth = '200px', toggleProps } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialOptions", "isDisabled", "onSelect", "onToggle", "toggleContent", "toggleWidth", "toggleProps"]);
|
|
9
9
|
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
10
10
|
const [selected, setSelected] = react_1.default.useState([]);
|
|
11
|
+
react_1.default.useEffect(() => {
|
|
12
|
+
var _a;
|
|
13
|
+
const selectedOptions = initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.filter((option) => option.selected);
|
|
14
|
+
setSelected((_a = selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.map((selectedOption) => String(selectedOption.value))) !== null && _a !== void 0 ? _a : []);
|
|
15
|
+
}, [initialOptions]);
|
|
11
16
|
const checkboxSelectOptions = initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.map((option) => {
|
|
12
17
|
const { content, value } = option, props = tslib_1.__rest(option, ["content", "value"]);
|
|
13
18
|
const isSelected = selected.includes(`${value}`);
|
|
14
|
-
return (react_1.default.createElement(react_core_1.SelectOption, Object.assign({
|
|
19
|
+
return (react_1.default.createElement(react_core_1.SelectOption, Object.assign({ value: value, key: value, hasCheckbox: true, isSelected: isSelected }, props), content));
|
|
15
20
|
});
|
|
16
21
|
const onToggleClick = () => {
|
|
17
22
|
onToggle && onToggle(!isOpen);
|
|
@@ -30,10 +35,13 @@ const CheckboxSelectBase = (_a) => {
|
|
|
30
35
|
const defaultToggleContent = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
31
36
|
"Filter by status",
|
|
32
37
|
selected.length > 0 && react_1.default.createElement(react_core_1.Badge, { isRead: true }, selected.length)));
|
|
33
|
-
const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, { ref: toggleRef, onClick: onToggleClick, isExpanded: isOpen, isDisabled: isDisabled, style: {
|
|
34
|
-
width:
|
|
35
|
-
} }, toggleContent || defaultToggleContent));
|
|
36
|
-
return (react_1.default.createElement(react_core_1.Select, Object.assign({
|
|
38
|
+
const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, Object.assign({ ref: toggleRef, onClick: onToggleClick, isExpanded: isOpen, isDisabled: isDisabled, style: {
|
|
39
|
+
width: toggleWidth
|
|
40
|
+
} }, toggleProps), toggleContent || defaultToggleContent));
|
|
41
|
+
return (react_1.default.createElement(react_core_1.Select, Object.assign({ isOpen: isOpen, selected: selected, onSelect: onSelect, onOpenChange: (isOpen) => {
|
|
42
|
+
onToggle && onToggle(isOpen);
|
|
43
|
+
setIsOpen(isOpen);
|
|
44
|
+
}, toggle: toggle, ref: innerRef, role: "menu" }, props),
|
|
37
45
|
react_1.default.createElement(react_core_1.SelectList, null, checkboxSelectOptions)));
|
|
38
46
|
};
|
|
39
47
|
exports.CheckboxSelect = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(CheckboxSelectBase, Object.assign({}, props, { innerRef: ref }))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxSelect.js","sourceRoot":"","sources":["../../../../src/components/Select/CheckboxSelect.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"CheckboxSelect.js","sourceRoot":"","sources":["../../../../src/components/Select/CheckboxSelect.tsx"],"names":[],"mappings":";;;;AA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Q,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE;YACvB,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7B,SAAS,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC,EACD,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,QAAQ,EACb,IAAI,EAAC,MAAM,IACP,KAAK;QAET,8BAAC,uBAAU,QAAE,qBAAqB,CAAc,CACzC,CACV,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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectOptionProps, MenuToggleProps, SelectProps } from '@patternfly/react-core';
|
|
3
|
+
export interface MultiTypeaheadSelectOption 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 MultiTypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSelect'> {
|
|
10
|
+
/** @hide Forwarded ref */
|
|
11
|
+
innerRef?: React.Ref<any>;
|
|
12
|
+
/** Initial options of the select. */
|
|
13
|
+
initialOptions: MultiTypeaheadSelectOption[];
|
|
14
|
+
/** Callback triggered on selection. */
|
|
15
|
+
onSelectionChange?: (_event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<HTMLInputElement>, selections: (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
|
+
/** Width of the toggle. */
|
|
27
|
+
toggleWidth?: string;
|
|
28
|
+
/** Additional props passed to the toggle. */
|
|
29
|
+
toggleProps?: MenuToggleProps;
|
|
30
|
+
}
|
|
31
|
+
export declare const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSelectProps>;
|
|
32
|
+
export declare const MultiTypeaheadSelect: React.ForwardRefExoticComponent<MultiTypeaheadSelectProps & React.RefAttributes<any>>;
|
|
33
|
+
//# sourceMappingURL=MultiTypeaheadSelect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiTypeaheadSelect.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/MultiTypeaheadSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAIL,iBAAiB,EAOjB,eAAe,EACf,WAAW,EAGZ,MAAM,wBAAwB,CAAC;AAGhC,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC;IACpF,oCAAoC;IACpC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,UAAU,CAAC;IACzF,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,qCAAqC;IACrC,cAAc,EAAE,0BAA0B,EAAE,CAAC;IAC7C,uCAAuC;IACvC,iBAAiB,CAAC,EAAE,CAClB,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAC,EACrF,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAC5B,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;IACrB,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,iBAAiB,CAAC,yBAAyB,CA+RvF,CAAC;AAIF,eAAO,MAAM,oBAAoB,uFAE/B,CAAC"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiTypeaheadSelect = exports.MultiTypeaheadSelectBase = 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 MultiTypeaheadSelectBase = (_a) => {
|
|
9
|
+
var _b;
|
|
10
|
+
var { innerRef, initialOptions, onSelectionChange, onToggle, onInputChange, placeholder = 'Select an option', noOptionsFoundMessage = (filter) => `No results found for "${filter}"`, isDisabled, toggleWidth, toggleProps } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialOptions", "onSelectionChange", "onToggle", "onInputChange", "placeholder", "noOptionsFoundMessage", "isDisabled", "toggleWidth", "toggleProps"]);
|
|
11
|
+
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
12
|
+
const [selected, setSelected] = react_1.default.useState(((_b = initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.filter((o) => o.selected)) !== null && _b !== void 0 ? _b : []).map((o) => o.value));
|
|
13
|
+
const [inputValue, setInputValue] = 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
|
+
const openMenu = () => {
|
|
20
|
+
onToggle && onToggle(true);
|
|
21
|
+
setIsOpen(true);
|
|
22
|
+
};
|
|
23
|
+
react_1.default.useEffect(() => {
|
|
24
|
+
let newSelectOptions = initialOptions;
|
|
25
|
+
// Filter menu items based on the text input value when one exists
|
|
26
|
+
if (inputValue) {
|
|
27
|
+
newSelectOptions = initialOptions.filter((option) => String(option.content).toLowerCase().includes(inputValue.toLowerCase()));
|
|
28
|
+
// When no options are found after filtering, display 'No results found'
|
|
29
|
+
if (!newSelectOptions.length) {
|
|
30
|
+
newSelectOptions = [
|
|
31
|
+
{
|
|
32
|
+
isAriaDisabled: true,
|
|
33
|
+
content: typeof noOptionsFoundMessage === 'string' ? noOptionsFoundMessage : noOptionsFoundMessage(inputValue),
|
|
34
|
+
value: NO_RESULTS
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
// Open the menu when the input value changes and the new value is not empty
|
|
39
|
+
openMenu();
|
|
40
|
+
}
|
|
41
|
+
setSelectOptions(newSelectOptions);
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
}, [inputValue, initialOptions]);
|
|
44
|
+
react_1.default.useEffect(() => { var _a; return setSelected(((_a = initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.filter((o) => o.selected)) !== null && _a !== void 0 ? _a : []).map((o) => o.value)); }, [initialOptions]);
|
|
45
|
+
const setActiveAndFocusedItem = (itemIndex) => {
|
|
46
|
+
setFocusedItemIndex(itemIndex);
|
|
47
|
+
const focusedItem = selectOptions[itemIndex];
|
|
48
|
+
setActiveItemId(focusedItem.value);
|
|
49
|
+
};
|
|
50
|
+
const resetActiveAndFocusedItem = () => {
|
|
51
|
+
setFocusedItemIndex(null);
|
|
52
|
+
setActiveItemId(null);
|
|
53
|
+
};
|
|
54
|
+
const closeMenu = () => {
|
|
55
|
+
onToggle && onToggle(false);
|
|
56
|
+
setIsOpen(false);
|
|
57
|
+
resetActiveAndFocusedItem();
|
|
58
|
+
setInputValue('');
|
|
59
|
+
};
|
|
60
|
+
const onInputClick = () => {
|
|
61
|
+
if (!isOpen) {
|
|
62
|
+
openMenu();
|
|
63
|
+
}
|
|
64
|
+
else if (!inputValue) {
|
|
65
|
+
closeMenu();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const selectOption = (_event, option) => {
|
|
69
|
+
const selections = selected.includes(option) ? selected.filter((o) => option !== o) : [...selected, option];
|
|
70
|
+
onSelectionChange && onSelectionChange(_event, selections);
|
|
71
|
+
setSelected(selections);
|
|
72
|
+
};
|
|
73
|
+
const clearOption = (_event, option) => {
|
|
74
|
+
const selections = selected.filter((o) => option !== o);
|
|
75
|
+
onSelectionChange && onSelectionChange(_event, selections);
|
|
76
|
+
setSelected(selections);
|
|
77
|
+
};
|
|
78
|
+
const _onSelect = (_event, value) => {
|
|
79
|
+
if (value && value !== NO_RESULTS) {
|
|
80
|
+
selectOption(_event, value);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const onTextInputChange = (_event, value) => {
|
|
84
|
+
setInputValue(value);
|
|
85
|
+
onInputChange && onInputChange(value);
|
|
86
|
+
resetActiveAndFocusedItem();
|
|
87
|
+
};
|
|
88
|
+
const handleMenuArrowKeys = (key) => {
|
|
89
|
+
let indexToFocus = 0;
|
|
90
|
+
if (!isOpen) {
|
|
91
|
+
openMenu();
|
|
92
|
+
}
|
|
93
|
+
if (selectOptions.every((option) => option.isDisabled)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (key === 'ArrowUp') {
|
|
97
|
+
// When no index is set or at the first index, focus to the last, otherwise decrement focus index
|
|
98
|
+
if (focusedItemIndex === null || focusedItemIndex === 0) {
|
|
99
|
+
indexToFocus = selectOptions.length - 1;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
indexToFocus = focusedItemIndex - 1;
|
|
103
|
+
}
|
|
104
|
+
// Skip disabled options
|
|
105
|
+
while (selectOptions[indexToFocus].isDisabled) {
|
|
106
|
+
indexToFocus--;
|
|
107
|
+
if (indexToFocus === -1) {
|
|
108
|
+
indexToFocus = selectOptions.length - 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (key === 'ArrowDown') {
|
|
113
|
+
// When no index is set or at the last index, focus to the first, otherwise increment focus index
|
|
114
|
+
if (focusedItemIndex === null || focusedItemIndex === selectOptions.length - 1) {
|
|
115
|
+
indexToFocus = 0;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
indexToFocus = focusedItemIndex + 1;
|
|
119
|
+
}
|
|
120
|
+
// Skip disabled options
|
|
121
|
+
while (selectOptions[indexToFocus].isDisabled) {
|
|
122
|
+
indexToFocus++;
|
|
123
|
+
if (indexToFocus === selectOptions.length) {
|
|
124
|
+
indexToFocus = 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
setActiveAndFocusedItem(indexToFocus);
|
|
129
|
+
};
|
|
130
|
+
const onInputKeyDown = (event) => {
|
|
131
|
+
const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
132
|
+
switch (event.key) {
|
|
133
|
+
case 'Enter':
|
|
134
|
+
if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
|
|
135
|
+
selectOption(event, focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.value);
|
|
136
|
+
}
|
|
137
|
+
if (!isOpen) {
|
|
138
|
+
onToggle && onToggle(true);
|
|
139
|
+
setIsOpen(true);
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
case 'ArrowUp':
|
|
143
|
+
case 'ArrowDown':
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
handleMenuArrowKeys(event.key);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const onToggleClick = () => {
|
|
150
|
+
var _a;
|
|
151
|
+
onToggle && onToggle(!isOpen);
|
|
152
|
+
setIsOpen(!isOpen);
|
|
153
|
+
(_a = textInputRef === null || textInputRef === void 0 ? void 0 : textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
154
|
+
};
|
|
155
|
+
const onClearButtonClick = (ev) => {
|
|
156
|
+
var _a;
|
|
157
|
+
setSelected([]);
|
|
158
|
+
onInputChange && onInputChange('');
|
|
159
|
+
resetActiveAndFocusedItem();
|
|
160
|
+
(_a = textInputRef === null || textInputRef === void 0 ? void 0 : textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
161
|
+
onSelectionChange && onSelectionChange(ev, []);
|
|
162
|
+
};
|
|
163
|
+
const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, Object.assign({ ref: toggleRef, variant: "typeahead", "aria-label": "Multi select Typeahead menu toggle", onClick: onToggleClick, isExpanded: isOpen, isDisabled: isDisabled, isFullWidth: true, style: {
|
|
164
|
+
width: toggleWidth
|
|
165
|
+
} }, toggleProps),
|
|
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, 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.ChipGroup, { "aria-label": "Current selections" }, selected.map((selection, index) => {
|
|
169
|
+
var _a;
|
|
170
|
+
return (react_1.default.createElement(react_core_1.Chip, { key: index, "datatest-id": `${selection}-chip`, onClick: (ev) => {
|
|
171
|
+
ev.stopPropagation();
|
|
172
|
+
clearOption(ev, selection);
|
|
173
|
+
} }, (_a = initialOptions.find((o) => o.value === selection)) === null || _a === void 0 ? void 0 : _a.content));
|
|
174
|
+
}))),
|
|
175
|
+
react_1.default.createElement(react_core_1.TextInputGroupUtilities, Object.assign({}, (selected.length === 0 ? { style: { display: 'none' } } : {})),
|
|
176
|
+
react_1.default.createElement(react_core_1.Button, { variant: "plain", onClick: onClearButtonClick, "aria-label": "Clear input value" },
|
|
177
|
+
react_1.default.createElement(times_icon_1.default, { "aria-hidden": true }))))));
|
|
178
|
+
return (react_1.default.createElement(react_core_1.Select, Object.assign({ isOpen: isOpen, selected: selected, onSelect: _onSelect, onOpenChange: (isOpen) => {
|
|
179
|
+
!isOpen && closeMenu();
|
|
180
|
+
}, toggle: toggle, shouldFocusFirstItemOnOpen: false, ref: innerRef }, props),
|
|
181
|
+
react_1.default.createElement(react_core_1.SelectList, null, selectOptions.map((option, index) => {
|
|
182
|
+
const { content, value } = option, props = tslib_1.__rest(option, ["content", "value"]);
|
|
183
|
+
return (react_1.default.createElement(react_core_1.SelectOption, Object.assign({ key: value, value: value, isFocused: focusedItemIndex === index }, props), content));
|
|
184
|
+
}))));
|
|
185
|
+
};
|
|
186
|
+
exports.MultiTypeaheadSelectBase = MultiTypeaheadSelectBase;
|
|
187
|
+
exports.MultiTypeaheadSelectBase.displayName = 'MultiTypeaheadSelectBase';
|
|
188
|
+
exports.MultiTypeaheadSelect = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(exports.MultiTypeaheadSelectBase, Object.assign({}, props, { innerRef: ref }))));
|
|
189
|
+
exports.MultiTypeaheadSelect.displayName = 'MultiTypeaheadSelect';
|
|
190
|
+
//# sourceMappingURL=MultiTypeaheadSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiTypeaheadSelect.js","sourceRoot":"","sources":["../../../../src/components/Select/MultiTypeaheadSelect.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,uDAegC;;AAoCzB,MAAM,wBAAwB,GAAuD,CAAC,EAYjE,EAAE,EAAE;;QAZ6D,EAC3F,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,WAAW,GAAG,kBAAkB,EAChC,qBAAqB,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,yBAAyB,MAAM,GAAG,EACtE,UAAU,EACV,WAAW,EACX,WAAW,OAEe,EADvB,KAAK,sBAXmF,oKAY5F,CADS;IAER,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,eAAK,CAAC,QAAQ,CAC5C,CAAC,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CACtE,CAAC;IACF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG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1
1
|
import React from 'react';
|
|
2
|
-
import { SelectOptionProps } from '@patternfly/react-core/dist/esm/components/Select';
|
|
3
|
-
|
|
2
|
+
import { SelectOptionProps, SelectProps } from '@patternfly/react-core/dist/esm/components/Select';
|
|
3
|
+
import { MenuToggleProps } from '@patternfly/react-core/dist/esm/components/MenuToggle';
|
|
4
|
+
export interface SimpleSelectOption extends Omit<SelectOptionProps, 'content'> {
|
|
4
5
|
/** Content of the select option. */
|
|
5
6
|
content: React.ReactNode;
|
|
6
7
|
/** Value of the select option. */
|
|
7
8
|
value: string | number;
|
|
8
9
|
}
|
|
9
|
-
export interface
|
|
10
|
+
export interface SimpleSelectProps extends Omit<SelectProps, 'toggle'> {
|
|
10
11
|
/** @hide Forwarded ref */
|
|
11
12
|
innerRef?: React.Ref<any>;
|
|
12
13
|
/** Initial options of the select. */
|
|
13
|
-
initialOptions?:
|
|
14
|
+
initialOptions?: SimpleSelectOption[];
|
|
14
15
|
/** Callback triggered on selection. */
|
|
15
16
|
onSelect?: (_event: React.MouseEvent<Element, MouseEvent>, selection: string | number) => void;
|
|
16
17
|
/** Callback triggered when the select opens or closes. */
|
|
@@ -19,8 +20,12 @@ export interface SelectSimpleProps {
|
|
|
19
20
|
isDisabled?: boolean;
|
|
20
21
|
/** Content of the toggle. Defaults to the selected option. */
|
|
21
22
|
toggleContent?: React.ReactNode;
|
|
22
|
-
/**
|
|
23
|
+
/** Placeholder text for the select input. */
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Width of the toggle. */
|
|
23
26
|
toggleWidth?: string;
|
|
27
|
+
/** Additional props passed to the toggle. */
|
|
28
|
+
toggleProps?: MenuToggleProps;
|
|
24
29
|
}
|
|
25
|
-
export declare const
|
|
26
|
-
//# sourceMappingURL=
|
|
30
|
+
export declare const SimpleSelect: React.ForwardRefExoticComponent<SimpleSelectProps & React.RefAttributes<any>>;
|
|
31
|
+
//# sourceMappingURL=SimpleSelect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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+1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleSelect = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const Select_1 = require('@patternfly/react-core/dist/js/components/Select');
|
|
7
|
+
const MenuToggle_1 = require('@patternfly/react-core/dist/js/components/MenuToggle');
|
|
8
|
+
const SimpleSelectBase = (_a) => {
|
|
9
|
+
var { innerRef, initialOptions, isDisabled, onSelect, onToggle, toggleContent, toggleWidth = '200px', toggleProps, placeholder = 'Select a value' } = _a, props = tslib_1.__rest(_a, ["innerRef", "initialOptions", "isDisabled", "onSelect", "onToggle", "toggleContent", "toggleWidth", "toggleProps", "placeholder"]);
|
|
10
|
+
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
11
|
+
const [selected, setSelected] = react_1.default.useState();
|
|
12
|
+
react_1.default.useEffect(() => {
|
|
13
|
+
const selectedOption = initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.find((option) => option.selected);
|
|
14
|
+
setSelected(selectedOption);
|
|
15
|
+
}, [initialOptions]);
|
|
16
|
+
const simpleSelectOptions = initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.map((option) => {
|
|
17
|
+
const { content, value } = option, props = tslib_1.__rest(option, ["content", "value"]);
|
|
18
|
+
const isSelected = (selected === null || selected === void 0 ? void 0 : selected.value) === value;
|
|
19
|
+
return (react_1.default.createElement(Select_1.SelectOption, Object.assign({ value: value, key: value, isSelected: isSelected }, props), content));
|
|
20
|
+
});
|
|
21
|
+
const onToggleClick = () => {
|
|
22
|
+
onToggle && onToggle(!isOpen);
|
|
23
|
+
setIsOpen(!isOpen);
|
|
24
|
+
};
|
|
25
|
+
const _onSelect = (_event, value) => {
|
|
26
|
+
onSelect && onSelect(_event, value);
|
|
27
|
+
setSelected(initialOptions.find((o) => o.value === value));
|
|
28
|
+
onToggle && onToggle(true);
|
|
29
|
+
setIsOpen(false);
|
|
30
|
+
};
|
|
31
|
+
const toggle = (toggleRef) => (react_1.default.createElement(MenuToggle_1.MenuToggle, Object.assign({ ref: toggleRef, onClick: onToggleClick, isExpanded: isOpen, isDisabled: isDisabled, style: {
|
|
32
|
+
width: toggleWidth
|
|
33
|
+
} }, toggleProps), toggleContent ? toggleContent : (selected === null || selected === void 0 ? void 0 : selected.content) || placeholder));
|
|
34
|
+
return (react_1.default.createElement(Select_1.Select, Object.assign({ isOpen: isOpen, selected: selected, onSelect: _onSelect, onOpenChange: (isOpen) => {
|
|
35
|
+
onToggle && onToggle(isOpen);
|
|
36
|
+
setIsOpen(isOpen);
|
|
37
|
+
}, toggle: toggle, shouldFocusToggleOnSelect: true, ref: innerRef }, props),
|
|
38
|
+
react_1.default.createElement(Select_1.SelectList, null, simpleSelectOptions)));
|
|
39
|
+
};
|
|
40
|
+
exports.SimpleSelect = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(SimpleSelectBase, Object.assign({}, props, { innerRef: ref }))));
|
|
41
|
+
exports.SimpleSelect.displayName = 'SimpleSelect';
|
|
42
|
+
//# sourceMappingURL=SimpleSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleSelect.js","sourceRoot":"","sources":["../../../../src/components/Select/SimpleSelect.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;;;AAsC1B,MAAM,gBAAgB,GAA+C,CAAC,EAWlD,EAAE,EAAE;QAX8C,EACpE,QAAQ,EACR,cAAc,EACd,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,WAAW,GAAG,OAAO,EACrB,WAAW,EACX,WAAW,GAAG,gBAAgB,OAEZ,EADf,KAAK,sBAV4D,kIAWrE,CADS;IAER,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,QAAQ,EAAE,WAAW,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B,SAAS,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,SAAuC,EAAE,EAAE,CAAC,CAC1D,8BAAC,uBAAU,kBACT,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,EACtB,KAAK,EACH;YACE,KAAK,EAAE,WAAW;SACI,IAEtB,WAAW,GAEd,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,KAAI,WAAW,CACtD,CACd,CAAC;IAEF,OAAO,CACL,8BAAC,eAAM,kBACL,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,SAAS,EACnB,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE;YACvB,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7B,SAAS,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC,EACD,MAAM,EAAE,MAAM,EACd,yBAAyB,QACzB,GAAG,EAAE,QAAQ,IACT,KAAK;QAET,8BAAC,mBAAU,QAAE,mBAAmB,CAAc,CACvC,CACV,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,YAAY,GAAG,eAAK,CAAC,UAAU,CAAC,CAAC,KAAwB,EAAE,GAAmB,EAAE,EAAE,CAAC,CAC9F,8BAAC,gBAAgB,oBAAK,KAAK,IAAE,QAAQ,EAAE,GAAG,IAAI,CAC/C,CAAC,CAAC;AAEH,oBAAY,CAAC,WAAW,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectOptionProps, MenuToggleProps, SelectProps } from '@patternfly/react-core';
|
|
3
|
+
export interface TypeaheadSelectOption extends Omit<SelectOptionProps, 'content' | 'isSelected'> {
|
|
4
|
+
/** Content of the select option. */
|
|
5
|
+
content: string | number;
|
|
6
|
+
/** Value of the select option. */
|
|
7
|
+
value: string | number;
|
|
8
|
+
/** Indicator for option being selected */
|
|
9
|
+
isSelected?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface TypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSelect'> {
|
|
12
|
+
/** @hide Forwarded ref */
|
|
13
|
+
innerRef?: React.Ref<any>;
|
|
14
|
+
/** Options of the select */
|
|
15
|
+
selectOptions: TypeaheadSelectOption[];
|
|
16
|
+
/** Callback triggered on selection. */
|
|
17
|
+
onSelect?: (_event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<HTMLInputElement> | undefined, selection: string | number) => void;
|
|
18
|
+
/** Callback triggered when the select opens or closes. */
|
|
19
|
+
onToggle?: (nextIsOpen: boolean) => void;
|
|
20
|
+
/** Callback triggered when the text in the input field changes. */
|
|
21
|
+
onInputChange?: (newValue: string) => void;
|
|
22
|
+
/** Function to return items matching the current filter value */
|
|
23
|
+
filterFunction?: (filterValue: string, options: TypeaheadSelectOption[]) => TypeaheadSelectOption[];
|
|
24
|
+
/** Callback triggered when the clear button is selected */
|
|
25
|
+
onClearSelection?: () => void;
|
|
26
|
+
/** Placeholder text for the select input. */
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** Flag to indicate if the typeahead select allows new items */
|
|
29
|
+
isCreatable?: boolean;
|
|
30
|
+
/** Flag to indicate if create option should be at top of typeahead */
|
|
31
|
+
isCreateOptionOnTop?: boolean;
|
|
32
|
+
/** Message to display to create a new option */
|
|
33
|
+
createOptionMessage?: string | ((newValue: string) => string);
|
|
34
|
+
/** Message to display when no options are available. */
|
|
35
|
+
noOptionsAvailableMessage?: string;
|
|
36
|
+
/** Message to display when no options match the filter. */
|
|
37
|
+
noOptionsFoundMessage?: string | ((filter: string) => string);
|
|
38
|
+
/** Flag indicating the select should be disabled. */
|
|
39
|
+
isDisabled?: boolean;
|
|
40
|
+
/** Width of the toggle. */
|
|
41
|
+
toggleWidth?: string;
|
|
42
|
+
/** Additional props passed to the toggle. */
|
|
43
|
+
toggleProps?: MenuToggleProps;
|
|
44
|
+
}
|
|
45
|
+
export declare const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>;
|
|
46
|
+
export declare const TypeaheadSelect: React.ForwardRefExoticComponent<TypeaheadSelectProps & React.RefAttributes<any>>;
|
|
47
|
+
//# sourceMappingURL=TypeaheadSelect.d.ts.map
|