@antscorp/antsomi-ui 1.3.5-beta.669 → 1.3.5-beta.670
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/es/components/molecules/MatchAnySelect/MatchesAnySelect.js +29 -16
- package/es/components/molecules/MatchAnySelect/styled.d.ts +3 -0
- package/es/components/molecules/MatchAnySelect/styled.js +8 -2
- package/es/components/molecules/MatchAnySelect/types.d.ts +10 -13
- package/es/components/molecules/SearchPopover/SearchPopover.js +1 -1
- package/es/components/molecules/SearchPopover/components/PopoverAddField/PopoverAddField.js +10 -7
- package/es/components/molecules/SearchPopover/components/PopoverSelect/PopoverSelect.js +17 -17
- package/es/components/molecules/SearchPopover/components/PopoverSelect/styled.d.ts +2 -2
- package/es/components/molecules/SearchPopover/components/PopoverSelect/styled.js +2 -3
- package/es/components/molecules/SearchPopover/types.d.ts +1 -1
- package/es/constants/theme.js +1 -0
- package/es/utils/common.js +1 -1
- package/package.json +1 -1
|
@@ -13,13 +13,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
// Libraries
|
|
14
14
|
import { ConfigProvider } from 'antd';
|
|
15
15
|
import { uniqBy } from 'lodash';
|
|
16
|
-
import React, { useEffect,
|
|
16
|
+
import React, { useEffect, useState } from 'react';
|
|
17
17
|
// Components
|
|
18
|
-
import { EmptyData, Select } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
18
|
+
import { EmptyData, PopoverSelect, Select } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
19
19
|
import { Button, Flex, Icon, Input, Popover, Scrollbars, Spin, Typography, Tooltip, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
20
20
|
import { ExtendValuePopup } from './components/ExtendValuePopup';
|
|
21
21
|
// Styled
|
|
22
|
-
import { MatchesAnyWrapper, ActionButton, StyledTree, TextButton } from './styled';
|
|
22
|
+
import { MatchesAnyWrapper, ActionButton, StyledTree, TextButton, GroupSelectButton, } from './styled';
|
|
23
23
|
// Locales
|
|
24
24
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
25
25
|
import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
|
|
@@ -43,7 +43,7 @@ const { t } = i18nInstance;
|
|
|
43
43
|
const { Text } = Typography;
|
|
44
44
|
export const MatchesAny = props => {
|
|
45
45
|
// Props
|
|
46
|
-
const { objectName, loading = false, showExtendValue = true, items, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { } } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "items", "onApply", "onCancel", "onLoadMore"]);
|
|
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"]);
|
|
47
47
|
// State
|
|
48
48
|
const [state, setState] = useState(matchesAnyInitialState);
|
|
49
49
|
// Variables
|
|
@@ -142,11 +142,12 @@ export const MatchesAny = props => {
|
|
|
142
142
|
React.createElement(Icon, { type: `icon-ants-${onSelectItem ? 'double-arrow-up' : 'remove-slim'}`, size: 11 })))));
|
|
143
143
|
};
|
|
144
144
|
// Memos
|
|
145
|
-
const { treeData, matchedParents } =
|
|
145
|
+
const { treeData, matchedParents } = useDeepCompareMemo(() => {
|
|
146
|
+
var _a;
|
|
146
147
|
const { results, matchedParents } = recursiveSearchItems({
|
|
147
148
|
list: items || [],
|
|
148
149
|
searchKeys: ['title', 'key'],
|
|
149
|
-
searchValue,
|
|
150
|
+
searchValue: !onChangeSearch ? searchValue : '',
|
|
150
151
|
childrenKey: 'children',
|
|
151
152
|
});
|
|
152
153
|
const serializeTreeData = (list) => list.map(item => {
|
|
@@ -171,10 +172,14 @@ export const MatchesAny = props => {
|
|
|
171
172
|
children: serializeTreeData(item.children),
|
|
172
173
|
}));
|
|
173
174
|
});
|
|
174
|
-
|
|
175
|
+
let treeData = serializeTreeData(results);
|
|
176
|
+
// Filter the tree data based on the group selected items
|
|
177
|
+
if (groupSelectProps && ((_a = groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
178
|
+
treeData = treeData.filter(item => { var _a; return (_a = groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.includes(item.key); });
|
|
179
|
+
}
|
|
175
180
|
return { treeData, matchedParents };
|
|
176
|
-
}, [items, searchValue, selectedItems]);
|
|
177
|
-
const selectedTreeData =
|
|
181
|
+
}, [items, searchValue, selectedItems, groupSelectProps, onChangeSearch]);
|
|
182
|
+
const selectedTreeData = useDeepCompareMemo(() => {
|
|
178
183
|
var _a;
|
|
179
184
|
const notExtendValueSelectedItems = (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => !item.isExtendValue)) || [];
|
|
180
185
|
const extendValueSelectedItems = (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => item.isExtendValue)) || [];
|
|
@@ -194,9 +199,11 @@ export const MatchesAny = props => {
|
|
|
194
199
|
? flatTree(item.children, 'children').some(item => notExtendValueSelectedItems === null || notExtendValueSelectedItems === void 0 ? void 0 : notExtendValueSelectedItems.some(selectedItem => selectedItem.key === item.key))
|
|
195
200
|
: notExtendValueSelectedItems === null || notExtendValueSelectedItems === void 0 ? void 0 : notExtendValueSelectedItems.some(selectedItem => selectedItem.key === item.key);
|
|
196
201
|
return isSelected;
|
|
197
|
-
})) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, onRemoveItem }) }), (item.children
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
})) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, onRemoveItem }) }), (item.children
|
|
203
|
+
? {
|
|
204
|
+
children: serializeTreeData(item.children),
|
|
205
|
+
}
|
|
206
|
+
: { className: 'leaf-node' }))))) || [];
|
|
200
207
|
};
|
|
201
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 }) })))) || []);
|
|
202
209
|
}, [items, selectedItems]);
|
|
@@ -207,11 +214,17 @@ export const MatchesAny = props => {
|
|
|
207
214
|
}, [treeData]);
|
|
208
215
|
// Renders
|
|
209
216
|
const renderSelectList = () => {
|
|
210
|
-
var _a;
|
|
217
|
+
var _a, _b;
|
|
211
218
|
return (React.createElement("div", { className: "matches-any__section matches-any__section--left" },
|
|
212
219
|
React.createElement("div", { className: "matches-any__header" },
|
|
220
|
+
!!groupSelectProps && (React.createElement(PopoverSelect, Object.assign({}, groupSelectProps),
|
|
221
|
+
React.createElement(GroupSelectButton, { type: "default", size: "small", shape: "round" },
|
|
222
|
+
React.createElement("span", { className: "group-name" }, groupSelectProps === null || groupSelectProps === void 0 ? void 0 :
|
|
223
|
+
groupSelectProps.name,
|
|
224
|
+
":"),
|
|
225
|
+
`${((_a = groupSelectProps === null || groupSelectProps === void 0 ? void 0 : groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.length) || 0} ${t(translations.global.selected)}`))),
|
|
213
226
|
React.createElement("div", { style: { width: '100%' } },
|
|
214
|
-
React.createElement(Input.CustomSearch, { placeholder: `${(
|
|
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 }))) }))),
|
|
215
228
|
React.createElement("div", { className: "matches-any__body" },
|
|
216
229
|
React.createElement(Flex, { align: "center", justify: "space-between" },
|
|
217
230
|
React.createElement(Text, { strong: true }, `${objectName} (${flatTree(items, 'children').filter(item => !item.children).length})`),
|
|
@@ -262,7 +275,7 @@ export const MatchesAny = props => {
|
|
|
262
275
|
};
|
|
263
276
|
export const MatchesAnySelect = props => {
|
|
264
277
|
var _a, _b, _c;
|
|
265
|
-
const { placeholder = 'Select an item', dropdownStyle, objectName, selectedItems, items, loading, popupClassName, onChange = () => { }, onLoadMore } = props, restProps = __rest(props, ["placeholder", "dropdownStyle", "objectName", "selectedItems", "items", "loading", "popupClassName", "onChange", "onLoadMore"]);
|
|
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"]);
|
|
266
279
|
// State
|
|
267
280
|
const [state, setState] = useState(initialState);
|
|
268
281
|
// Variables
|
|
@@ -275,7 +288,7 @@ export const MatchesAnySelect = props => {
|
|
|
275
288
|
onChange(selectedItems);
|
|
276
289
|
setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
|
|
277
290
|
};
|
|
278
|
-
return (React.createElement(Popover, { open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
|
|
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: {
|
|
279
292
|
overflow: {
|
|
280
293
|
shiftY: 0,
|
|
281
294
|
shiftX: 0,
|
|
@@ -3,6 +3,9 @@ export declare const MatchesAnyWrapper: import("styled-components").StyledCompon
|
|
|
3
3
|
export declare const TextButton: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/typography/Text").TextProps & import("react").RefAttributes<HTMLSpanElement>>, any, {
|
|
4
4
|
disabled?: boolean | undefined;
|
|
5
5
|
}, never>;
|
|
6
|
+
export declare const GroupSelectButton: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/button/button").ButtonProps & import("react").RefAttributes<HTMLElement>> & {
|
|
7
|
+
Group: import("react").FC<import("antd/es/button").ButtonGroupProps>;
|
|
8
|
+
}, any, {}, never>;
|
|
6
9
|
export declare const ActionButton: 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>;
|
|
7
10
|
export declare const StyledTree: import("styled-components").StyledComponent<(<T extends import("rc-tree").BasicDataNode | import("rc-tree/lib/interface").DataNode = import("rc-tree/lib/interface").DataNode>(props: import("antd/es/tree/Tree").TreeProps<T> & {
|
|
8
11
|
children?: import("react").ReactNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import styled, { css } from 'styled-components';
|
|
3
3
|
// Components
|
|
4
|
-
import { Flex, Input, Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
4
|
+
import { Button, Flex, Input, Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
5
5
|
import { Tree } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
6
6
|
// Constants
|
|
7
7
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
@@ -11,7 +11,6 @@ export const MatchesAnyWrapper = styled(Flex) `
|
|
|
11
11
|
height: 550px;
|
|
12
12
|
|
|
13
13
|
.matches-any {
|
|
14
|
-
background-color: red;
|
|
15
14
|
&__header {
|
|
16
15
|
display: flex;
|
|
17
16
|
align-items: center;
|
|
@@ -19,6 +18,7 @@ export const MatchesAnyWrapper = styled(Flex) `
|
|
|
19
18
|
box-sizing: border-box;
|
|
20
19
|
padding: 0px 15px;
|
|
21
20
|
border-bottom: 1px solid ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw3};
|
|
21
|
+
gap: 10px;
|
|
22
22
|
|
|
23
23
|
.antsomi-search-input {
|
|
24
24
|
padding-left: 0px;
|
|
@@ -177,6 +177,12 @@ export const TextButton = styled(Typography.Text) `
|
|
|
177
177
|
pointer-events: none;
|
|
178
178
|
`}
|
|
179
179
|
`;
|
|
180
|
+
export const GroupSelectButton = styled(Button) `
|
|
181
|
+
gap: 4px !important;
|
|
182
|
+
.group-name {
|
|
183
|
+
font-weight: normal !important;
|
|
184
|
+
}
|
|
185
|
+
`;
|
|
180
186
|
export const ActionButton = styled(Flex) `
|
|
181
187
|
height: 16px;
|
|
182
188
|
width: 16px;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TreeDataNode } from 'antd';
|
|
2
2
|
import type { SelectProps } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
3
3
|
import type { FlexProps } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
4
|
+
import { PopoverSelectProps } from '../SearchPopover/types';
|
|
4
5
|
export type MatchesAnyItem = TreeDataNode & {
|
|
5
6
|
/** Addition title of the item. */
|
|
6
7
|
subTitle?: string;
|
|
@@ -9,6 +10,10 @@ export type MatchesAnyItem = TreeDataNode & {
|
|
|
9
10
|
/** An array of children items. */
|
|
10
11
|
children?: MatchesAnyItem[];
|
|
11
12
|
};
|
|
13
|
+
export type GroupSelectProps = PopoverSelectProps & {
|
|
14
|
+
/** Name of the group select to be displayed */
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
12
17
|
export interface MatchesAnySelectProps extends SelectProps {
|
|
13
18
|
/** The name of object to be displayed in Popover */
|
|
14
19
|
objectName?: string;
|
|
@@ -18,22 +23,16 @@ export interface MatchesAnySelectProps extends SelectProps {
|
|
|
18
23
|
items?: MatchesAnyItem[];
|
|
19
24
|
/** An array of selected items. */
|
|
20
25
|
selectedItems?: MatchesAnyItem[];
|
|
26
|
+
/** The properties of the group select */
|
|
27
|
+
groupSelectProps?: GroupSelectProps;
|
|
21
28
|
/** Callback function that is called when the selected items change. */
|
|
22
29
|
onChange?: (selectedItems: MatchesAnyItem[]) => void;
|
|
30
|
+
/** Callback function that is called when the search value changes */
|
|
31
|
+
onChangeSearch?: (searchValue: string) => void;
|
|
23
32
|
/** Callback function that is called when the user scroll */
|
|
24
33
|
onLoadMore?: () => void;
|
|
25
34
|
}
|
|
26
|
-
export interface MatchesAnyProps extends Omit<FlexProps, 'children'> {
|
|
27
|
-
/** The name of the object, corresponding to the `objectName` property in `MatchesAnySelectProps`. */
|
|
28
|
-
objectName?: MatchesAnySelectProps['objectName'];
|
|
29
|
-
/** Indicates whether the component is in a loading state, corresponding to the `isLoading` property in `MatchesAnySelectProps`. */
|
|
30
|
-
loading?: MatchesAnySelectProps['loading'];
|
|
31
|
-
/** Determines whether to show the extended value, corresponding to the `showExtendValue` property in `MatchesAnySelectProps`. */
|
|
32
|
-
showExtendValue?: MatchesAnySelectProps['showExtendValue'];
|
|
33
|
-
/** An array of items. */
|
|
34
|
-
items?: MatchesAnySelectProps['items'];
|
|
35
|
-
/** An array of selected items. */
|
|
36
|
-
selectedItems?: MatchesAnySelectProps['selectedItems'];
|
|
35
|
+
export interface MatchesAnyProps extends Omit<FlexProps, 'children'>, Pick<MatchesAnySelectProps, 'objectName' | 'loading' | 'showExtendValue' | 'items' | 'selectedItems' | 'onLoadMore' | 'groupSelectProps' | 'onChangeSearch'> {
|
|
37
36
|
/**
|
|
38
37
|
* Callback function that is called when the apply action is triggered.
|
|
39
38
|
*
|
|
@@ -42,6 +41,4 @@ export interface MatchesAnyProps extends Omit<FlexProps, 'children'> {
|
|
|
42
41
|
onApply?: (selectedItems: MatchesAnyItem[]) => void;
|
|
43
42
|
/** Callback function that is called when the cancel action is triggered. */
|
|
44
43
|
onCancel?: () => void;
|
|
45
|
-
/** Callback function that is called when the user scroll */
|
|
46
|
-
onLoadMore?: MatchesAnySelectProps['onLoadMore'];
|
|
47
44
|
}
|
|
@@ -18,7 +18,7 @@ import { StyledInput } from './styled';
|
|
|
18
18
|
export const SearchPopover = (props) => {
|
|
19
19
|
const { inputSearchProps = {} } = props, popoverProps = __rest(props, ["inputSearchProps"]);
|
|
20
20
|
const { overlayClassName, arrow = false, children, content, trigger = ['click'] } = popoverProps, restPopoverProps = __rest(popoverProps, ["overlayClassName", "arrow", "children", "content", "trigger"]);
|
|
21
|
-
return (React.createElement(Popover, Object.assign({ trigger: trigger, arrow: arrow }, restPopoverProps, { overlayClassName: clsx('search-popover-overlay', overlayClassName), overlay: true, content: React.createElement(React.Fragment, null,
|
|
21
|
+
return (React.createElement(Popover, Object.assign({ trigger: trigger, arrow: arrow, destroyTooltipOnHide: true }, restPopoverProps, { overlayClassName: clsx('search-popover-overlay', overlayClassName), overlay: true, content: React.createElement(React.Fragment, null,
|
|
22
22
|
React.createElement(StyledInput, Object.assign({ placeholder: (inputSearchProps === null || inputSearchProps === void 0 ? void 0 : inputSearchProps.placeholder) || 'Search...', bordered: false }, inputSearchProps, { addonAfter: React.createElement(Icon, { type: "icon-ants-search-2" }), withWrapper: false })),
|
|
23
23
|
content) }), children));
|
|
24
24
|
};
|
|
@@ -11,21 +11,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React, { useCallback, useMemo } from 'react';
|
|
13
13
|
import clsx from 'clsx';
|
|
14
|
+
import { Button, Icon } from '../../../../atoms';
|
|
14
15
|
import { renderIconField } from '../../utils';
|
|
15
16
|
import { PopoverSelect } from '../PopoverSelect';
|
|
16
17
|
import { Typography } from 'antd';
|
|
17
18
|
export const PopoverAddField = (props) => {
|
|
18
|
-
const { fields, onSearchPredicate, className } = props, rest = __rest(props, ["fields", "onSearchPredicate", "className"]);
|
|
19
|
+
const { fields, onSearchPredicate, className, children } = props, rest = __rest(props, ["fields", "onSearchPredicate", "className", "children"]);
|
|
19
20
|
const originalFieldByKey = useMemo(() => new Map(fields.map(field => [field.key, field])), [fields]);
|
|
20
|
-
const handleOnSearchPredicate = (
|
|
21
|
-
const originalField = originalFieldByKey.get(
|
|
21
|
+
const handleOnSearchPredicate = useCallback((option) => {
|
|
22
|
+
const originalField = originalFieldByKey.get(option.key);
|
|
22
23
|
if (!originalField)
|
|
23
|
-
return
|
|
24
|
+
return false;
|
|
24
25
|
if (onSearchPredicate && originalField) {
|
|
25
26
|
return onSearchPredicate(originalField);
|
|
26
27
|
}
|
|
27
|
-
return
|
|
28
|
-
};
|
|
28
|
+
return false;
|
|
29
|
+
}, [onSearchPredicate, originalFieldByKey]);
|
|
29
30
|
const options = useCallback((params) => fields.map(field => (Object.assign(Object.assign({}, field), { label: (React.createElement(React.Fragment, null,
|
|
30
31
|
field.dataType && renderIconField(field.dataType),
|
|
31
32
|
typeof field.label === 'string' && (React.createElement(Typography.Text, { ellipsis: {
|
|
@@ -35,5 +36,7 @@ export const PopoverAddField = (props) => {
|
|
|
35
36
|
field.label({
|
|
36
37
|
selected: params.selected.includes(field.key),
|
|
37
38
|
}))) }))), [fields]);
|
|
38
|
-
return (React.createElement(PopoverSelect, Object.assign({}, rest, { options: options, onSearchPredicate: handleOnSearchPredicate, className: clsx(className, 'ants-popover-add-fields') })
|
|
39
|
+
return (React.createElement(PopoverSelect, Object.assign({}, rest, { options: options, onSearchPredicate: handleOnSearchPredicate, className: clsx(className, 'ants-popover-add-fields') }), children || (React.createElement(Button, { type: "text" },
|
|
40
|
+
React.createElement(Icon, { type: "icon-ants-plus-slim", size: 14 }),
|
|
41
|
+
"Add fields"))));
|
|
39
42
|
};
|
|
@@ -14,7 +14,7 @@ import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
|
14
14
|
import { SearchPopover } from '../../SearchPopover';
|
|
15
15
|
import './styles.scss';
|
|
16
16
|
import { searchStringQuery } from '@antscorp/antsomi-ui/es/utils';
|
|
17
|
-
import { Button, Checkbox
|
|
17
|
+
import { Button, Checkbox } from '../../../../atoms';
|
|
18
18
|
import { StyledAction, StyledFooter, StyledListFieldsWrapper } from './styled';
|
|
19
19
|
import { List } from 'antd';
|
|
20
20
|
export const PopoverSelect = (props) => {
|
|
@@ -48,18 +48,20 @@ export const PopoverSelect = (props) => {
|
|
|
48
48
|
setSelectedKeys(new Set(selected));
|
|
49
49
|
}
|
|
50
50
|
}, [selected]);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (refOnSearchPredicate.current) {
|
|
54
|
-
const isFilteredOption = refOnSearchPredicate.current(field);
|
|
55
|
-
return isFilteredOption;
|
|
56
|
-
}
|
|
51
|
+
const filteredOptions = useMemo(() => {
|
|
52
|
+
const defaultFilter = (opt) => {
|
|
57
53
|
let labelIncluded = false;
|
|
58
|
-
if (typeof
|
|
59
|
-
labelIncluded = searchStringQuery(
|
|
54
|
+
if (typeof opt.label === 'string') {
|
|
55
|
+
labelIncluded = searchStringQuery(opt.label, search);
|
|
60
56
|
}
|
|
61
|
-
const keyIncluded = searchStringQuery(
|
|
57
|
+
const keyIncluded = searchStringQuery(opt.key, search);
|
|
62
58
|
return keyIncluded || labelIncluded;
|
|
59
|
+
};
|
|
60
|
+
let result = options.filter(field => {
|
|
61
|
+
if (!refOnSearchPredicate.current) {
|
|
62
|
+
return defaultFilter(field);
|
|
63
|
+
}
|
|
64
|
+
return refOnSearchPredicate.current(field) || defaultFilter(field);
|
|
63
65
|
});
|
|
64
66
|
if (showSelected) {
|
|
65
67
|
result = result.filter(field => selectedKeys.has(field.key));
|
|
@@ -117,17 +119,15 @@ export const PopoverSelect = (props) => {
|
|
|
117
119
|
return option.label;
|
|
118
120
|
};
|
|
119
121
|
return (React.createElement(SearchPopover, Object.assign({}, rest, { content: React.createElement(React.Fragment, null,
|
|
120
|
-
|
|
122
|
+
optionsProp.length > 0 && (React.createElement(StyledAction, null,
|
|
121
123
|
React.createElement(Button, { type: "link", size: "small", onClick: () => setShowSelected(current => !current) }, showSelected ? showAllLabel : showSelectedLabel),
|
|
122
|
-
selectedKeys.size ===
|
|
123
|
-
!!
|
|
124
|
-
React.createElement(List, { bordered: false, dataSource:
|
|
124
|
+
selectedKeys.size === options.length ? (React.createElement(Button, { type: "link", onClick: handleDeselectAll }, deselectAllLabel)) : (React.createElement(Button, { type: "link", onClick: handleSelectAll }, selectAllLabel)))),
|
|
125
|
+
!!filteredOptions.length && (React.createElement(StyledListFieldsWrapper, { autoHeight: true, autoHeightMax: 260 },
|
|
126
|
+
React.createElement(List, { bordered: false, dataSource: filteredOptions, renderItem: option => (React.createElement(List.Item, null,
|
|
125
127
|
React.createElement(Checkbox, { onChange: e => handleToggleField(option, e.target.checked), checked: selectedKeys.has(option.key) }, renderCheckBoxLabel(option)))) }))),
|
|
126
128
|
React.createElement(StyledFooter, null,
|
|
127
129
|
React.createElement(Button, { onClick: handleCancel }, "Cancel"),
|
|
128
130
|
React.createElement(Button, { onClick: handleApply, disabled: applyDisabled, type: "primary" }, "Apply"))), overlayInnerStyle: {
|
|
129
131
|
'--item-padding': `${((_b = (_a = THEME.components) === null || _a === void 0 ? void 0 : _a.Menu) === null || _b === void 0 ? void 0 : _b.itemPaddingInline) || 10}px`,
|
|
130
|
-
}, trigger: ['click'], placement: "bottomLeft", open: open, inputSearchProps: Object.assign(Object.assign({}, restInputSearchProps), { value: search, onAfterChange: handleOnSearch }), afterOpenChange: handleAfterOpenChange, onOpenChange: handleOpenChange }), children ||
|
|
131
|
-
React.createElement(Icon, { type: "icon-ants-plus-slim", size: 14 }),
|
|
132
|
-
"Add fields"))));
|
|
132
|
+
}, trigger: ['click'], placement: "bottomLeft", open: open, inputSearchProps: Object.assign(Object.assign({}, restInputSearchProps), { value: search, onAfterChange: handleOnSearch }), afterOpenChange: handleAfterOpenChange, onOpenChange: handleOpenChange }), children || React.createElement(Button, null, "Select")));
|
|
133
133
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
export declare const StyledFooter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
3
|
export declare const StyledAction: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const StyledListFieldsWrapper: import("styled-components").StyledComponent<
|
|
4
|
+
export declare const StyledListFieldsWrapper: import("styled-components").StyledComponent<import("react").FC<import("@antscorp/antsomi-ui/es/components/atoms").ScrollbarsProps>, any, {}, never>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a, _b;
|
|
2
|
+
import { Scrollbars } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
2
3
|
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
3
|
-
import Scrollbars from 'react-custom-scrollbars';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
export const StyledFooter = styled.div `
|
|
6
6
|
gap: 10px;
|
|
@@ -8,6 +8,7 @@ export const StyledFooter = styled.div `
|
|
|
8
8
|
display: flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
justify-content: flex-end;
|
|
11
|
+
border-top: 1px solid var(--divider-1);
|
|
11
12
|
`;
|
|
12
13
|
export const StyledAction = styled.div `
|
|
13
14
|
display: flex;
|
|
@@ -23,8 +24,6 @@ export const StyledAction = styled.div `
|
|
|
23
24
|
`;
|
|
24
25
|
export const StyledListFieldsWrapper = styled(Scrollbars) `
|
|
25
26
|
.antsomi-list-items {
|
|
26
|
-
border-bottom: 1px solid var(--divider-1);
|
|
27
|
-
|
|
28
27
|
> .antsomi-list-item {
|
|
29
28
|
padding: 0;
|
|
30
29
|
border-bottom: 0;
|
|
@@ -25,7 +25,7 @@ export type PopoverSelectProps<TOption extends Option = Option> = SearchPopoverP
|
|
|
25
25
|
showSelectedLabel: string;
|
|
26
26
|
deselectAllLabel: string;
|
|
27
27
|
selectAllLabel: string;
|
|
28
|
-
onSearchPredicate: (option:
|
|
28
|
+
onSearchPredicate: (option: Option) => boolean;
|
|
29
29
|
}>;
|
|
30
30
|
export type PopoverAddFieldProps = Omit<PopoverSelectProps, 'options'> & {
|
|
31
31
|
fields: Field[];
|
package/es/constants/theme.js
CHANGED
|
@@ -97,6 +97,7 @@ THEME.components = {
|
|
|
97
97
|
borderColorDisabled: (_d = THEME.token) === null || _d === void 0 ? void 0 : _d.bw6,
|
|
98
98
|
colorTextDisabled: (_e = THEME.token) === null || _e === void 0 ? void 0 : _e.bw0,
|
|
99
99
|
textHoverBg: '#F2F9FF',
|
|
100
|
+
controlHeightSM: 24,
|
|
100
101
|
marginXS: 0,
|
|
101
102
|
/* Text type */
|
|
102
103
|
colorBgTextHover: (_f = THEME.token) === null || _f === void 0 ? void 0 : _f.blue,
|
package/es/utils/common.js
CHANGED
|
@@ -536,7 +536,7 @@ export const recursiveSearchItems = ({ list = [], childrenKey = 'children', sear
|
|
|
536
536
|
matchingSubChildren = searchChildren(child[childrenKey], child);
|
|
537
537
|
}
|
|
538
538
|
if (childMatches || matchingSubChildren.length > 0) {
|
|
539
|
-
matchingChildren.push(Object.assign(Object.assign({}, child), { [childrenKey]: matchingSubChildren }));
|
|
539
|
+
matchingChildren.push(Object.assign(Object.assign({}, child), (matchingSubChildren.length > 0 && { [childrenKey]: matchingSubChildren })));
|
|
540
540
|
}
|
|
541
541
|
});
|
|
542
542
|
if (matchingChildren.length > 0) {
|