@antscorp/antsomi-ui 2.0.7 → 2.0.8

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.
@@ -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 { searchValue, selectedItems, selectedTreeData, isShowLoadMoreEl } = state;
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
@@ -165,7 +166,7 @@ export function MatchesAny(props) {
165
166
  const { results, matchedParents } = recursiveSearchItems({
166
167
  list: items || [],
167
168
  searchKeys: ['title', 'key'],
168
- searchValue: !onChangeSearch ? searchValue : '',
169
+ searchValue: !isExternalSearch ? searchValue : '',
169
170
  childrenKey: 'children',
170
171
  });
171
172
  const serializeTreeData = (list) => list.map(item => {
@@ -234,8 +235,7 @@ export function MatchesAny(props) {
234
235
  ":"),
235
236
  `${((_a = groupSelectProps === null || groupSelectProps === void 0 ? void 0 : groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.length) || 0} ${t(translations.global.selected)}`))),
236
237
  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 })));
238
+ React.createElement(Input.CustomSearch, { value: searchValue, placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => {
239
239
  if (onChangeSearch) {
240
240
  onChangeSearch(searchValue);
241
241
  }
@@ -311,12 +311,22 @@ export function MatchesAnySelect(props) {
311
311
  const value = Array.isArray(selectedItems) && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length)
312
312
  ? `${(_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
313
  : undefined;
314
+ // Effects
315
+ useDeepCompareEffect(() => {
316
+ if (props.searchValue && props.searchValue !== state.searchValue) {
317
+ setState(prev => (Object.assign(Object.assign({}, prev), { searchValue: props.searchValue || '' })));
318
+ }
319
+ }, [props.searchValue, state.searchValue]);
314
320
  // Handlers
315
321
  const onApplyMatchesAny = (selectedItems, selectedTreeData) => {
316
322
  onChange(selectedItems, selectedTreeData);
317
323
  setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
318
324
  };
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: onChangeSearch, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
325
+ 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 => {
326
+ setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
327
+ if (onChangeSearch)
328
+ onChangeSearch(searchValue);
329
+ }, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
320
330
  overflow: {
321
331
  shiftY: 0,
322
332
  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
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",