@antscorp/antsomi-ui 2.0.7 → 2.0.9
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.
|
@@ -15,7 +15,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
15
15
|
import { ConfigProvider } from 'antd';
|
|
16
16
|
import clsx from 'clsx';
|
|
17
17
|
import { isEmpty, uniqBy } from 'lodash';
|
|
18
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
18
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
19
19
|
// Components
|
|
20
20
|
import { Button, Flex, Icon, Input, Popover, Spin, Tooltip, Typography, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
21
21
|
import { EmptyData, PopoverSelect, Select } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
@@ -37,6 +37,7 @@ import { getSelectedTreeData } from './utils';
|
|
|
37
37
|
import { DataIcon, WarningIcon } from '../../icons';
|
|
38
38
|
const initialState = {
|
|
39
39
|
isOpenPopover: false,
|
|
40
|
+
searchValue: '',
|
|
40
41
|
};
|
|
41
42
|
const matchesAnyInitialState = {
|
|
42
43
|
searchValue: '',
|
|
@@ -48,11 +49,11 @@ const { t } = i18nInstance;
|
|
|
48
49
|
const { Text } = Typography;
|
|
49
50
|
export function MatchesAny(props) {
|
|
50
51
|
// Props
|
|
51
|
-
const { objectName, loading = false, showExtendValue = true, selectedItems: selectedItemsProp, items, groupSelectProps, renderExtraValues, customItemRenders, listEmptyProps, selectedListEmptyProps, selectedTreeData: selectedTreeDataProp, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "selectedItems", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "listEmptyProps", "selectedListEmptyProps", "selectedTreeData", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
|
|
52
|
+
const { objectName, loading = false, showExtendValue = true, selectedItems: selectedItemsProp, items, groupSelectProps, renderExtraValues, customItemRenders, listEmptyProps, selectedListEmptyProps, selectedTreeData: selectedTreeDataProp, searchValue = '', isExternalSearch, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "selectedItems", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "listEmptyProps", "selectedListEmptyProps", "selectedTreeData", "searchValue", "isExternalSearch", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
|
|
52
53
|
// State
|
|
53
54
|
const [state, setState] = useState(matchesAnyInitialState);
|
|
54
55
|
// Variables
|
|
55
|
-
const {
|
|
56
|
+
const { selectedItems, selectedTreeData, isShowLoadMoreEl } = state;
|
|
56
57
|
const _a = listEmptyProps || {}, { icon: listEmptyIcon, description: listEmptyDescription = t(translations.global.noResultsMatchesKeyWord).toString() } = _a, restListEmptyProps = __rest(_a, ["icon", "description"]);
|
|
57
58
|
const _b = selectedListEmptyProps || {}, { description: selectedListEmptyDescription = t(translations.global.selectItemsFromList).toString(), icon: selectedListEmptyIcon = React.createElement(DataIcon, { color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw5, size: 48 }) } = _b, restSelectedListEmptyProps = __rest(_b, ["description", "icon"]);
|
|
58
59
|
// Refs
|
|
@@ -65,6 +66,7 @@ export function MatchesAny(props) {
|
|
|
65
66
|
}
|
|
66
67
|
},
|
|
67
68
|
});
|
|
69
|
+
const searchInputRef = useRef(null);
|
|
68
70
|
// Effects
|
|
69
71
|
/**
|
|
70
72
|
* Updates the `selectedItems` state when the `selectedItems` prop changes.
|
|
@@ -75,6 +77,8 @@ export function MatchesAny(props) {
|
|
|
75
77
|
useEffect(() => {
|
|
76
78
|
// Delay for show load more el
|
|
77
79
|
setTimeout(() => {
|
|
80
|
+
var _a;
|
|
81
|
+
(_a = searchInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
78
82
|
setState(prev => (Object.assign(Object.assign({}, prev), { isShowLoadMoreEl: true })));
|
|
79
83
|
}, 500);
|
|
80
84
|
}, []);
|
|
@@ -165,7 +169,7 @@ export function MatchesAny(props) {
|
|
|
165
169
|
const { results, matchedParents } = recursiveSearchItems({
|
|
166
170
|
list: items || [],
|
|
167
171
|
searchKeys: ['title', 'key'],
|
|
168
|
-
searchValue: !
|
|
172
|
+
searchValue: !isExternalSearch ? searchValue : '',
|
|
169
173
|
childrenKey: 'children',
|
|
170
174
|
});
|
|
171
175
|
const serializeTreeData = (list) => list.map(item => {
|
|
@@ -234,8 +238,7 @@ export function MatchesAny(props) {
|
|
|
234
238
|
":"),
|
|
235
239
|
`${((_a = groupSelectProps === null || groupSelectProps === void 0 ? void 0 : groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.length) || 0} ${t(translations.global.selected)}`))),
|
|
236
240
|
React.createElement("div", { style: { width: '100%' } },
|
|
237
|
-
React.createElement(Input.CustomSearch, { placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => {
|
|
238
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
|
|
241
|
+
React.createElement(Input.CustomSearch, { ref: searchInputRef, autoFocus: true, value: searchValue, placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => {
|
|
239
242
|
if (onChangeSearch) {
|
|
240
243
|
onChangeSearch(searchValue);
|
|
241
244
|
}
|
|
@@ -311,12 +314,20 @@ export function MatchesAnySelect(props) {
|
|
|
311
314
|
const value = Array.isArray(selectedItems) && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length)
|
|
312
315
|
? `${(_a = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.map(item => item.title)) === null || _a === void 0 ? void 0 : _a[0]}${((_b = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.slice(1)) === null || _b === void 0 ? void 0 : _b.length) ? `, and +${(_c = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.slice(1)) === null || _c === void 0 ? void 0 : _c.length} more` : ''}` || []
|
|
313
316
|
: undefined;
|
|
317
|
+
// Effects
|
|
318
|
+
useDeepCompareEffect(() => {
|
|
319
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { searchValue: props.searchValue || '' })));
|
|
320
|
+
}, [props.searchValue]);
|
|
314
321
|
// Handlers
|
|
315
322
|
const onApplyMatchesAny = (selectedItems, selectedTreeData) => {
|
|
316
323
|
onChange(selectedItems, selectedTreeData);
|
|
317
324
|
setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
|
|
318
325
|
};
|
|
319
|
-
return (React.createElement(Popover, Object.assign({ open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, groupSelectProps: groupSelectProps, renderExtraValues: renderExtraValues, customItemRenders: customItemRenders, listEmptyProps: listEmptyProps, selectedListEmptyProps: selectedListEmptyProps, selectedTreeData: selectedTreeData, onChangeSearch:
|
|
326
|
+
return (React.createElement(Popover, Object.assign({ open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { isExternalSearch: !!onChangeSearch, searchValue: state.searchValue, className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, groupSelectProps: groupSelectProps, renderExtraValues: renderExtraValues, customItemRenders: customItemRenders, listEmptyProps: listEmptyProps, selectedListEmptyProps: selectedListEmptyProps, selectedTreeData: selectedTreeData, onChangeSearch: searchValue => {
|
|
327
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
|
|
328
|
+
if (onChangeSearch)
|
|
329
|
+
onChangeSearch(searchValue);
|
|
330
|
+
}, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
|
|
320
331
|
overflow: {
|
|
321
332
|
shiftY: 0,
|
|
322
333
|
shiftX: 0,
|
|
@@ -50,6 +50,8 @@ export interface MatchesAnySelectProps<TItem = any> extends Omit<SelectProps, 'o
|
|
|
50
50
|
listEmptyProps?: EmptyDataProps;
|
|
51
51
|
/** Empty UI for selected list items */
|
|
52
52
|
selectedListEmptyProps?: EmptyDataProps;
|
|
53
|
+
/** Search value */
|
|
54
|
+
searchValue?: string;
|
|
53
55
|
/** Callback function that is called when the selected items change. */
|
|
54
56
|
onChange?: (selectedItems: MatchesAnyItem<TItem>[], selectedTreeData?: MatchesAnyItem<TItem>[]) => void;
|
|
55
57
|
/** Callback function that is called when the search value changes */
|
|
@@ -57,7 +59,9 @@ export interface MatchesAnySelectProps<TItem = any> extends Omit<SelectProps, 'o
|
|
|
57
59
|
/** Callback function that is called when the user scroll */
|
|
58
60
|
onLoadMore?: () => void;
|
|
59
61
|
}
|
|
60
|
-
export interface MatchesAnyProps<TItem = any> extends Omit<FlexProps, 'children'>, Pick<MatchesAnySelectProps<TItem>, 'objectName' | 'loading' | 'showExtendValue' | 'items' | 'selectedItems' | 'onLoadMore' | 'groupSelectProps' | 'onChangeSearch' | 'renderExtraValues' | 'customItemRenders' | 'listEmptyProps' | 'selectedListEmptyProps' | 'selectedTreeData'> {
|
|
62
|
+
export interface MatchesAnyProps<TItem = any> extends Omit<FlexProps, 'children'>, Pick<MatchesAnySelectProps<TItem>, 'objectName' | 'loading' | 'showExtendValue' | 'items' | 'selectedItems' | 'onLoadMore' | 'groupSelectProps' | 'onChangeSearch' | 'renderExtraValues' | 'customItemRenders' | 'listEmptyProps' | 'selectedListEmptyProps' | 'selectedTreeData' | 'searchValue'> {
|
|
63
|
+
/** Indicates handle search out of component */
|
|
64
|
+
isExternalSearch?: boolean;
|
|
61
65
|
/**
|
|
62
66
|
* Callback function that is called when the apply action is triggered.
|
|
63
67
|
*
|