@rh-support/components 2.5.1 → 2.5.3

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.
Files changed (72) hide show
  1. package/lib/esm/Functional/CaseContactsSelectorExternal.d.ts +12 -7
  2. package/lib/esm/Functional/CaseContactsSelectorExternal.d.ts.map +1 -1
  3. package/lib/esm/Functional/CaseContactsSelectorExternal.js +67 -60
  4. package/lib/esm/OwnerTypeaheadDropdown/OwnerTypeaheadDropdown.d.ts +17 -0
  5. package/lib/esm/OwnerTypeaheadDropdown/OwnerTypeaheadDropdown.d.ts.map +1 -0
  6. package/lib/esm/OwnerTypeaheadDropdown/OwnerTypeaheadDropdown.js +98 -0
  7. package/lib/esm/OwnerTypeaheadDropdown/index.d.ts +2 -0
  8. package/lib/esm/OwnerTypeaheadDropdown/index.d.ts.map +1 -0
  9. package/lib/esm/OwnerTypeaheadDropdown/index.js +1 -0
  10. package/lib/esm/SingleSelectDropdown/SingleSelectDropdown.d.ts +27 -0
  11. package/lib/esm/SingleSelectDropdown/SingleSelectDropdown.d.ts.map +1 -0
  12. package/lib/esm/SingleSelectDropdown/SingleSelectDropdown.js +26 -0
  13. package/lib/esm/SingleSelectDropdown/index.d.ts +2 -0
  14. package/lib/esm/SingleSelectDropdown/index.d.ts.map +1 -0
  15. package/lib/esm/SingleSelectDropdown/index.js +1 -0
  16. package/lib/esm/TypeaheadDropdown/TypeaheadDropdown.d.ts +39 -0
  17. package/lib/esm/TypeaheadDropdown/TypeaheadDropdown.d.ts.map +1 -0
  18. package/lib/esm/TypeaheadDropdown/TypeaheadDropdown.js +218 -0
  19. package/lib/esm/TypeaheadDropdown/index.d.ts +2 -0
  20. package/lib/esm/TypeaheadDropdown/index.d.ts.map +1 -0
  21. package/lib/esm/TypeaheadDropdown/index.js +1 -0
  22. package/lib/esm/hooks/index.d.ts +2 -0
  23. package/lib/esm/hooks/index.d.ts.map +1 -1
  24. package/lib/esm/hooks/index.js +2 -0
  25. package/lib/esm/hooks/usePatternFlySingleSelectToggle.d.ts +16 -0
  26. package/lib/esm/hooks/usePatternFlySingleSelectToggle.d.ts.map +1 -0
  27. package/lib/esm/hooks/usePatternFlySingleSelectToggle.js +17 -0
  28. package/lib/esm/hooks/useProgressiveLoading.d.ts +10 -0
  29. package/lib/esm/hooks/useProgressiveLoading.d.ts.map +1 -0
  30. package/lib/esm/hooks/useProgressiveLoading.js +33 -0
  31. package/lib/esm/hooks/useSelectKeyboardNavigator.d.ts +9 -1
  32. package/lib/esm/hooks/useSelectKeyboardNavigator.d.ts.map +1 -1
  33. package/lib/esm/hooks/useSelectKeyboardNavigator.js +82 -3
  34. package/lib/esm/index.d.ts +2 -1
  35. package/lib/esm/index.d.ts.map +1 -1
  36. package/lib/esm/index.js +2 -1
  37. package/package.json +6 -8
  38. package/lib/esm/DropDownList/AsyncDropDownList.d.ts +0 -6
  39. package/lib/esm/DropDownList/AsyncDropDownList.d.ts.map +0 -1
  40. package/lib/esm/DropDownList/AsyncDropDownList.js +0 -6
  41. package/lib/esm/DropDownList/DropDownList.d.ts +0 -9
  42. package/lib/esm/DropDownList/DropDownList.d.ts.map +0 -1
  43. package/lib/esm/DropDownList/DropDownList.js +0 -116
  44. package/lib/esm/DropDownList/DropdownWrapper.d.ts +0 -16
  45. package/lib/esm/DropDownList/DropdownWrapper.d.ts.map +0 -1
  46. package/lib/esm/DropDownList/DropdownWrapper.js +0 -19
  47. package/lib/esm/DropDownList/MultiSelectDropdownList.d.ts +0 -4
  48. package/lib/esm/DropDownList/MultiSelectDropdownList.d.ts.map +0 -1
  49. package/lib/esm/DropDownList/MultiSelectDropdownList.js +0 -4
  50. package/lib/esm/DropDownList/Readme.md +0 -114
  51. package/lib/esm/DropDownList/SearchableList.d.ts +0 -14
  52. package/lib/esm/DropDownList/SearchableList.d.ts.map +0 -1
  53. package/lib/esm/DropDownList/SearchableList.js +0 -98
  54. package/lib/esm/DropDownList/SelectList.d.ts +0 -11
  55. package/lib/esm/DropDownList/SelectList.d.ts.map +0 -1
  56. package/lib/esm/DropDownList/SelectList.js +0 -35
  57. package/lib/esm/DropDownList/async.d.ts +0 -9
  58. package/lib/esm/DropDownList/async.d.ts.map +0 -1
  59. package/lib/esm/DropDownList/async.js +0 -111
  60. package/lib/esm/DropDownList/dropdownList.css +0 -59
  61. package/lib/esm/DropDownList/dropdownUtils.d.ts +0 -5
  62. package/lib/esm/DropDownList/dropdownUtils.d.ts.map +0 -1
  63. package/lib/esm/DropDownList/dropdownUtils.js +0 -23
  64. package/lib/esm/DropDownList/index.d.ts +0 -4
  65. package/lib/esm/DropDownList/index.d.ts.map +0 -1
  66. package/lib/esm/DropDownList/index.js +0 -3
  67. package/lib/esm/DropDownList/types.d.ts +0 -53
  68. package/lib/esm/DropDownList/types.d.ts.map +0 -1
  69. package/lib/esm/DropDownList/types.js +0 -1
  70. package/lib/esm/DropDownList/withMulti.d.ts +0 -5
  71. package/lib/esm/DropDownList/withMulti.d.ts.map +0 -1
  72. package/lib/esm/DropDownList/withMulti.js +0 -46
@@ -1,116 +0,0 @@
1
- import './dropdownList.css';
2
- import CheckIcon from '@patternfly/react-icons/dist/js/icons/check-icon';
3
- import isEmpty from 'lodash/isEmpty';
4
- import map from 'lodash/map';
5
- import React, { useEffect, useMemo, useState } from 'react';
6
- import { Trans } from 'react-i18next';
7
- import { itemToString, noop } from './dropdownUtils';
8
- import SearchableList from './SearchableList';
9
- import SelectList from './SelectList';
10
- const defaultProps = {
11
- className: '',
12
- id: '',
13
- searchable: false,
14
- isInValid: false,
15
- isLoadingList: false,
16
- disabled: false,
17
- required: false,
18
- placeholder: '',
19
- name: '',
20
- 'data-tracking-id': '',
21
- filterListOnMenuOpen: false,
22
- maxResults: 100,
23
- paginate: false,
24
- paginationBtnText: 'Display additional results',
25
- isAsyncSearch: false,
26
- multiSelect: false,
27
- hasTwoColumns: false,
28
- hideToggleButton: false,
29
- };
30
- function Dropdown(props) {
31
- var _a, _b, _c;
32
- const [resultsShown, setResultsShown] = useState(props.maxResults);
33
- const [itemsList, setItemsList] = useState(props.list);
34
- const onChangeLocal = ({ selectedItem, }) => {
35
- selectedItem && props.onChange && props.onChange(selectedItem);
36
- };
37
- useEffect(() => {
38
- setItemsList(props.list);
39
- }, [props.list]);
40
- const onPaginatonButtonClick = (e, downshift) => {
41
- e.stopPropagation();
42
- const finalCount = resultsShown + props.maxResults;
43
- setResultsShown(finalCount);
44
- props.onPaginate && props.onPaginate(finalCount, downshift.inputValue, e);
45
- };
46
- const isSelectedItemLocal = (item) => {
47
- return !item.isNotSelectable && itemToString(props.selectedItem) === itemToString(item);
48
- };
49
- const isSelectedItem = props.isSelectedItem || isSelectedItemLocal;
50
- const getListItemClassNames = (downshift, item, itemIndex) => {
51
- let toReturn = 'downshift-item pf-v5-c-select__menu-item';
52
- toReturn += item.additionalInfo ? ' pf-m-description' : '';
53
- toReturn += isSelectedItem(item) ? ' pf-m-selected' : '';
54
- toReturn += item.disabled ? ' pf-m-disabled' : '';
55
- toReturn += itemIndex === downshift.highlightedIndex ? ' highlighted' : '';
56
- toReturn += item.className ? item.className : '';
57
- return toReturn;
58
- };
59
- const onInputChangeLocal = (items, inputValue) => {
60
- setResultsShown(props.maxResults);
61
- setItemsList(items);
62
- props.onInputChange && props.onInputChange(inputValue);
63
- };
64
- const renderListItems = (downshift) => {
65
- const listToRender = [];
66
- if (!downshift.isOpen)
67
- return [];
68
- let optionsToRender = itemsList;
69
- const shouldPaginate = props.paginate && resultsShown < optionsToRender.length;
70
- optionsToRender = props.paginate ? optionsToRender.slice(0, resultsShown) : optionsToRender;
71
- optionsToRender.filter((item) => !item.isNotSearchable).length === 0 &&
72
- props.emptyListLabel &&
73
- listToRender.push(React.createElement("li", { key: "empty-label", className: "pf-v5-u-p-sm" },
74
- React.createElement(Trans, null, props.emptyListLabel)));
75
- listToRender.push(...map(optionsToRender, (item, index) => {
76
- const itemProps = item.isNonActionable
77
- ? {}
78
- : downshift.getItemProps({
79
- item,
80
- index,
81
- disabled: item.disabled,
82
- className: getListItemClassNames(downshift, item, index),
83
- });
84
- return (React.createElement("li", { className: item.actionItem ? 'pf-v5-c-select__menu-wrapper' : '', role: "presentation", key: `${index}-${props.id}-${itemToString(item)}` },
85
- item.isNonActionable ? (isEmpty(item.children) ? itemToString(item) : item.children) : null,
86
- props.multiSelect && !item.isNotSelectable && !item.isNonActionable && (React.createElement("div", Object.assign({}, itemProps),
87
- React.createElement("div", { className: item.additionalInfo ? 'pf-v5-c-select__menu-item-main' : '' },
88
- React.createElement("input", { disabled: item.disabled === true, className: "pf-v5-c-check__input pf-v5-u-mr-sm", checked: isSelectedItem(item), onChange: noop, type: "checkbox" }),
89
- isEmpty(item.children) ? itemToString(item) : item.children),
90
- item.additionalInfo && (React.createElement("div", { className: "pf-v5-c-select__menu-item-description" }, item.additionalInfo)))),
91
- !props.multiSelect && !item.isNonActionable && (React.createElement("button", Object.assign({}, itemProps, { type: "button", title: itemToString(item) }),
92
- React.createElement("div", { className: item.additionalInfo ? 'pf-v5-c-select__menu-item-main' : '' },
93
- isEmpty(item.children) ? itemToString(item) : item.children,
94
- isSelectedItem(item) && (React.createElement("span", { className: "pf-v5-c-select__menu-item-icon" },
95
- React.createElement(CheckIcon, { "aria-hidden": true })))),
96
- item.additionalInfo && (React.createElement("div", { className: "pf-v5-c-select__menu-item-description" }, item.additionalInfo)))),
97
- item.actionItem ? React.cloneElement(item.actionItem, { disabled: item.disabled }) : null));
98
- }));
99
- shouldPaginate &&
100
- listToRender.push(...[
101
- React.createElement("li", { key: "separator", className: "dropdown-divider", role: "separator" }),
102
- React.createElement("li", { key: "pagination-item", className: "downshift-pagination-item" },
103
- React.createElement("button", { type: "button", onClick: (e) => onPaginatonButtonClick(e, downshift), className: "pf-v5-c-button pf-m-link pf-m-block", disabled: props.isLoadingList },
104
- React.createElement(Trans, null, props.paginationBtnText))),
105
- ]);
106
- return listToRender;
107
- };
108
- // eslint-disable-next-line react-hooks/exhaustive-deps
109
- const selectedItem = useMemo(() => props.selectedItem, [(_c = (_b = (_a = props.selectedItem) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : props.selectedItem) !== null && _c !== void 0 ? _c : '']);
110
- const newProps = Object.assign(Object.assign({}, props), { selectedItem, onChange: onChangeLocal, itemToString,
111
- renderListItems,
112
- itemsList });
113
- return props.searchable ? (React.createElement(SearchableList, Object.assign({}, newProps, { onInputChange: onInputChangeLocal }))) : (React.createElement(SelectList, Object.assign({}, newProps)));
114
- }
115
- Dropdown.defaultProps = defaultProps;
116
- export { Dropdown };
@@ -1,16 +0,0 @@
1
- import { IDClassNameProps } from '@rh-support/types/shared';
2
- import { GetPropsCommonOptions, UseComboboxGetLabelPropsOptions, UseComboboxGetMenuPropsOptions, UseSelectGetLabelPropsOptions, UseSelectGetMenuPropsOptions } from 'downshift';
3
- import React from 'react';
4
- interface IProps extends IDClassNameProps {
5
- isOpen: boolean;
6
- getMenuProps: (options?: UseComboboxGetMenuPropsOptions | UseSelectGetMenuPropsOptions, otherOptions?: GetPropsCommonOptions) => any;
7
- getLabelProps: (options?: UseComboboxGetLabelPropsOptions | UseSelectGetLabelPropsOptions) => any;
8
- toggleMenuComponent: React.ReactNode;
9
- label: string | React.ReactNode;
10
- children: JSX.Element | JSX.Element[] | React.ReactNode;
11
- 'data-tracking-id': string;
12
- hasTwoColumns: boolean;
13
- }
14
- export default function DropdownWrapper(props: IProps): React.JSX.Element;
15
- export {};
16
- //# sourceMappingURL=DropdownWrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropdownWrapper.d.ts","sourceRoot":"","sources":["../../../src/DropDownList/DropdownWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EACH,qBAAqB,EACrB,+BAA+B,EAC/B,8BAA8B,EAC9B,6BAA6B,EAC7B,4BAA4B,EAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,MAAO,SAAQ,gBAAgB;IACrC,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,CACV,OAAO,CAAC,EAAE,8BAA8B,GAAG,4BAA4B,EACvE,YAAY,CAAC,EAAE,qBAAqB,KACnC,GAAG,CAAC;IACT,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,6BAA6B,KAAK,GAAG,CAAC;IAClG,mBAAmB,EAAE,KAAK,CAAC,SAAS,CAAC;IACrC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IAChC,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;IACxD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE,MAAM,qBA6BpD"}
@@ -1,19 +0,0 @@
1
- import { isiOS } from '@rh-support/utils';
2
- import React from 'react';
3
- export default function DropdownWrapper(props) {
4
- const onBlur = (event) => {
5
- // on ios devices the onBlur event is called before the onClick event, so selecting an item in droponw
6
- // closes the dropdown without selecting the item
7
- // this is just a hack to prevent the downshift onBlur method from being called which closes the dropdown
8
- if (isiOS()) {
9
- event.nativeEvent.preventDownshiftDefault = true;
10
- }
11
- };
12
- return (React.createElement("div", { id: `${props.id}`, className: `downshift ${props.className} pf-v5-c-select ${props.isOpen ? 'pf-m-expanded' : ''} `, "data-tracking-id": props['data-tracking-id'] ? props['data-tracking-id'] : null },
13
- props.label && React.createElement("label", Object.assign({}, props.getLabelProps()), props.label),
14
- props.toggleMenuComponent,
15
- React.createElement("ul", Object.assign({}, props.getMenuProps({
16
- onBlur: onBlur,
17
- className: `downshift-menu pf-v5-c-select__menu ${props.hasTwoColumns ? 'column-selector-menu' : ''} ${props.isOpen ? 'open' : ''}`,
18
- })), props.children)));
19
- }
@@ -1,4 +0,0 @@
1
- import { MultiSelectDropdownProps } from './types';
2
- declare const MultiSelectDropDownList: <T extends {}>(props: MultiSelectDropdownProps<T>) => JSX.Element;
3
- export { MultiSelectDropDownList, MultiSelectDropdownProps };
4
- //# sourceMappingURL=MultiSelectDropdownList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MultiSelectDropdownList.d.ts","sourceRoot":"","sources":["../../../src/DropDownList/MultiSelectDropdownList.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGnD,QAAA,MAAM,uBAAuB,EAA0B,CAAC,CAAY,SAAF,EAAE,EAChE,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC,KACjC,GAAG,CAAC,OAAO,CAAC;AAEjB,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,4 +0,0 @@
1
- import { Dropdown } from './DropDownList';
2
- import { withMulti } from './withMulti';
3
- const MultiSelectDropDownList = withMulti(Dropdown);
4
- export { MultiSelectDropDownList };
@@ -1,114 +0,0 @@
1
- # Dropdown list
2
-
3
- ## Async Dropdown
4
-
5
- It is an HOC wrapper around the original dropdown component.If you use async dropdown then the dropdown list will be searchable by default. You don't need to pass the searchable prop explicitly.
6
-
7
- ### How to use async dropdownlist
8
-
9
- Below is the an example of how you can use async dropdown list. Please also go through the comments as they explain a lot about the inner functionalities of the dropdown
10
-
11
- ```js
12
- import React, { useState, useMemo } from 'react'
13
- import { AsyncDropDownList } from '@rh-support/components';
14
- import { toOptions, toOption } from '@rh-support/utils';
15
-
16
-
17
- // it's better to keep the server pagination in sync with the dropdown pagination
18
- // so that you always know that if user will click on pagination button
19
- // we need to fetch data from the server just by increasing the page size.
20
- // otherwise we will need some complex logic in handle pagination function
21
- const PER_PAGE = 50;
22
- const SEARCH_URI = 'https://api.github.com/search/users';
23
-
24
-
25
- function makeAndHandleRequest(query, page = 1) {
26
- return fetch(`${SEARCH_URI}?q=${query}+in:login&page=${page}&per_page=${PER_PAGE}`)
27
- .then(resp => resp.json())
28
- .then(({ items, total_count }) => {
29
- /* eslint-disable-line camelcase */
30
- const options = items.map(i => ({
31
- avatar_url: i.avatar_url,
32
- id: i.id,
33
- login: i.login,
34
- }));
35
- return { options, total_count };
36
- });
37
- }
38
-
39
- export function Test() {
40
- const [items, setItems] = useState<any>([]);
41
- const [isFetching, setIsFetching] = useState(false);
42
- const [selectedItem, setSelectedItem] = useState({ login: 'karan' });
43
- const fetchUsers = async (inputVal) => {
44
- try {
45
- setIsFetching(true);
46
- const userResponse = await makeAndHandleRequest(inputVal);
47
- setItems(userResponse)
48
- } catch (e) {
49
- // silently fails
50
- }
51
- finally {
52
- setIsFetching(false);
53
- }
54
- };
55
-
56
- const onDropdownChange = (item) => {
57
- setSelectedItem(item.label);
58
- }
59
-
60
- const onPaginate = (shownResults, inputVal, e) => {
61
- console.log(inputVal);
62
- // fetch more results here
63
- };
64
-
65
- const onOuterClick = () => {
66
- // optional if you don't want to show the last results if user focuses out of dropdown
67
- setItems({ options: [] });
68
- }
69
-
70
- const onDropdownClear = () => {
71
- setSelectedItem({ login: '' });
72
- }
73
-
74
- // this is the most important part to memoize the selected item. If you don't then every time
75
- // new results are fetched the dropdown will render and toOption always create a new object
76
- // forcing dropdown to render and overriding the input value
77
- const memoizedSelectedItem = useMemo(() => toOption(selectedItem, { labelKey: 'login' }), [selectedItem]);
78
-
79
- return (
80
- <AsyncDropDownList<any>
81
- placeholder={'Select a Cluster'}
82
- id="case-details-cluster-nickname-selector"
83
- selectedItem={memoizedSelectedItem}
84
- list={items ? toOptions(items.options, {
85
- labelKey: 'login',
86
- childrenKey: 'children'
87
- }) : []}
88
- title={`Select a Cluster`}
89
- onOuterClick={onOuterClick}
90
- onChange={onDropdownChange}
91
- onSearch={fetchUsers}
92
- delay={300}
93
- useCache={true}
94
- isLoadingList={isFetching}
95
- paginate={true}
96
- onPaginate={onPaginate}
97
- maxResults={PER_PAGE - 1}
98
- emptyListLabel={'No results found'}
99
- onClearSelection={onDropdownClear}
100
- />
101
- )
102
- }
103
-
104
- ```
105
-
106
- **Props specific to async dropdown**
107
-
108
- | Name | Type | Default | Description |
109
- | ---------- | -------------------- | ------------------- | ----------------------------------------------------------------------- |
110
- | delay | <code>number</code> | 200 | Delay, in milliseconds, before performing search. |
111
- | minlength | <code>number</code> | 2 | Number of input characters that must be entered before showing results. |
112
- | promptText | <code>string</code> | 'Type to search...' | Message displayed in the menu when there is no user input. |
113
- | searchText | <code>string</code> | 'Searching...' | Message displayed in the menu while the request is pending. |
114
- | useCache | <code>boolean</code> | false | Whether or not the component should cache query results. |
@@ -1,14 +0,0 @@
1
- import { IOption } from '@rh-support/types/shared';
2
- import { UseComboboxReturnValue, UseComboboxStateChange } from 'downshift';
3
- import React from 'react';
4
- import { IDropdownListProps } from './types';
5
- interface IProps<T> extends Omit<IDropdownListProps<T>, 'onChange' | 'onInputChange'> {
6
- renderListItems: (downshift: UseComboboxReturnValue<IOption<T>>) => React.ReactNode[];
7
- onChange: (changes: UseComboboxStateChange<IOption<T>>) => void;
8
- itemsList: IOption<T>[];
9
- onInputChange?: (items: IOption<T>[], inputValue: string) => void;
10
- isPDFExporting?: boolean;
11
- }
12
- export default function SearchableList<T>(props: IProps<T>): React.JSX.Element;
13
- export {};
14
- //# sourceMappingURL=SearchableList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SearchableList.d.ts","sourceRoot":"","sources":["../../../src/DropDownList/SearchableList.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAEH,sBAAsB,EAEtB,sBAAsB,EAEzB,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,UAAU,MAAM,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,UAAU,GAAG,eAAe,CAAC;IACjF,eAAe,EAAE,CAAC,SAAS,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,SAAS,EAAE,CAAC;IACtF,QAAQ,EAAE,CAAC,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAChE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAClE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,qBAgJzD"}
@@ -1,98 +0,0 @@
1
- import CaretDownIcon from '@patternfly/react-icons/dist/js/icons/caret-down-icon';
2
- import TimesCircleIcon from '@patternfly/react-icons/dist/js/icons/times-circle-icon';
3
- import { useCombobox, } from 'downshift';
4
- import includes from 'lodash/includes';
5
- import isEmpty from 'lodash/isEmpty';
6
- import React from 'react';
7
- import { LoadingIndicator } from '../LoadingIndicator/LoadingIndicator';
8
- import { itemToString, multiSelectDropdownStateReducer, noop } from './dropdownUtils';
9
- import DropdownWrapper from './DropdownWrapper';
10
- export default function SearchableList(props) {
11
- const doesMatchInput = (inputVal) => (item) => {
12
- // Should always keep non-searchable, or item with no labels
13
- if (item.isNotSearchable || item.label === null || item.label === undefined)
14
- return true;
15
- const inputValueLC = inputVal ? inputVal.trim().toLowerCase() : '';
16
- const labelLC = itemToString(item).trim().toLowerCase();
17
- return includes(labelLC, inputValueLC);
18
- };
19
- const onIsOpenChange = (changes) => {
20
- if (!changes.isOpen && changes.type !== useCombobox.stateChangeTypes.ItemClick) {
21
- props.onOuterClick && props.onOuterClick(props.selectedItem);
22
- }
23
- };
24
- const comboboxStateReducer = (state, actionAndChanges) => {
25
- const { changes, type } = actionAndChanges;
26
- switch (type) {
27
- case useCombobox.stateChangeTypes.InputBlur:
28
- return Object.assign(Object.assign({}, changes), { inputValue: itemToString(props.selectedItem) && downshift.inputValue !== itemToString(props.selectedItem)
29
- ? itemToString(props.selectedItem)
30
- : state.inputValue });
31
- case useCombobox.stateChangeTypes.InputKeyDownEnter:
32
- return Object.assign(Object.assign({}, changes), { inputValue: state.inputValue });
33
- default:
34
- return changes;
35
- }
36
- };
37
- const downshift = useCombobox({
38
- selectedItem: props.selectedItem,
39
- items: props.itemsList,
40
- onSelectedItemChange: props.onChange,
41
- labelId: `${props.id}-label`,
42
- itemToString,
43
- onIsOpenChange,
44
- onInputValueChange: ({ inputValue, isOpen }) => {
45
- const newList = props.searchable && (props.filterListOnMenuOpen || isOpen) && !props.isAsyncSearch
46
- ? props.list.filter(doesMatchInput(inputValue))
47
- : props.list;
48
- // for async search we want to make sure that we don't call input change unless the user changes
49
- // the input manually as it will trigger an api call.
50
- (!props.isAsyncSearch || (props.isAsyncSearch && isOpen)) && props.onInputChange(newList, inputValue);
51
- },
52
- stateReducer: props.multiSelect ? multiSelectDropdownStateReducer : comboboxStateReducer,
53
- });
54
- const { getInputProps, getToggleButtonProps, getMenuProps, getLabelProps, openMenu, isOpen } = downshift;
55
- const clearSelection = () => (event) => {
56
- props.onClearSelection && props.onClearSelection();
57
- // in case of multi select we force input to get cleared on clear button click
58
- downshift.selectItem(null);
59
- !isOpen && openMenu();
60
- };
61
- const onInputClick = () => (e) => {
62
- if (!isOpen) {
63
- openMenu();
64
- props.onMenuToggle && props.onMenuToggle();
65
- }
66
- };
67
- const onInputBlur = () => (e) => {
68
- props.onInputBlur && props.onInputBlur(e);
69
- };
70
- const renderSearchableToggleButton = () => {
71
- return (React.createElement("div", Object.assign({}, downshift.getComboboxProps({ className: 'pf-v5-c-select__toggle pf-m-typeahead' })),
72
- React.createElement("div", { className: "pf-v5-c-select__toggle-wrapper" },
73
- props.chipGroupComponent,
74
- React.createElement("input", Object.assign({}, getInputProps({
75
- placeholder: props.placeholder,
76
- className: `pf-v5-c-form-control pf-v5-c-select__toggle-typeahead`,
77
- id: `${props.id}-downshift-search`,
78
- 'aria-invalid': props.isInValid,
79
- 'aria-required': props.required,
80
- required: props.required,
81
- disabled: props.disabled,
82
- onClick: onInputClick(),
83
- onBlur: onInputBlur(),
84
- })))),
85
- React.createElement(LoadingIndicator, { isInline: true, show: props.isLoadingList }),
86
- !isEmpty(downshift.inputValue) &&
87
- !props.isLoadingList &&
88
- (!props.isExportingPDF ? (React.createElement("button", { className: "pf-v5-c-button pf-m-plain pf-v5-c-select__toggle-clear", onClick: clearSelection(), "aria-label": "clear selection", type: "button", title: "Clear selection", disabled: props.disabled, "data-tracking-id": `${props['data-tracking-id']}-clear` },
89
- React.createElement(TimesCircleIcon, null))) : null),
90
- !props.hideToggleButton && (React.createElement("button", Object.assign({ type: "button", "aria-label": "Menu toggle" }, getToggleButtonProps({
91
- disabled: props.disabled || props.isLoadingList,
92
- className: 'pf-v5-c-button pf-v5-c-select__toggle-button pf-m-plain',
93
- onClick: props.onMenuToggle ? () => props.onMenuToggle() : noop,
94
- })),
95
- React.createElement(CaretDownIcon, null)))));
96
- };
97
- return (React.createElement(DropdownWrapper, { id: props.id, className: props.className, isOpen: isOpen, getMenuProps: getMenuProps, getLabelProps: getLabelProps, label: props.label, toggleMenuComponent: renderSearchableToggleButton(), "data-tracking-id": props['data-tracking-id'], hasTwoColumns: props.hasTwoColumns }, isOpen && props.renderListItems(downshift)));
98
- }
@@ -1,11 +0,0 @@
1
- import { IOption } from '@rh-support/types/shared';
2
- import { UseSelectReturnValue, UseSelectStateChange } from 'downshift';
3
- import React from 'react';
4
- import { IDropdownListProps } from './types';
5
- interface IProps<T> extends Omit<IDropdownListProps<T>, 'onChange'> {
6
- renderListItems: (downshift: UseSelectReturnValue<IOption<T>>) => React.ReactNode[];
7
- onChange: (changes: UseSelectStateChange<IOption<T>>) => void;
8
- }
9
- export default function SelectList<T>(props: IProps<T>): React.JSX.Element;
10
- export {};
11
- //# sourceMappingURL=SelectList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectList.d.ts","sourceRoot":"","sources":["../../../src/DropDownList/SelectList.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAa,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,UAAU,MAAM,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;IAC/D,eAAe,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,SAAS,EAAE,CAAC;IACpF,QAAQ,EAAE,CAAC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACjE;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,qBAkErD"}
@@ -1,35 +0,0 @@
1
- import CaretDownIcon from '@patternfly/react-icons/dist/js/icons/caret-down-icon';
2
- import { useSelect } from 'downshift';
3
- import React from 'react';
4
- import { LoadingIndicator } from '../LoadingIndicator/LoadingIndicator';
5
- import { itemToString, multiSelectDropdownStateReducer, noop } from './dropdownUtils';
6
- import DropdownWrapper from './DropdownWrapper';
7
- export default function SelectList(props) {
8
- const onIsOpenChange = (changes) => {
9
- if (!changes.isOpen && changes.type !== useSelect.stateChangeTypes.ItemClick) {
10
- props.onOuterClick && props.onOuterClick(props.selectedItem);
11
- }
12
- };
13
- const downshift = useSelect(Object.assign({ selectedItem: props.selectedItem, items: props.list, onIsOpenChange, onSelectedItemChange: props.onChange, labelId: `${props.id}-label`, itemToString }, (props.multiSelect && { stateReducer: multiSelectDropdownStateReducer })));
14
- const { getToggleButtonProps, getLabelProps, getMenuProps, isOpen } = downshift;
15
- const renderToggleButton = () => {
16
- var _a;
17
- return (React.createElement("button", Object.assign({ type: "button" }, getToggleButtonProps({
18
- id: `pcm-${props.id}-${props.name}-toggle`,
19
- className: `pf-v5-c-select__toggle ${props.isInValid ? 'form-invalid' : ''}`,
20
- disabled: props.disabled || props.isLoadingList,
21
- 'aria-label': `${isOpen ? 'Close ' + props.title : 'Open ' + props.title}${props.selectedItem ? '. The selected option is ' + itemToString(props.selectedItem) + '.' : ''}`,
22
- 'aria-invalid': props.isInValid,
23
- name: props.name,
24
- title: itemToString(props.selectedItem) || props.placeholder,
25
- 'data-tracking-id': (_a = props['data-tracking-id']) !== null && _a !== void 0 ? _a : '',
26
- onClick: props.onMenuToggle ? () => props.onMenuToggle() : noop,
27
- })),
28
- React.createElement("div", { className: "pf-v5-c-select__toggle-wrapper" },
29
- React.createElement("span", { className: "pf-v5-c-select__toggle-text" }, itemToString(props.selectedItem) || (React.createElement("span", { className: "pf-v5-c-select__placeholder-text" }, props.placeholder)))),
30
- React.createElement(LoadingIndicator, { isInline: true, show: props.isLoadingList }),
31
- !props.isLoadingList && (React.createElement("span", { className: "pf-v5-c-select__toggle-arrow" },
32
- React.createElement(CaretDownIcon, null)))));
33
- };
34
- return (React.createElement(DropdownWrapper, { id: props.id, className: props.className, label: props.label, isOpen: isOpen, getMenuProps: getMenuProps, getLabelProps: getLabelProps, toggleMenuComponent: renderToggleButton(), "data-tracking-id": props['data-tracking-id'], hasTwoColumns: props.hasTwoColumns }, isOpen && props.renderListItems(downshift)));
35
- }
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { IAsyncOnlyProps, IDropdownListBasePropsForAsync } from './types';
3
- export declare function useAsync<OptionType, DropdownPropsType extends IDropdownListBasePropsForAsync<OptionType>>(props: DropdownPropsType & IAsyncOnlyProps<OptionType>): DropdownPropsType;
4
- export declare function withAsync<DropdownPropsType extends IDropdownListBasePropsForAsync<OptionType>, OptionType>(WrappedComponent: React.ComponentType<DropdownPropsType>): {
5
- (props: DropdownPropsType & IAsyncOnlyProps<OptionType>): React.JSX.Element;
6
- displayName: string;
7
- defaultProps: {};
8
- };
9
- //# sourceMappingURL=async.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../../src/DropDownList/async.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAI9D,OAAO,EAAE,eAAe,EAAE,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAiB1E,wBAAgB,QAAQ,CAAC,UAAU,EAAE,iBAAiB,SAAS,8BAA8B,CAAC,UAAU,CAAC,EACrG,KAAK,EAAE,iBAAiB,GAAG,eAAe,CAAC,UAAU,CAAC,GACvD,iBAAiB,CA6HnB;AAED,wBAAgB,SAAS,CAAC,iBAAiB,SAAS,8BAA8B,CAAC,UAAU,CAAC,EAAE,UAAU,EACtG,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC;YAE1B,iBAAiB,GAAG,eAAe,CAAC,UAAU,CAAC;;;EAUhF"}
@@ -1,111 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import debounce from 'lodash/debounce';
13
- import React, { useCallback, useEffect, useRef } from 'react';
14
- import { useForceUpdate, useLRUCache } from '../hooks';
15
- import { usePrevious } from '../hooks/usePrevious';
16
- // Most of the code credit goes to
17
- // https://github.com/ericgio/react-bootstrap-typeahead/blob/master/src/behaviors/async.js
18
- const defaultProps = {
19
- delay: 200,
20
- minLength: 2,
21
- promptText: '',
22
- searchText: 'Searching...',
23
- useCache: false,
24
- };
25
- export function useAsync(props) {
26
- const { delay, isLoadingList, minLength, onInputChange, onSearch, useCache, list, onInputBlur, emptyListLabel, onClearSelection, suggestedItems } = props, otherProps = __rest(props, ["delay", "isLoadingList", "minLength", "onInputChange", "onSearch", "useCache", "list", "onInputBlur", "emptyListLabel", "onClearSelection", "suggestedItems"]);
27
- const { getFromCache, setInCache, clearCache } = useLRUCache(25);
28
- const handleSearchDebouncedRef = useRef();
29
- const queryRef = useRef('');
30
- const forceUpdate = useForceUpdate();
31
- const prevProps = usePrevious(props);
32
- const handleSearch = useCallback((query) => {
33
- queryRef.current = query;
34
- if (!query || (minLength && query.length < minLength)) {
35
- return;
36
- }
37
- // Use cached results, if applicable.
38
- if (useCache && getFromCache(query)) {
39
- // Re-render the component with the cached results.
40
- forceUpdate();
41
- return;
42
- }
43
- // Perform the search.
44
- onSearch(query);
45
- },
46
- // eslint-disable-next-line react-hooks/exhaustive-deps
47
- [forceUpdate, minLength, onSearch, useCache]);
48
- // Set the debounced search function.
49
- useEffect(() => {
50
- handleSearchDebouncedRef.current = debounce(handleSearch, delay);
51
- return () => {
52
- handleSearchDebouncedRef.current && handleSearchDebouncedRef.current.cancel();
53
- };
54
- }, [delay, handleSearch]);
55
- useEffect(() => {
56
- // Ensure that we've gone from a loading to a completed state. Otherwise
57
- // an empty response could get cached if the component updates during the
58
- // request (eg: if the parent re-renders for some reason).
59
- // NOTE: There is a limitation that empty responses will not be cached.
60
- const listToCache = list.filter((item) => !item.isNotSearchable);
61
- if (!isLoadingList && useCache && queryRef.current && (listToCache || []).length > 0) {
62
- setInCache(queryRef.current, list);
63
- }
64
- // eslint-disable-next-line react-hooks/exhaustive-deps
65
- }, [list, isLoadingList, useCache]);
66
- useEffect(() => {
67
- if (prevProps && prevProps.useCache && !useCache) {
68
- clearCache();
69
- }
70
- return () => {
71
- clearCache();
72
- };
73
- // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, [useCache]);
75
- const getEmptyLabel = () => {
76
- if (!queryRef.current.length) {
77
- return props.promptText;
78
- }
79
- if (isLoadingList) {
80
- return props.searchText;
81
- }
82
- return emptyListLabel;
83
- };
84
- const handleInputBlur = (e) => {
85
- onInputBlur && onInputBlur(e);
86
- };
87
- const handleClearSelection = () => {
88
- onClearSelection && onClearSelection();
89
- queryRef.current = '';
90
- };
91
- const handleInputChange = useCallback((query) => {
92
- onInputChange && onInputChange(query);
93
- handleSearchDebouncedRef.current && handleSearchDebouncedRef.current(query);
94
- }, [onInputChange]);
95
- const cachedQuery = getFromCache(queryRef.current);
96
- return Object.assign(Object.assign({}, otherProps), { isLoadingList,
97
- minLength, onInputChange: handleInputChange, emptyListLabel: getEmptyLabel(), list: useCache && cachedQuery
98
- ? cachedQuery
99
- : !queryRef.current
100
- ? (suggestedItems || []).length > 0
101
- ? suggestedItems
102
- : list
103
- : list, onInputBlur: handleInputBlur, searchable: true, onClearSelection: handleClearSelection, isAsyncSearch: true });
104
- }
105
- export function withAsync(WrappedComponent) {
106
- const AsyncDropdown = (props) => (React.createElement(WrappedComponent, Object.assign({}, useAsync(props))));
107
- const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
108
- AsyncDropdown.displayName = `withAsync${displayName}`;
109
- AsyncDropdown.defaultProps = defaultProps;
110
- return AsyncDropdown;
111
- }
@@ -1,59 +0,0 @@
1
- .downshift {
2
- position: relative;
3
- }
4
-
5
- .downshift input {
6
- border: none;
7
- padding: 6px;
8
- }
9
-
10
- .downshift > .pf-v5-c-select__toggle.form-invalid {
11
- border-bottom: 2px solid #c9190b;
12
- }
13
-
14
- .downshift > .pf-v5-c-select__toggle.form-invalid[disabled] {
15
- background-color: #ededed;
16
- border-color: #ededed;
17
- }
18
-
19
- .downshift .downshift-menu li[disabled] {
20
- background: #f0f0f0;
21
- cursor: not-allowed;
22
- opacity: 0.3;
23
- }
24
-
25
- .downshift .downshift-menu .downshift-item.highlighted:not(:hover) {
26
- background-color: #ededed;
27
- }
28
-
29
- .downshift .downshift-menu li.dropdown-divider {
30
- height: 0;
31
- padding: 0;
32
- overflow: hidden;
33
- border-top: 1px solid #e9ecef;
34
- }
35
-
36
- .downshift .pf-v5-c-select__placeholder-text {
37
- color: #6a6e73;
38
- }
39
-
40
- .downshift .pf-v5-c-select__menu-wrapper {
41
- display: flex;
42
- }
43
-
44
- .downshift .pf-v5-c-select__menu-wrapper:hover {
45
- background-color: rgb(240, 240, 240);
46
- }
47
-
48
- .downshift .downshift-menu.open {
49
- visibility: visible;
50
- z-index: 89;
51
- }
52
-
53
- .downshift .downshift-menu {
54
- visibility: hidden;
55
- }
56
-
57
- .hide-in-pdf {
58
- display: none !important;
59
- }