@antscorp/antsomi-ui 1.3.5-beta.670 → 1.3.5-beta.672

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.
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { MatchesAnyProps, MatchesAnySelectProps } from './types';
3
- export declare const MatchesAny: React.FC<MatchesAnyProps>;
4
- export declare const MatchesAnySelect: React.FC<MatchesAnySelectProps>;
3
+ export declare function MatchesAny<TItem = Record<string, any>>(props: MatchesAnyProps<TItem>): React.JSX.Element;
4
+ export declare function MatchesAnySelect<TItem = Record<string, any>>(props: MatchesAnySelectProps<TItem>): React.JSX.Element;
@@ -9,6 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
+ /* eslint-disable react/function-component-definition */
12
13
  /* eslint-disable react/destructuring-assignment */
13
14
  // Libraries
14
15
  import { ConfigProvider } from 'antd';
@@ -19,7 +20,7 @@ import { EmptyData, PopoverSelect, Select } from '@antscorp/antsomi-ui/es/compon
19
20
  import { Button, Flex, Icon, Input, Popover, Scrollbars, Spin, Typography, Tooltip, } from '@antscorp/antsomi-ui/es/components/atoms';
20
21
  import { ExtendValuePopup } from './components/ExtendValuePopup';
21
22
  // Styled
22
- import { MatchesAnyWrapper, ActionButton, StyledTree, TextButton, GroupSelectButton, } from './styled';
23
+ import { MatchesAnyWrapper, ActionButton, StyledTree, TextButton, GroupSelectButton, ExtraValueLabel, } from './styled';
23
24
  // Locales
24
25
  import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
25
26
  import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
@@ -31,6 +32,7 @@ import { useDeepCompareEffect, useDeepCompareMemo, useIntersectionObserver, } fr
31
32
  // Utils
32
33
  import { flatTree, recursiveSearchItems } from '@antscorp/antsomi-ui/es/utils';
33
34
  import { DataIcon } from '../../icons';
35
+ import clsx from 'clsx';
34
36
  const initialState = {
35
37
  isOpenPopover: false,
36
38
  };
@@ -41,9 +43,9 @@ const matchesAnyInitialState = {
41
43
  };
42
44
  const { t } = i18nInstance;
43
45
  const { Text } = Typography;
44
- export const MatchesAny = props => {
46
+ export function MatchesAny(props) {
45
47
  // Props
46
- const { objectName, loading = false, showExtendValue = true, items, groupSelectProps, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "items", "groupSelectProps", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
48
+ const { objectName, loading = false, showExtendValue = true, items, groupSelectProps, renderExtraValues, customItemRenders, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
47
49
  // State
48
50
  const [state, setState] = useState(matchesAnyInitialState);
49
51
  // Variables
@@ -121,13 +123,24 @@ export const MatchesAny = props => {
121
123
  const onRemoveAll = () => {
122
124
  setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: [] })));
123
125
  };
124
- const renderItemNodeTitle = ({ item, onSelectItem, onRemoveItem, }) => {
126
+ const renderItemNodeTitle = ({ item, mode = 'unselect', onSelectItem, onRemoveItem, }) => {
127
+ var _a, _b, _c;
125
128
  const { isExtendValue, title, subTitle } = item; // Destructure properties from item
126
129
  return (React.createElement(React.Fragment, null,
127
- React.createElement("div", { className: "title-content" },
128
- React.createElement(Text, { ellipsis: { tooltip: true } }, title),
129
- subTitle && (React.createElement(Text, { className: "sub-title", ellipsis: { tooltip: true }, style: { color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 } }, subTitle))),
130
- React.createElement(Flex, { align: "center", gap: 5 },
130
+ React.createElement("div", { className: clsx('title-content', {
131
+ 'extra-value': !!(renderExtraValues === null || renderExtraValues === void 0 ? void 0 : renderExtraValues.length),
132
+ }) },
133
+ React.createElement(Flex, { vertical: true, gap: 5, className: "left-content" },
134
+ React.createElement(Text, { ellipsis: { tooltip: `${item.title || ''}` } }, ((_a = customItemRenders === null || customItemRenders === void 0 ? void 0 : customItemRenders.title) === null || _a === void 0 ? void 0 : _a.call(customItemRenders, item)) || title),
135
+ subTitle && (React.createElement(Text, { className: "sub-title", ellipsis: { tooltip: `${item.subTitle || ''}` }, style: { color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 } }, ((_b = customItemRenders === null || customItemRenders === void 0 ? void 0 : customItemRenders.subTitle) === null || _b === void 0 ? void 0 : _b.call(customItemRenders, item)) || subTitle))),
136
+ !!(renderExtraValues === null || renderExtraValues === void 0 ? void 0 : renderExtraValues.length) && (React.createElement(Flex, { align: "center", gap: 10 }, renderExtraValues.map(extraValue => (React.createElement("div", { className: "extra-value-content", key: `${extraValue.key}` },
137
+ React.createElement(Text, { ellipsis: { tooltip: true } }, extraValue.render
138
+ ? typeof extraValue.render === 'function'
139
+ ? extraValue.render(item)
140
+ : extraValue.render
141
+ : item[extraValue.key]))))))),
142
+ React.createElement(Flex, { align: "center", gap: 10 },
143
+ mode === 'select' && ((_c = customItemRenders === null || customItemRenders === void 0 ? void 0 : customItemRenders.status) === null || _c === void 0 ? void 0 : _c.call(customItemRenders, item)),
131
144
  isExtendValue && (React.createElement(Icon, { type: "icon-ants-empty-flag", size: 20, color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.colorPrimary })),
132
145
  React.createElement(ActionButton, { className: "select-button", align: "center", justify: "center", onClick: () => {
133
146
  // Call onSelectItem function if provided
@@ -199,13 +212,13 @@ export const MatchesAny = props => {
199
212
  ? flatTree(item.children, 'children').some(item => notExtendValueSelectedItems === null || notExtendValueSelectedItems === void 0 ? void 0 : notExtendValueSelectedItems.some(selectedItem => selectedItem.key === item.key))
200
213
  : notExtendValueSelectedItems === null || notExtendValueSelectedItems === void 0 ? void 0 : notExtendValueSelectedItems.some(selectedItem => selectedItem.key === item.key);
201
214
  return isSelected;
202
- })) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, onRemoveItem }) }), (item.children
215
+ })) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, mode: 'select', onRemoveItem }) }), (item.children
203
216
  ? {
204
217
  children: serializeTreeData(item.children),
205
218
  }
206
219
  : { className: 'leaf-node' }))))) || [];
207
220
  };
208
- return serializeTreeData(items || []).concat(((_a = [...lazyLoadSelectedItems, ...extendValueSelectedItems]) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, onRemoveItem }) })))) || []);
221
+ return serializeTreeData(items || []).concat(((_a = [...lazyLoadSelectedItems, ...extendValueSelectedItems]) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, mode: 'select', onRemoveItem }) })))) || []);
209
222
  }, [items, selectedItems]);
210
223
  const isDisableRemoveAll = useDeepCompareMemo(() => !(selectedTreeData === null || selectedTreeData === void 0 ? void 0 : selectedTreeData.length), [selectedTreeData]);
211
224
  const isDisableSelectAll = useDeepCompareMemo(() => {
@@ -213,6 +226,13 @@ export const MatchesAny = props => {
213
226
  return !(flattenTreeData === null || flattenTreeData === void 0 ? void 0 : flattenTreeData.some(item => !item.disabled));
214
227
  }, [treeData]);
215
228
  // Renders
229
+ const renderExtraValueLabels = () => {
230
+ if (renderExtraValues === null || renderExtraValues === void 0 ? void 0 : renderExtraValues.length) {
231
+ return renderExtraValues.map((extraValue, index) => (React.createElement(ExtraValueLabel, { key: extraValue.key || index },
232
+ React.createElement(Text, { strong: true, ellipsis: { tooltip: true } }, extraValue.label))));
233
+ }
234
+ return null;
235
+ };
216
236
  const renderSelectList = () => {
217
237
  var _a, _b;
218
238
  return (React.createElement("div", { className: "matches-any__section matches-any__section--left" },
@@ -224,11 +244,18 @@ export const MatchesAny = props => {
224
244
  ":"),
225
245
  `${((_a = groupSelectProps === null || groupSelectProps === void 0 ? void 0 : groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.length) || 0} ${t(translations.global.selected)}`))),
226
246
  React.createElement("div", { style: { width: '100%' } },
227
- React.createElement(Input.CustomSearch, { placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => setState(prev => (Object.assign(Object.assign({}, prev), { searchValue }))) }))),
247
+ React.createElement(Input.CustomSearch, { placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => {
248
+ setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
249
+ if (onChangeSearch) {
250
+ onChangeSearch(searchValue);
251
+ }
252
+ } }))),
228
253
  React.createElement("div", { className: "matches-any__body" },
229
254
  React.createElement(Flex, { align: "center", justify: "space-between" },
230
255
  React.createElement(Text, { strong: true }, `${objectName} (${flatTree(items, 'children').filter(item => !item.children).length})`),
231
- React.createElement(TextButton, { disabled: isDisableSelectAll, onClick: onSelectAll }, t(translations.global.selectAll).toString())),
256
+ React.createElement(Flex, { align: "center", gap: 10 },
257
+ renderExtraValueLabels(),
258
+ React.createElement(TextButton, { disabled: isDisableSelectAll, onClick: onSelectAll }, t(translations.global.selectAll).toString()))),
232
259
  React.createElement(Spin, { spinning: loading },
233
260
  React.createElement(Scrollbars, { style: { height: '100%' } }, (treeData === null || treeData === void 0 ? void 0 : treeData.length) ? (React.createElement(React.Fragment, null,
234
261
  React.createElement(StyledTree, { key: searchValue, defaultExpandedKeys: matchedParents.map(item => item.key), selectable: false, treeData: treeData, switcherIcon: props => (React.createElement(Icon, { type: "icon-ants-caret-down", style: {
@@ -272,10 +299,10 @@ export const MatchesAny = props => {
272
299
  React.createElement(Button, { onClick: () => onCancel() }, t(translations.cancel.title).toString())),
273
300
  showExtendValue && (React.createElement(ExtendValuePopup, { onApply: onApplyExtendValue },
274
301
  React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-empty-flag" }) }, t(translations.extendValue.title).toString())))))));
275
- };
276
- export const MatchesAnySelect = props => {
302
+ }
303
+ export function MatchesAnySelect(props) {
277
304
  var _a, _b, _c;
278
- const { placeholder = 'Select an item', dropdownStyle, objectName, selectedItems, items, loading, popupClassName, groupSelectProps, onChange = () => { }, onLoadMore } = props, restProps = __rest(props, ["placeholder", "dropdownStyle", "objectName", "selectedItems", "items", "loading", "popupClassName", "groupSelectProps", "onChange", "onLoadMore"]);
305
+ const { placeholder = 'Select an item', dropdownStyle, objectName, selectedItems, items, loading, popupClassName, groupSelectProps, renderExtraValues, customItemRenders, popoverProps, onChangeSearch, onChange = () => { }, onLoadMore } = props, restProps = __rest(props, ["placeholder", "dropdownStyle", "objectName", "selectedItems", "items", "loading", "popupClassName", "groupSelectProps", "renderExtraValues", "customItemRenders", "popoverProps", "onChangeSearch", "onChange", "onLoadMore"]);
279
306
  // State
280
307
  const [state, setState] = useState(initialState);
281
308
  // Variables
@@ -288,14 +315,14 @@ export const MatchesAnySelect = props => {
288
315
  onChange(selectedItems);
289
316
  setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
290
317
  };
291
- return (React.createElement(Popover, { open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, groupSelectProps: groupSelectProps, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
318
+ 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, onChangeSearch: onChangeSearch, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
292
319
  overflow: {
293
320
  shiftY: 0,
294
321
  shiftX: 0,
295
322
  },
296
323
  }, overlayStyle: { width: 700 }, overlayInnerStyle: {
297
324
  padding: 0,
298
- }, trigger: ['click'], destroyTooltipOnHide: true, onOpenChange: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: !isOpenPopover }))) },
325
+ }, trigger: ['click'], destroyTooltipOnHide: true, onOpenChange: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: !isOpenPopover }))), zIndex: 1400 }, popoverProps),
299
326
  React.createElement(Tooltip, { mouseEnterDelay: 0.5, title: `${selectedItems ? selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.map(item => item.title).join(', ') : ''}` },
300
327
  React.createElement(Select, Object.assign({ title: "", value: value, placeholder: placeholder, popupMatchSelectWidth: 700, dropdownStyle: Object.assign(Object.assign({}, dropdownStyle), { display: 'none', padding: 0 }), loading: loading }, restProps)))));
301
- };
328
+ }
@@ -1,3 +1,22 @@
1
1
  import { ThemeConfig, TreeDataNode } from 'antd';
2
+ /** The width of the extra value */
3
+ export declare const EXTRA_VALUE_WIDTH = 70;
4
+ /** The shift width of the extra value */
5
+ export declare const EXTRA_VALUE_SHIFT_WIDTH = 54;
2
6
  export declare const SAMPLE_DATA: TreeDataNode[];
3
7
  export declare const MATCHES_ANY_THEME: ThemeConfig;
8
+ export declare const EXTRA_VALUE_SAMPLE_DATA: {
9
+ rowCount: string;
10
+ portalId: number;
11
+ itemTypeId: number;
12
+ status: number;
13
+ isSort: number;
14
+ isFilter: number;
15
+ preDefined: number;
16
+ segmentSize: string;
17
+ utime: string;
18
+ processStatus: string;
19
+ id: number;
20
+ name: string;
21
+ code: string;
22
+ }[];
@@ -1,3 +1,7 @@
1
+ /** The width of the extra value */
2
+ export const EXTRA_VALUE_WIDTH = 70;
3
+ /** The shift width of the extra value */
4
+ export const EXTRA_VALUE_SHIFT_WIDTH = 54;
1
5
  export const SAMPLE_DATA = [
2
6
  {
3
7
  key: '12179',
@@ -302,3 +306,80 @@ export const MATCHES_ANY_THEME = {
302
306
  },
303
307
  },
304
308
  };
309
+ export const EXTRA_VALUE_SAMPLE_DATA = [
310
+ {
311
+ rowCount: '5',
312
+ portalId: 564890051,
313
+ itemTypeId: -1003,
314
+ status: 3,
315
+ isSort: 1,
316
+ isFilter: 1,
317
+ preDefined: 0,
318
+ segmentSize: '91',
319
+ utime: '2024-03-06T18:00:03.336Z',
320
+ processStatus: '2',
321
+ id: 5110110,
322
+ name: 'ANTSOMI',
323
+ code: 'sgmt_5110110',
324
+ },
325
+ {
326
+ rowCount: '5',
327
+ portalId: 564890051,
328
+ itemTypeId: -1003,
329
+ status: 4,
330
+ isSort: 1,
331
+ isFilter: 1,
332
+ preDefined: 0,
333
+ segmentSize: '686',
334
+ utime: '2024-08-12T07:56:53.750Z',
335
+ processStatus: '2',
336
+ id: 5562963,
337
+ name: 'CLIENT',
338
+ code: 'sgmt_5562963',
339
+ },
340
+ {
341
+ rowCount: '5',
342
+ portalId: 564890051,
343
+ itemTypeId: -1003,
344
+ status: 2,
345
+ isSort: 1,
346
+ isFilter: 1,
347
+ preDefined: 0,
348
+ segmentSize: '265',
349
+ utime: '2024-05-14T09:48:16.678Z',
350
+ processStatus: '2',
351
+ id: 16368074,
352
+ name: 'Lead BSS send to client 14/5',
353
+ code: 'sgmt_16368074',
354
+ },
355
+ {
356
+ rowCount: '5',
357
+ portalId: 564890051,
358
+ itemTypeId: -1003,
359
+ status: 1,
360
+ isSort: 1,
361
+ isFilter: 1,
362
+ preDefined: 0,
363
+ segmentSize: '49',
364
+ utime: '2024-06-24T10:48:40.007Z',
365
+ processStatus: '2',
366
+ id: 17172749,
367
+ name: 'Customer - Antsomian',
368
+ code: 'sgmt_17172749',
369
+ },
370
+ {
371
+ rowCount: '5',
372
+ portalId: 564890051,
373
+ itemTypeId: -1003,
374
+ status: 1,
375
+ isSort: 1,
376
+ isFilter: 1,
377
+ preDefined: 0,
378
+ segmentSize: '534',
379
+ utime: '2024-06-26T08:57:01.839Z',
380
+ processStatus: '2',
381
+ id: 17190312,
382
+ name: 'Ba thang chua quay lai App OCB',
383
+ code: 'sgmt_17190312',
384
+ },
385
+ ];
@@ -18,3 +18,5 @@ export declare const StyledTree: import("styled-components").StyledComponent<(<T
18
18
  };
19
19
  }, any, {}, never>;
20
20
  export declare const TextArea: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/input").TextAreaProps & import("react").RefAttributes<import("antd/es/input/TextArea").TextAreaRef>>, any, {}, never>;
21
+ export declare const ExtraValueLabel: import("styled-components").StyledComponent<"div", any, {}, never>;
22
+ export declare const ItemStatus: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
@@ -5,6 +5,7 @@ import { Button, Flex, Input, Typography } from '@antscorp/antsomi-ui/es/compone
5
5
  import { Tree } from '@antscorp/antsomi-ui/es/components/molecules';
6
6
  // Constants
7
7
  import { globalToken } from '@antscorp/antsomi-ui/es/constants';
8
+ import { EXTRA_VALUE_SHIFT_WIDTH, EXTRA_VALUE_WIDTH } from './constants';
8
9
  const { borderRadius, bw3, bw6, blue, blue1, colorPrimary } = globalToken || {};
9
10
  export const MatchesAnyWrapper = styled(Flex) `
10
11
  width: 100%;
@@ -94,14 +95,32 @@ export const MatchesAnyWrapper = styled(Flex) `
94
95
  .title-content {
95
96
  padding: 5px 0px;
96
97
  display: flex;
97
- flex-direction: column;
98
+ align-items: center;
99
+ justify-content: space-between;
100
+ gap: 10px;
98
101
  width: 100%;
99
102
  height: 100%;
100
103
  overflow: auto;
101
104
 
105
+ > .left-content {
106
+ width: 100%;
107
+ overflow: auto;
108
+ }
109
+
102
110
  .sub-title {
103
111
  font-size: 11px;
104
112
  }
113
+
114
+ .extra-value-content {
115
+ display: flex;
116
+ align-items: center;
117
+ justify-content: center;
118
+ width: ${EXTRA_VALUE_WIDTH}px;
119
+ }
120
+
121
+ &.extra-value {
122
+ width: calc(100% - ${EXTRA_VALUE_SHIFT_WIDTH}px);
123
+ }
105
124
  }
106
125
  }
107
126
  }
@@ -169,6 +188,7 @@ export const MatchesAnyWrapper = styled(Flex) `
169
188
  `;
170
189
  export const TextButton = styled(Typography.Text) `
171
190
  color: ${colorPrimary} !important;
191
+ font-weight: 500;
172
192
  cursor: pointer;
173
193
 
174
194
  ${props => props.disabled &&
@@ -201,3 +221,10 @@ export const TextArea = styled(Input.TextArea) `
201
221
  border-radius: ${borderRadius}px;
202
222
  }
203
223
  `;
224
+ export const ExtraValueLabel = styled.div `
225
+ width: ${EXTRA_VALUE_WIDTH}px;
226
+ display: flex;
227
+ align-items: center;
228
+ justify-content: center;
229
+ `;
230
+ export const ItemStatus = styled(Flex) ``;
@@ -1,44 +1,61 @@
1
1
  import { TreeDataNode } from 'antd';
2
+ import { ReactNode } from 'react';
2
3
  import type { SelectProps } from '@antscorp/antsomi-ui/es/components/molecules';
3
- import type { FlexProps } from '@antscorp/antsomi-ui/es/components/atoms';
4
+ import type { FlexProps, PopoverProps } from '@antscorp/antsomi-ui/es/components/atoms';
4
5
  import { PopoverSelectProps } from '../SearchPopover/types';
5
- export type MatchesAnyItem = TreeDataNode & {
6
+ export type MatchesAnyItem<TItem = Record<string, any>> = TreeDataNode & {
6
7
  /** Addition title of the item. */
7
8
  subTitle?: string;
8
9
  /** Indicates whether the item is extended */
9
10
  isExtendValue?: boolean;
10
11
  /** An array of children items. */
11
- children?: MatchesAnyItem[];
12
- };
12
+ children?: MatchesAnyItem<TItem>[];
13
+ } & TItem;
13
14
  export type GroupSelectProps = PopoverSelectProps & {
14
15
  /** Name of the group select to be displayed */
15
16
  name?: string;
16
17
  };
17
- export interface MatchesAnySelectProps extends SelectProps {
18
+ export type RenderExtraValue<TItem = Record<string, any>> = {
19
+ key: keyof MatchesAnyItem<TItem>;
20
+ label: string;
21
+ render?: (item: MatchesAnyItem<TItem>) => ReactNode | ReactNode;
22
+ };
23
+ export type CustomItemRenders<TItem> = {
24
+ title?: (item: MatchesAnyItem<TItem>) => ReactNode;
25
+ subTitle?: (item: MatchesAnyItem<TItem>) => ReactNode;
26
+ status?: (item: MatchesAnyItem<TItem>) => ReactNode;
27
+ };
28
+ export interface MatchesAnySelectProps<TItem = Record<string, any>> extends SelectProps {
18
29
  /** The name of object to be displayed in Popover */
19
30
  objectName?: string;
20
31
  /** Indicates whether show the extend value button */
21
32
  showExtendValue?: boolean;
22
33
  /** An array of items. */
23
- items?: MatchesAnyItem[];
34
+ items?: MatchesAnyItem<TItem>[];
24
35
  /** An array of selected items. */
25
- selectedItems?: MatchesAnyItem[];
36
+ selectedItems?: MatchesAnyItem<TItem>[];
26
37
  /** The properties of the group select */
27
38
  groupSelectProps?: GroupSelectProps;
39
+ /** An array of render extra values */
40
+ renderExtraValues?: RenderExtraValue<TItem>[];
41
+ /** Custom item renders */
42
+ customItemRenders?: CustomItemRenders<TItem>;
43
+ /** Popover Props */
44
+ popoverProps?: Partial<PopoverProps>;
28
45
  /** Callback function that is called when the selected items change. */
29
- onChange?: (selectedItems: MatchesAnyItem[]) => void;
46
+ onChange?: (selectedItems: MatchesAnyItem<TItem>[]) => void;
30
47
  /** Callback function that is called when the search value changes */
31
48
  onChangeSearch?: (searchValue: string) => void;
32
49
  /** Callback function that is called when the user scroll */
33
50
  onLoadMore?: () => void;
34
51
  }
35
- export interface MatchesAnyProps extends Omit<FlexProps, 'children'>, Pick<MatchesAnySelectProps, 'objectName' | 'loading' | 'showExtendValue' | 'items' | 'selectedItems' | 'onLoadMore' | 'groupSelectProps' | 'onChangeSearch'> {
52
+ export interface MatchesAnyProps<TItem = Record<string, any>> extends Omit<FlexProps, 'children'>, Pick<MatchesAnySelectProps<TItem>, 'objectName' | 'loading' | 'showExtendValue' | 'items' | 'selectedItems' | 'onLoadMore' | 'groupSelectProps' | 'onChangeSearch' | 'renderExtraValues' | 'customItemRenders'> {
36
53
  /**
37
54
  * Callback function that is called when the apply action is triggered.
38
55
  *
39
56
  * @param selectedItems - The array of selected items.
40
57
  */
41
- onApply?: (selectedItems: MatchesAnyItem[]) => void;
58
+ onApply?: (selectedItems: MatchesAnyItem<TItem>[]) => void;
42
59
  /** Callback function that is called when the cancel action is triggered. */
43
60
  onCancel?: () => void;
44
61
  }
package/es/test.js CHANGED
@@ -19,7 +19,9 @@ import { GET_LIST_TYPE, OBJECT_TYPES, PUBLIC_LEVEL } from './constants';
19
19
  import axios from 'axios';
20
20
  import { get } from 'lodash';
21
21
  import { MENU_PERMISSION } from './components/molecules/ShareAccess/constants';
22
+ import { QueryClientProviderAntsomiUI, queryClientAntsomiUI } from './queries';
22
23
  import { ConfigProvider } from './providers';
24
+ import { MatchesAnySelectTest } from './tests';
23
25
  const SHARE_ACCESS_DEFAULT_VALUE = {
24
26
  ownerId: 1600085510,
25
27
  isPublic: 1,
@@ -106,7 +108,7 @@ export const App = () => {
106
108
  console.log({ type, data });
107
109
  };
108
110
  /* MatchesAnySelect */
109
- // return <MatchesAnySelectTest />;
111
+ return React.createElement(MatchesAnySelectTest, null);
110
112
  /* Data Table */
111
113
  return (React.createElement("div", null,
112
114
  "THIS IS TEST VITE BUILD",
@@ -213,7 +215,6 @@ export const App = () => {
213
215
  };
214
216
  const container = document.getElementById('root');
215
217
  const root = createRoot(container);
216
- root.render(
217
- // <QueryClientProviderAntsomiUI client={queryClientAntsomiUI}>
218
- React.createElement(ConfigProvider, { locale: "en" },
219
- React.createElement(App, null)));
218
+ root.render(React.createElement(QueryClientProviderAntsomiUI, { client: queryClientAntsomiUI },
219
+ React.createElement(ConfigProvider, { locale: "en" },
220
+ React.createElement(App, null))));
@@ -1,10 +1,77 @@
1
1
  // Libraries
2
- import React, { useState } from 'react';
3
- import { MATCHES_ANY_SAMPLE_DATA, MatchesAnySelect } from '../components';
2
+ import React, { useMemo, useState } from 'react';
3
+ import { MatchesAnySelect, Tooltip, Typography } from '../components';
4
+ import { EXTRA_VALUE_SAMPLE_DATA } from '../components/molecules/MatchAnySelect/constants';
5
+ import { WarningIcon } from '../components/icons';
6
+ import { recursiveSearchItems } from '../utils';
4
7
  export const MatchesAnySelectTest = () => {
5
8
  const [state, setState] = useState({
6
9
  selectedItems: [],
7
- items: MATCHES_ANY_SAMPLE_DATA,
10
+ items: EXTRA_VALUE_SAMPLE_DATA.map(item => {
11
+ var _a;
12
+ return ({
13
+ key: item.id,
14
+ title: item.name,
15
+ segmentSize: item.segmentSize,
16
+ rowCount: item.rowCount,
17
+ subTitle: (_a = item.id) === null || _a === void 0 ? void 0 : _a.toString(),
18
+ status: item.status,
19
+ });
20
+ }),
21
+ searchValue: '',
8
22
  });
9
- return (React.createElement(MatchesAnySelect, { items: state.items, selectedItems: state.selectedItems, onChange: selectedItems => setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems }))) }));
23
+ const memoItems = useMemo(() => recursiveSearchItems({
24
+ list: state.items || [],
25
+ searchValue: state.searchValue || '',
26
+ searchKeys: ['title', 'key'],
27
+ childrenKey: 'children',
28
+ }).results, [state.items, state.searchValue]);
29
+ console.log('matchesAnyItems:: ', state.items);
30
+ console.log('selectedItems:: ', state.selectedItems);
31
+ return (React.createElement(MatchesAnySelect, { items: memoItems, objectName: "Is member of", selectedItems: state.selectedItems,
32
+ /** Support for render extra values */
33
+ renderExtraValues: [
34
+ {
35
+ key: 'rowCount',
36
+ label: 'Rows',
37
+ },
38
+ {
39
+ key: 'segmentSize',
40
+ label: 'Members',
41
+ render(item) {
42
+ const parseNumber = parseInt(item.segmentSize);
43
+ return isNaN(parseNumber) ? null : parseNumber.toLocaleString();
44
+ },
45
+ },
46
+ ],
47
+ /** Support for custom item renders such as title, subtitle, status */
48
+ customItemRenders: {
49
+ title(item) {
50
+ var _a;
51
+ return (React.createElement(Typography.Link, { href: item.key.toString() }, (_a = item.title) === null || _a === void 0 ? void 0 : _a.toString()));
52
+ },
53
+ status(item) {
54
+ let tooltip = '';
55
+ switch (item.status) {
56
+ case 3:
57
+ tooltip = 'This segment is archived';
58
+ break;
59
+ case 4:
60
+ tooltip = 'This segment does not exist';
61
+ break;
62
+ default:
63
+ break;
64
+ }
65
+ return (!!tooltip && (React.createElement(Tooltip, { title: tooltip },
66
+ React.createElement(WarningIcon, { size: 16 }))));
67
+ },
68
+ },
69
+ /** Support for handle search outside */
70
+ onChangeSearch: searchValue => {
71
+ console.log({ searchValue });
72
+ setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
73
+ }, onChange: selectedItems => {
74
+ console.log({ selectedItems });
75
+ setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems })));
76
+ } }));
10
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.670",
3
+ "version": "1.3.5-beta.672",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",