@canlooks/can-ui 0.0.128 → 0.0.129
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/dist/cjs/components/select/select.d.ts +1 -2
- package/dist/cjs/components/select/select.js +6 -24
- package/dist/cjs/components/selectBase/selectBase.d.ts +3 -5
- package/dist/cjs/components/selectBase/selectBase.js +2 -3
- package/dist/cjs/components/selectionContext/selectionHook.d.ts +3 -2
- package/dist/cjs/components/selectionContext/selectionHook.js +1 -1
- package/dist/cjs/components/tree/tree.d.ts +3 -1
- package/dist/cjs/components/treeSelect/treeSelect.d.ts +3 -11
- package/dist/cjs/components/treeSelect/treeSelect.js +38 -47
- package/dist/cjs/types.d.ts +1 -6
- package/dist/esm/components/select/select.d.ts +1 -2
- package/dist/esm/components/select/select.js +6 -24
- package/dist/esm/components/selectBase/selectBase.d.ts +3 -5
- package/dist/esm/components/selectBase/selectBase.js +2 -3
- package/dist/esm/components/selectionContext/selectionHook.d.ts +3 -2
- package/dist/esm/components/selectionContext/selectionHook.js +1 -1
- package/dist/esm/components/tree/tree.d.ts +3 -1
- package/dist/esm/components/treeSelect/treeSelect.d.ts +3 -11
- package/dist/esm/components/treeSelect/treeSelect.js +38 -47
- package/dist/esm/types.d.ts +1 -6
- package/documentation/dist/assets/{index-Uf9Gh2-g.js → index-DyrGMYuH.js} +131 -131
- package/documentation/dist/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { SelectBaseMultipleProps, SelectBaseOwnProps, SelectBaseSingleProps } from '../selectBase';
|
|
3
3
|
import { MenuOptionType, OptionsBaseSharedProps } from '../optionsBase';
|
|
4
|
-
import { InputBaseProps } from '../inputBase';
|
|
5
4
|
import { Id } from '../../types';
|
|
6
5
|
import { MenuItem } from '../menuItem';
|
|
7
|
-
export interface SelectOwnProps<O extends MenuOptionType> extends SelectBaseOwnProps, OptionsBaseSharedProps<O
|
|
6
|
+
export interface SelectOwnProps<O extends MenuOptionType> extends SelectBaseOwnProps, OptionsBaseSharedProps<O> {
|
|
8
7
|
}
|
|
9
8
|
export interface SelectSingleProps<O extends MenuOptionType, V extends Id = Id> extends SelectOwnProps<O>, SelectBaseSingleProps<V> {
|
|
10
9
|
}
|
|
@@ -7,11 +7,12 @@ const selectBase_1 = require("../selectBase");
|
|
|
7
7
|
const optionsBase_1 = require("../optionsBase");
|
|
8
8
|
const menuItem_1 = require("../menuItem");
|
|
9
9
|
const selectionContext_1 = require("../selectionContext");
|
|
10
|
-
exports.Select = (0, react_1.memo)(({
|
|
10
|
+
exports.Select = (0, react_1.memo)(({ children,
|
|
11
11
|
// 从SelectableProps继承
|
|
12
|
-
multiple = false,
|
|
12
|
+
multiple = false, // 同时转发至<SelectBase/>
|
|
13
|
+
defaultValue, value, onChange, renderBackfill, // 同时转发至<SelectBase/>
|
|
13
14
|
// 从OptionsBaseSharedProps继承
|
|
14
|
-
showCheckbox = multiple, loading = false, options, labelKey = 'label', primaryKey = 'value', searchTokenKey = 'searchToken', filterPredicate, ...
|
|
15
|
+
showCheckbox = multiple, loading = false, options, labelKey = 'label', primaryKey = 'value', searchTokenKey = 'searchToken', filterPredicate, ...props }) => {
|
|
15
16
|
const optionsArr = options || react_1.Children.map(children, c => {
|
|
16
17
|
return (0, react_1.isValidElement)(c) ? c.props : c;
|
|
17
18
|
}) || void 0;
|
|
@@ -24,33 +25,14 @@ showCheckbox = multiple, loading = false, options, labelKey = 'label', primaryKe
|
|
|
24
25
|
}, [optionsArr, primaryKey]);
|
|
25
26
|
const [innerValue, toggleSelected, setInnerValue] = (0, selectionContext_1.useFlatSelection)({ multiple, defaultValue, value, onChange });
|
|
26
27
|
const onClear = () => {
|
|
28
|
+
props.onClear?.();
|
|
27
29
|
setInnerValue(multiple ? [] : void 0);
|
|
28
30
|
};
|
|
29
|
-
return ((0, jsx_runtime_1.jsx)(selectBase_1.SelectBase, { ...{
|
|
30
|
-
inputProps,
|
|
31
|
-
popperProps,
|
|
32
|
-
popperRef,
|
|
33
|
-
defaultOpen,
|
|
34
|
-
open,
|
|
35
|
-
onOpenChange,
|
|
36
|
-
placeholder,
|
|
37
|
-
sizeAdaptable,
|
|
38
|
-
disabled,
|
|
39
|
-
readOnly,
|
|
40
|
-
searchable,
|
|
41
|
-
defaultSearchValue,
|
|
42
|
-
searchValue,
|
|
43
|
-
onSearchChange,
|
|
44
|
-
searchInputProps,
|
|
45
|
-
multiple,
|
|
46
|
-
renderBackfill,
|
|
47
|
-
}, _internalProps: {
|
|
48
|
-
inputBaseProps,
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(selectBase_1.SelectBase, { ...props, multiple: multiple, renderBackfill: renderBackfill, onClear: onClear, _internalProps: {
|
|
49
32
|
labelKey,
|
|
50
33
|
optionsMap,
|
|
51
34
|
innerValue,
|
|
52
35
|
onToggleSelected: toggleSelected,
|
|
53
|
-
onClear,
|
|
54
36
|
renderPopperContent: (searchValue, onToggleSelected) => ((0, jsx_runtime_1.jsx)(optionsBase_1.OptionsBase, { selectedValue: innerValue, searchValue,
|
|
55
37
|
onToggleSelected,
|
|
56
38
|
showCheckbox,
|
|
@@ -3,7 +3,7 @@ import { ComponentProps, ReactNode, Ref } from 'react';
|
|
|
3
3
|
import { PopperProps, PopperRef } from '../popper';
|
|
4
4
|
import { InputProps } from '../input';
|
|
5
5
|
import { Id, SelectableMultipleProps, SelectableSingleProps } from '../../types';
|
|
6
|
-
export
|
|
6
|
+
export interface SelectBaseOwnProps extends Omit<InputBaseProps<'input'>, 'children' | 'placeholder' | 'defaultValue' | 'value' | 'onChange' | 'onToggle'> {
|
|
7
7
|
/** <select />内部由<input />实现 */
|
|
8
8
|
inputProps?: ComponentProps<'input'>;
|
|
9
9
|
popperProps?: PopperProps;
|
|
@@ -21,7 +21,7 @@ export type SelectBaseOwnProps = {
|
|
|
21
21
|
searchValue?: string;
|
|
22
22
|
onSearchChange?(searchValue: string): void;
|
|
23
23
|
searchInputProps?: InputProps;
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
export interface SelectBaseSingleProps<V extends Id = Id> extends SelectBaseOwnProps, SelectableSingleProps<V> {
|
|
26
26
|
renderBackfill?(selectedValue: V | undefined): ReactNode;
|
|
27
27
|
}
|
|
@@ -29,15 +29,13 @@ export interface SelectBaseMultipleProps<V extends Id = Id> extends SelectBaseOw
|
|
|
29
29
|
renderBackfill?(selectedValue: V[] | undefined): ReactNode;
|
|
30
30
|
}
|
|
31
31
|
export type SelectBaseProps<V extends Id = Id> = SelectBaseSingleProps<V> | SelectBaseMultipleProps<V>;
|
|
32
|
-
export declare function SelectBase({ inputProps, popperProps, popperRef, defaultOpen, open, onOpenChange, placeholder, sizeAdaptable, disabled, readOnly, loading, searchable, defaultSearchValue, searchValue, onSearchChange, searchInputProps, multiple, renderBackfill, _internalProps: {
|
|
32
|
+
export declare function SelectBase({ inputProps, popperProps, popperRef, defaultOpen, open, onOpenChange, placeholder, sizeAdaptable, disabled, readOnly, loading, searchable, defaultSearchValue, searchValue, onSearchChange, searchInputProps, multiple, renderBackfill, _internalProps: { labelKey, optionsMap, innerValue, onToggleSelected, renderPopperContent }, ...props }: Omit<SelectBaseProps, 'defaultValue' | 'value' | 'onChange'> & {
|
|
33
33
|
/** @private 内部使用的属性 */
|
|
34
34
|
_internalProps: {
|
|
35
|
-
inputBaseProps?: Omit<InputBaseProps<'input'>, 'children'>;
|
|
36
35
|
labelKey: keyof any;
|
|
37
36
|
optionsMap: Map<Id, any>;
|
|
38
37
|
innerValue: (Id & Id[]) | undefined;
|
|
39
38
|
onToggleSelected(value: Id): void;
|
|
40
|
-
onClear: (() => void) | undefined;
|
|
41
39
|
renderPopperContent(searchValue: string, toggleSelected: (value: Id) => void): ReactNode;
|
|
42
40
|
};
|
|
43
41
|
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -16,7 +16,7 @@ const loadingIndicator_1 = require("../loadingIndicator");
|
|
|
16
16
|
const faChevronDown_1 = require("@fortawesome/free-solid-svg-icons/faChevronDown");
|
|
17
17
|
function SelectBase({ inputProps, popperProps, popperRef, defaultOpen = false, open, onOpenChange, placeholder = '请选择', sizeAdaptable = true, disabled, readOnly, loading = false, searchable, defaultSearchValue = '', searchValue, onSearchChange, searchInputProps,
|
|
18
18
|
// 从SelectableProps继承
|
|
19
|
-
multiple = false, renderBackfill, _internalProps: {
|
|
19
|
+
multiple = false, renderBackfill, _internalProps: { labelKey, optionsMap, innerValue, onToggleSelected, renderPopperContent }, ...props }) {
|
|
20
20
|
const [innerOpen, _setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open, onOpenChange);
|
|
21
21
|
const setInnerOpen = (open) => {
|
|
22
22
|
_setInnerOpen(open);
|
|
@@ -86,13 +86,12 @@ multiple = false, renderBackfill, _internalProps: { inputBaseProps, labelKey, op
|
|
|
86
86
|
onOpenChange: openChangeHandler,
|
|
87
87
|
onOpenChangeEnd: openChangeEnd,
|
|
88
88
|
onPointerDown: e => e.preventDefault()
|
|
89
|
-
}), children: (0, jsx_runtime_1.jsx)(inputBase_1.InputBase, { clearable: multiple, ...(0, utils_1.mergeComponentProps)(
|
|
89
|
+
}), children: (0, jsx_runtime_1.jsx)(inputBase_1.InputBase, { clearable: multiple, ...(0, utils_1.mergeComponentProps)(props, {
|
|
90
90
|
css: selectBase_style_1.style,
|
|
91
91
|
className: selectBase_style_1.classes.root,
|
|
92
92
|
disabled,
|
|
93
93
|
readOnly,
|
|
94
94
|
value: innerValue,
|
|
95
|
-
onClear,
|
|
96
95
|
onBlur
|
|
97
96
|
}), "data-focused": innerOpen.current, children: inputBaseProps => (0, jsx_runtime_1.jsxs)("div", { className: selectBase_style_1.classes.contentWrap, children: [(0, utils_1.isNoValue)(innerValue)
|
|
98
97
|
? (0, jsx_runtime_1.jsx)("div", { className: selectBase_style_1.classes.placeholder, children: placeholder })
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
2
|
import { ISelectionContext, OptionType, SelectionContextProps } from './selectionContext';
|
|
3
3
|
import { Id, SelectableProps } from '../../types';
|
|
4
|
-
export declare function useSelection<O extends OptionType<V>, V extends Id = Id>(props: SelectionContextProps<O, V>): ISelectionContext<O, V>;
|
|
5
|
-
export type UseFlatSelectionParams<V extends Id = Id> = SelectableProps<V> & {
|
|
4
|
+
export declare function useSelection<O extends OptionType<V>, V extends Id = Id>({ ...props }: SelectionContextProps<O, V>): ISelectionContext<O, V>;
|
|
5
|
+
export type UseFlatSelectionParams<V extends Id = Id> = Omit<SelectableProps<V>, 'multiple'> & {
|
|
6
|
+
multiple?: boolean;
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
clearable?: boolean;
|
|
8
9
|
};
|
|
@@ -5,7 +5,7 @@ exports.useFlatSelection = useFlatSelection;
|
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const selectionContext_1 = require("./selectionContext");
|
|
8
|
-
function useSelection(props) {
|
|
8
|
+
function useSelection({ ...props }) {
|
|
9
9
|
props.primaryKey ??= 'id';
|
|
10
10
|
props.childrenKey ??= 'children';
|
|
11
11
|
props.relation ??= 'dependent';
|
|
@@ -12,7 +12,7 @@ export type SortInfo<V extends Id = Id> = {
|
|
|
12
12
|
destination: V;
|
|
13
13
|
placement: SortPlacement;
|
|
14
14
|
};
|
|
15
|
-
export interface
|
|
15
|
+
export interface TreeSharedProps<N extends NodeType<V>, V extends Id = Id> extends Omit<SelectionContextBaseProps<N, V>, 'options'> {
|
|
16
16
|
nodes?: N[];
|
|
17
17
|
/** 默认为`label` */
|
|
18
18
|
labelKey?: keyof N;
|
|
@@ -33,6 +33,8 @@ export interface TreeBaseProps<N extends NodeType<V>, V extends Id = Id> extends
|
|
|
33
33
|
/** 是否显示拖拽把手,默认为`true` */
|
|
34
34
|
showDragHandle?: boolean;
|
|
35
35
|
onSort?(info: SortInfo<V>): void;
|
|
36
|
+
}
|
|
37
|
+
export interface TreeBaseProps<N extends NodeType<V>, V extends Id = Id> extends TreeSharedProps<N, V>, Omit<DivProps, 'defaultValue' | 'onChange' | 'onToggle'> {
|
|
36
38
|
searchable?: boolean;
|
|
37
39
|
searchInputProps?: InputProps;
|
|
38
40
|
defaultSearchValue?: string;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { NodeType,
|
|
2
|
+
import { NodeType, TreeNode, TreeProps, TreeSharedProps } from '../tree';
|
|
3
3
|
import { Id } from '../../types';
|
|
4
4
|
import { SelectBaseMultipleProps, SelectBaseOwnProps, SelectBaseSingleProps } from '../selectBase';
|
|
5
|
-
|
|
6
|
-
export interface TreeSelectOwnProps<N extends NodeType<V>, V extends Id = Id> extends SelectBaseOwnProps, Omit<TreeBaseProps<N, V>, 'prefix'> {
|
|
5
|
+
export interface TreeSelectOwnProps<N extends NodeType<V>, V extends Id = Id> extends SelectBaseOwnProps, TreeSharedProps<N, V> {
|
|
7
6
|
options?: N[];
|
|
8
|
-
|
|
9
|
-
variant?: InputBaseProps<'input'>['variant'];
|
|
10
|
-
size?: InputBaseProps<'input'>['size'];
|
|
11
|
-
shape?: InputBaseProps<'input'>['shape'];
|
|
12
|
-
color?: InputBaseProps<'input'>['color'];
|
|
13
|
-
prefix?: InputBaseProps<'input'>['prefix'];
|
|
14
|
-
suffix?: InputBaseProps<'input'>['suffix'];
|
|
15
|
-
onClear?: InputBaseProps<'input'>['onClear'];
|
|
7
|
+
treeProps?: TreeProps<N, V>;
|
|
16
8
|
}
|
|
17
9
|
export interface TreeSelectSingleProps<N extends NodeType<V>, V extends Id = Id> extends TreeSelectOwnProps<N, V>, SelectBaseSingleProps<V> {
|
|
18
10
|
}
|
|
@@ -7,14 +7,16 @@ const tree_1 = require("../tree");
|
|
|
7
7
|
const selectBase_1 = require("../selectBase");
|
|
8
8
|
const selectionContext_1 = require("../selectionContext");
|
|
9
9
|
const placeholder_1 = require("../placeholder");
|
|
10
|
-
exports.TreeSelect = (0, react_1.memo)(({
|
|
10
|
+
exports.TreeSelect = (0, react_1.memo)(({ options, children, treeProps,
|
|
11
|
+
// 从TreeSharedProps继承
|
|
12
|
+
nodes, labelKey = 'label', searchTokenKey, showLine, indent, renderExpandIcon, showCheckbox, readOnly, // 同时转发至<InputBase/>, <SelectBase/>
|
|
13
|
+
clickLabelToExpand, defaultExpanded, expanded, onExpandedChange, sortable, showDragHandle, onSort, primaryKey = 'value', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', clearable, // 同时转发至<InputBase/>, <SelectBase/>
|
|
14
|
+
disabled, // 同时转发至<InputBase/>, <SelectBase/>
|
|
15
|
+
onToggle,
|
|
11
16
|
// 从SelectableProps继承
|
|
12
|
-
multiple = false,
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
treeProps.labelKey ??= 'label';
|
|
16
|
-
treeProps.primaryKey ??= 'value';
|
|
17
|
-
treeProps.childrenKey ??= 'children';
|
|
17
|
+
multiple = false, // 同时转发至<Tree/>, <SelectBase/>
|
|
18
|
+
defaultValue, // 同时转发至<Tree/>
|
|
19
|
+
value, onChange, renderBackfill, ...props }) => {
|
|
18
20
|
const actualOptions = (0, react_1.useMemo)(() => {
|
|
19
21
|
if (options) {
|
|
20
22
|
return options;
|
|
@@ -38,58 +40,47 @@ inputBaseProps, variant = 'outlined', size = 'medium', shape = 'square', color =
|
|
|
38
40
|
}, [options, nodes, children]);
|
|
39
41
|
const { value: innerValue, setValue: setInnerValue, toggleSelected, optionsMap } = (0, selectionContext_1.useSelection)({
|
|
40
42
|
options: actualOptions,
|
|
41
|
-
primaryKey
|
|
42
|
-
childrenKey
|
|
43
|
+
primaryKey,
|
|
44
|
+
childrenKey,
|
|
43
45
|
clearable: multiple,
|
|
44
|
-
multiple,
|
|
46
|
+
multiple: multiple,
|
|
45
47
|
defaultValue,
|
|
46
48
|
value,
|
|
47
49
|
onChange
|
|
48
50
|
});
|
|
49
|
-
const
|
|
50
|
-
onClear?.();
|
|
51
|
+
const onClear = () => {
|
|
52
|
+
props.onClear?.();
|
|
51
53
|
setInnerValue(multiple ? [] : void 0);
|
|
52
54
|
};
|
|
53
|
-
return ((0, jsx_runtime_1.jsx)(selectBase_1.SelectBase, { ...{
|
|
54
|
-
|
|
55
|
-
popperProps,
|
|
56
|
-
popperRef,
|
|
57
|
-
defaultOpen,
|
|
58
|
-
open,
|
|
59
|
-
onOpenChange,
|
|
60
|
-
placeholder,
|
|
61
|
-
sizeAdaptable,
|
|
62
|
-
disabled,
|
|
63
|
-
readOnly,
|
|
64
|
-
searchable,
|
|
65
|
-
defaultSearchValue,
|
|
66
|
-
searchValue,
|
|
67
|
-
onSearchChange,
|
|
68
|
-
searchInputProps,
|
|
69
|
-
multiple,
|
|
70
|
-
renderBackfill
|
|
71
|
-
}, _internalProps: {
|
|
72
|
-
inputBaseProps: {
|
|
73
|
-
...inputBaseProps,
|
|
74
|
-
variant,
|
|
75
|
-
size,
|
|
76
|
-
shape,
|
|
77
|
-
color,
|
|
78
|
-
prefix,
|
|
79
|
-
suffix,
|
|
80
|
-
disabled,
|
|
81
|
-
readOnly,
|
|
82
|
-
autoFocus,
|
|
83
|
-
clearable,
|
|
84
|
-
},
|
|
85
|
-
labelKey: treeProps.labelKey,
|
|
55
|
+
return ((0, jsx_runtime_1.jsx)(selectBase_1.SelectBase, { ...props, readOnly: readOnly, clearable: clearable, disabled: disabled, multiple: multiple, renderBackfill: renderBackfill, onClear: onClear, _internalProps: {
|
|
56
|
+
labelKey,
|
|
86
57
|
optionsMap,
|
|
87
58
|
innerValue,
|
|
88
59
|
onToggleSelected: toggleSelected,
|
|
89
|
-
onClear: clearHandler,
|
|
90
60
|
renderPopperContent: (searchValue, toggleSelected) => {
|
|
91
61
|
return actualOptions?.length
|
|
92
|
-
? (0, jsx_runtime_1.jsx)(tree_1.Tree, { ...treeProps, nodes
|
|
62
|
+
? (0, jsx_runtime_1.jsx)(tree_1.Tree, { ...treeProps, nodes,
|
|
63
|
+
labelKey,
|
|
64
|
+
searchTokenKey,
|
|
65
|
+
showLine,
|
|
66
|
+
indent,
|
|
67
|
+
renderExpandIcon,
|
|
68
|
+
showCheckbox,
|
|
69
|
+
readOnly,
|
|
70
|
+
clickLabelToExpand,
|
|
71
|
+
defaultExpanded,
|
|
72
|
+
expanded,
|
|
73
|
+
onExpandedChange,
|
|
74
|
+
sortable,
|
|
75
|
+
showDragHandle,
|
|
76
|
+
onSort,
|
|
77
|
+
primaryKey,
|
|
78
|
+
childrenKey,
|
|
79
|
+
relation,
|
|
80
|
+
integration,
|
|
81
|
+
clearable,
|
|
82
|
+
disabled,
|
|
83
|
+
onToggle, multiple: multiple, nodes: actualOptions, searchable: false, searchValue: searchValue, value: innerValue, onToggle: (checked, value) => toggleSelected(value) })
|
|
93
84
|
: (0, jsx_runtime_1.jsx)(placeholder_1.Placeholder, {});
|
|
94
85
|
}
|
|
95
86
|
} }));
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -65,9 +65,4 @@ export type SelectableMultipleProps<T> = {
|
|
|
65
65
|
value?: T[];
|
|
66
66
|
onChange?(value: T[]): void;
|
|
67
67
|
};
|
|
68
|
-
export type SelectableProps<T> =
|
|
69
|
-
multiple?: boolean;
|
|
70
|
-
defaultValue?: T | T[];
|
|
71
|
-
value?: T | T[];
|
|
72
|
-
onChange?(value: T | T[]): void;
|
|
73
|
-
};
|
|
68
|
+
export type SelectableProps<T> = SelectableSingleProps<T> | SelectableMultipleProps<T>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { SelectBaseMultipleProps, SelectBaseOwnProps, SelectBaseSingleProps } from '../selectBase';
|
|
3
3
|
import { MenuOptionType, OptionsBaseSharedProps } from '../optionsBase';
|
|
4
|
-
import { InputBaseProps } from '../inputBase';
|
|
5
4
|
import { Id } from '../../types';
|
|
6
5
|
import { MenuItem } from '../menuItem';
|
|
7
|
-
export interface SelectOwnProps<O extends MenuOptionType> extends SelectBaseOwnProps, OptionsBaseSharedProps<O
|
|
6
|
+
export interface SelectOwnProps<O extends MenuOptionType> extends SelectBaseOwnProps, OptionsBaseSharedProps<O> {
|
|
8
7
|
}
|
|
9
8
|
export interface SelectSingleProps<O extends MenuOptionType, V extends Id = Id> extends SelectOwnProps<O>, SelectBaseSingleProps<V> {
|
|
10
9
|
}
|
|
@@ -4,11 +4,12 @@ import { SelectBase } from '../selectBase';
|
|
|
4
4
|
import { OptionsBase } from '../optionsBase';
|
|
5
5
|
import { MenuItem } from '../menuItem';
|
|
6
6
|
import { useFlatSelection } from '../selectionContext';
|
|
7
|
-
export const Select = memo(({
|
|
7
|
+
export const Select = memo(({ children,
|
|
8
8
|
// 从SelectableProps继承
|
|
9
|
-
multiple = false,
|
|
9
|
+
multiple = false, // 同时转发至<SelectBase/>
|
|
10
|
+
defaultValue, value, onChange, renderBackfill, // 同时转发至<SelectBase/>
|
|
10
11
|
// 从OptionsBaseSharedProps继承
|
|
11
|
-
showCheckbox = multiple, loading = false, options, labelKey = 'label', primaryKey = 'value', searchTokenKey = 'searchToken', filterPredicate, ...
|
|
12
|
+
showCheckbox = multiple, loading = false, options, labelKey = 'label', primaryKey = 'value', searchTokenKey = 'searchToken', filterPredicate, ...props }) => {
|
|
12
13
|
const optionsArr = options || Children.map(children, c => {
|
|
13
14
|
return isValidElement(c) ? c.props : c;
|
|
14
15
|
}) || void 0;
|
|
@@ -21,33 +22,14 @@ showCheckbox = multiple, loading = false, options, labelKey = 'label', primaryKe
|
|
|
21
22
|
}, [optionsArr, primaryKey]);
|
|
22
23
|
const [innerValue, toggleSelected, setInnerValue] = useFlatSelection({ multiple, defaultValue, value, onChange });
|
|
23
24
|
const onClear = () => {
|
|
25
|
+
props.onClear?.();
|
|
24
26
|
setInnerValue(multiple ? [] : void 0);
|
|
25
27
|
};
|
|
26
|
-
return (_jsx(SelectBase, { ...{
|
|
27
|
-
inputProps,
|
|
28
|
-
popperProps,
|
|
29
|
-
popperRef,
|
|
30
|
-
defaultOpen,
|
|
31
|
-
open,
|
|
32
|
-
onOpenChange,
|
|
33
|
-
placeholder,
|
|
34
|
-
sizeAdaptable,
|
|
35
|
-
disabled,
|
|
36
|
-
readOnly,
|
|
37
|
-
searchable,
|
|
38
|
-
defaultSearchValue,
|
|
39
|
-
searchValue,
|
|
40
|
-
onSearchChange,
|
|
41
|
-
searchInputProps,
|
|
42
|
-
multiple,
|
|
43
|
-
renderBackfill,
|
|
44
|
-
}, _internalProps: {
|
|
45
|
-
inputBaseProps,
|
|
28
|
+
return (_jsx(SelectBase, { ...props, multiple: multiple, renderBackfill: renderBackfill, onClear: onClear, _internalProps: {
|
|
46
29
|
labelKey,
|
|
47
30
|
optionsMap,
|
|
48
31
|
innerValue,
|
|
49
32
|
onToggleSelected: toggleSelected,
|
|
50
|
-
onClear,
|
|
51
33
|
renderPopperContent: (searchValue, onToggleSelected) => (_jsx(OptionsBase, { selectedValue: innerValue, searchValue,
|
|
52
34
|
onToggleSelected,
|
|
53
35
|
showCheckbox,
|
|
@@ -3,7 +3,7 @@ import { ComponentProps, ReactNode, Ref } from 'react';
|
|
|
3
3
|
import { PopperProps, PopperRef } from '../popper';
|
|
4
4
|
import { InputProps } from '../input';
|
|
5
5
|
import { Id, SelectableMultipleProps, SelectableSingleProps } from '../../types';
|
|
6
|
-
export
|
|
6
|
+
export interface SelectBaseOwnProps extends Omit<InputBaseProps<'input'>, 'children' | 'placeholder' | 'defaultValue' | 'value' | 'onChange' | 'onToggle'> {
|
|
7
7
|
/** <select />内部由<input />实现 */
|
|
8
8
|
inputProps?: ComponentProps<'input'>;
|
|
9
9
|
popperProps?: PopperProps;
|
|
@@ -21,7 +21,7 @@ export type SelectBaseOwnProps = {
|
|
|
21
21
|
searchValue?: string;
|
|
22
22
|
onSearchChange?(searchValue: string): void;
|
|
23
23
|
searchInputProps?: InputProps;
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
export interface SelectBaseSingleProps<V extends Id = Id> extends SelectBaseOwnProps, SelectableSingleProps<V> {
|
|
26
26
|
renderBackfill?(selectedValue: V | undefined): ReactNode;
|
|
27
27
|
}
|
|
@@ -29,15 +29,13 @@ export interface SelectBaseMultipleProps<V extends Id = Id> extends SelectBaseOw
|
|
|
29
29
|
renderBackfill?(selectedValue: V[] | undefined): ReactNode;
|
|
30
30
|
}
|
|
31
31
|
export type SelectBaseProps<V extends Id = Id> = SelectBaseSingleProps<V> | SelectBaseMultipleProps<V>;
|
|
32
|
-
export declare function SelectBase({ inputProps, popperProps, popperRef, defaultOpen, open, onOpenChange, placeholder, sizeAdaptable, disabled, readOnly, loading, searchable, defaultSearchValue, searchValue, onSearchChange, searchInputProps, multiple, renderBackfill, _internalProps: {
|
|
32
|
+
export declare function SelectBase({ inputProps, popperProps, popperRef, defaultOpen, open, onOpenChange, placeholder, sizeAdaptable, disabled, readOnly, loading, searchable, defaultSearchValue, searchValue, onSearchChange, searchInputProps, multiple, renderBackfill, _internalProps: { labelKey, optionsMap, innerValue, onToggleSelected, renderPopperContent }, ...props }: Omit<SelectBaseProps, 'defaultValue' | 'value' | 'onChange'> & {
|
|
33
33
|
/** @private 内部使用的属性 */
|
|
34
34
|
_internalProps: {
|
|
35
|
-
inputBaseProps?: Omit<InputBaseProps<'input'>, 'children'>;
|
|
36
35
|
labelKey: keyof any;
|
|
37
36
|
optionsMap: Map<Id, any>;
|
|
38
37
|
innerValue: (Id & Id[]) | undefined;
|
|
39
38
|
onToggleSelected(value: Id): void;
|
|
40
|
-
onClear: (() => void) | undefined;
|
|
41
39
|
renderPopperContent(searchValue: string, toggleSelected: (value: Id) => void): ReactNode;
|
|
42
40
|
};
|
|
43
41
|
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -13,7 +13,7 @@ import { LoadingIndicator } from '../loadingIndicator';
|
|
|
13
13
|
import { faChevronDown } from '@fortawesome/free-solid-svg-icons/faChevronDown';
|
|
14
14
|
export function SelectBase({ inputProps, popperProps, popperRef, defaultOpen = false, open, onOpenChange, placeholder = '请选择', sizeAdaptable = true, disabled, readOnly, loading = false, searchable, defaultSearchValue = '', searchValue, onSearchChange, searchInputProps,
|
|
15
15
|
// 从SelectableProps继承
|
|
16
|
-
multiple = false, renderBackfill, _internalProps: {
|
|
16
|
+
multiple = false, renderBackfill, _internalProps: { labelKey, optionsMap, innerValue, onToggleSelected, renderPopperContent }, ...props }) {
|
|
17
17
|
const [innerOpen, _setInnerOpen] = useControlled(defaultOpen, open, onOpenChange);
|
|
18
18
|
const setInnerOpen = (open) => {
|
|
19
19
|
_setInnerOpen(open);
|
|
@@ -83,13 +83,12 @@ multiple = false, renderBackfill, _internalProps: { inputBaseProps, labelKey, op
|
|
|
83
83
|
onOpenChange: openChangeHandler,
|
|
84
84
|
onOpenChangeEnd: openChangeEnd,
|
|
85
85
|
onPointerDown: e => e.preventDefault()
|
|
86
|
-
}), children: _jsx(InputBase, { clearable: multiple, ...mergeComponentProps(
|
|
86
|
+
}), children: _jsx(InputBase, { clearable: multiple, ...mergeComponentProps(props, {
|
|
87
87
|
css: style,
|
|
88
88
|
className: classes.root,
|
|
89
89
|
disabled,
|
|
90
90
|
readOnly,
|
|
91
91
|
value: innerValue,
|
|
92
|
-
onClear,
|
|
93
92
|
onBlur
|
|
94
93
|
}), "data-focused": innerOpen.current, children: inputBaseProps => _jsxs("div", { className: classes.contentWrap, children: [isNoValue(innerValue)
|
|
95
94
|
? _jsx("div", { className: classes.placeholder, children: placeholder })
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
2
|
import { ISelectionContext, OptionType, SelectionContextProps } from './selectionContext';
|
|
3
3
|
import { Id, SelectableProps } from '../../types';
|
|
4
|
-
export declare function useSelection<O extends OptionType<V>, V extends Id = Id>(props: SelectionContextProps<O, V>): ISelectionContext<O, V>;
|
|
5
|
-
export type UseFlatSelectionParams<V extends Id = Id> = SelectableProps<V> & {
|
|
4
|
+
export declare function useSelection<O extends OptionType<V>, V extends Id = Id>({ ...props }: SelectionContextProps<O, V>): ISelectionContext<O, V>;
|
|
5
|
+
export type UseFlatSelectionParams<V extends Id = Id> = Omit<SelectableProps<V>, 'multiple'> & {
|
|
6
|
+
multiple?: boolean;
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
clearable?: boolean;
|
|
8
9
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isSelected, isUnset, toArray, useControlled, useDerivedState, useSync } from '../../utils';
|
|
2
2
|
import { useCallback, useMemo, useRef } from 'react';
|
|
3
3
|
import { useSelectionContext } from './selectionContext';
|
|
4
|
-
export function useSelection(props) {
|
|
4
|
+
export function useSelection({ ...props }) {
|
|
5
5
|
props.primaryKey ??= 'id';
|
|
6
6
|
props.childrenKey ??= 'children';
|
|
7
7
|
props.relation ??= 'dependent';
|
|
@@ -12,7 +12,7 @@ export type SortInfo<V extends Id = Id> = {
|
|
|
12
12
|
destination: V;
|
|
13
13
|
placement: SortPlacement;
|
|
14
14
|
};
|
|
15
|
-
export interface
|
|
15
|
+
export interface TreeSharedProps<N extends NodeType<V>, V extends Id = Id> extends Omit<SelectionContextBaseProps<N, V>, 'options'> {
|
|
16
16
|
nodes?: N[];
|
|
17
17
|
/** 默认为`label` */
|
|
18
18
|
labelKey?: keyof N;
|
|
@@ -33,6 +33,8 @@ export interface TreeBaseProps<N extends NodeType<V>, V extends Id = Id> extends
|
|
|
33
33
|
/** 是否显示拖拽把手,默认为`true` */
|
|
34
34
|
showDragHandle?: boolean;
|
|
35
35
|
onSort?(info: SortInfo<V>): void;
|
|
36
|
+
}
|
|
37
|
+
export interface TreeBaseProps<N extends NodeType<V>, V extends Id = Id> extends TreeSharedProps<N, V>, Omit<DivProps, 'defaultValue' | 'onChange' | 'onToggle'> {
|
|
36
38
|
searchable?: boolean;
|
|
37
39
|
searchInputProps?: InputProps;
|
|
38
40
|
defaultSearchValue?: string;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { NodeType,
|
|
2
|
+
import { NodeType, TreeNode, TreeProps, TreeSharedProps } from '../tree';
|
|
3
3
|
import { Id } from '../../types';
|
|
4
4
|
import { SelectBaseMultipleProps, SelectBaseOwnProps, SelectBaseSingleProps } from '../selectBase';
|
|
5
|
-
|
|
6
|
-
export interface TreeSelectOwnProps<N extends NodeType<V>, V extends Id = Id> extends SelectBaseOwnProps, Omit<TreeBaseProps<N, V>, 'prefix'> {
|
|
5
|
+
export interface TreeSelectOwnProps<N extends NodeType<V>, V extends Id = Id> extends SelectBaseOwnProps, TreeSharedProps<N, V> {
|
|
7
6
|
options?: N[];
|
|
8
|
-
|
|
9
|
-
variant?: InputBaseProps<'input'>['variant'];
|
|
10
|
-
size?: InputBaseProps<'input'>['size'];
|
|
11
|
-
shape?: InputBaseProps<'input'>['shape'];
|
|
12
|
-
color?: InputBaseProps<'input'>['color'];
|
|
13
|
-
prefix?: InputBaseProps<'input'>['prefix'];
|
|
14
|
-
suffix?: InputBaseProps<'input'>['suffix'];
|
|
15
|
-
onClear?: InputBaseProps<'input'>['onClear'];
|
|
7
|
+
treeProps?: TreeProps<N, V>;
|
|
16
8
|
}
|
|
17
9
|
export interface TreeSelectSingleProps<N extends NodeType<V>, V extends Id = Id> extends TreeSelectOwnProps<N, V>, SelectBaseSingleProps<V> {
|
|
18
10
|
}
|
|
@@ -4,14 +4,16 @@ import { Tree, TreeNode } from '../tree';
|
|
|
4
4
|
import { SelectBase } from '../selectBase';
|
|
5
5
|
import { useSelection } from '../selectionContext';
|
|
6
6
|
import { Placeholder } from '../placeholder';
|
|
7
|
-
export const TreeSelect = memo(({
|
|
7
|
+
export const TreeSelect = memo(({ options, children, treeProps,
|
|
8
|
+
// 从TreeSharedProps继承
|
|
9
|
+
nodes, labelKey = 'label', searchTokenKey, showLine, indent, renderExpandIcon, showCheckbox, readOnly, // 同时转发至<InputBase/>, <SelectBase/>
|
|
10
|
+
clickLabelToExpand, defaultExpanded, expanded, onExpandedChange, sortable, showDragHandle, onSort, primaryKey = 'value', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', clearable, // 同时转发至<InputBase/>, <SelectBase/>
|
|
11
|
+
disabled, // 同时转发至<InputBase/>, <SelectBase/>
|
|
12
|
+
onToggle,
|
|
8
13
|
// 从SelectableProps继承
|
|
9
|
-
multiple = false,
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
treeProps.labelKey ??= 'label';
|
|
13
|
-
treeProps.primaryKey ??= 'value';
|
|
14
|
-
treeProps.childrenKey ??= 'children';
|
|
14
|
+
multiple = false, // 同时转发至<Tree/>, <SelectBase/>
|
|
15
|
+
defaultValue, // 同时转发至<Tree/>
|
|
16
|
+
value, onChange, renderBackfill, ...props }) => {
|
|
15
17
|
const actualOptions = useMemo(() => {
|
|
16
18
|
if (options) {
|
|
17
19
|
return options;
|
|
@@ -35,58 +37,47 @@ inputBaseProps, variant = 'outlined', size = 'medium', shape = 'square', color =
|
|
|
35
37
|
}, [options, nodes, children]);
|
|
36
38
|
const { value: innerValue, setValue: setInnerValue, toggleSelected, optionsMap } = useSelection({
|
|
37
39
|
options: actualOptions,
|
|
38
|
-
primaryKey
|
|
39
|
-
childrenKey
|
|
40
|
+
primaryKey,
|
|
41
|
+
childrenKey,
|
|
40
42
|
clearable: multiple,
|
|
41
|
-
multiple,
|
|
43
|
+
multiple: multiple,
|
|
42
44
|
defaultValue,
|
|
43
45
|
value,
|
|
44
46
|
onChange
|
|
45
47
|
});
|
|
46
|
-
const
|
|
47
|
-
onClear?.();
|
|
48
|
+
const onClear = () => {
|
|
49
|
+
props.onClear?.();
|
|
48
50
|
setInnerValue(multiple ? [] : void 0);
|
|
49
51
|
};
|
|
50
|
-
return (_jsx(SelectBase, { ...{
|
|
51
|
-
|
|
52
|
-
popperProps,
|
|
53
|
-
popperRef,
|
|
54
|
-
defaultOpen,
|
|
55
|
-
open,
|
|
56
|
-
onOpenChange,
|
|
57
|
-
placeholder,
|
|
58
|
-
sizeAdaptable,
|
|
59
|
-
disabled,
|
|
60
|
-
readOnly,
|
|
61
|
-
searchable,
|
|
62
|
-
defaultSearchValue,
|
|
63
|
-
searchValue,
|
|
64
|
-
onSearchChange,
|
|
65
|
-
searchInputProps,
|
|
66
|
-
multiple,
|
|
67
|
-
renderBackfill
|
|
68
|
-
}, _internalProps: {
|
|
69
|
-
inputBaseProps: {
|
|
70
|
-
...inputBaseProps,
|
|
71
|
-
variant,
|
|
72
|
-
size,
|
|
73
|
-
shape,
|
|
74
|
-
color,
|
|
75
|
-
prefix,
|
|
76
|
-
suffix,
|
|
77
|
-
disabled,
|
|
78
|
-
readOnly,
|
|
79
|
-
autoFocus,
|
|
80
|
-
clearable,
|
|
81
|
-
},
|
|
82
|
-
labelKey: treeProps.labelKey,
|
|
52
|
+
return (_jsx(SelectBase, { ...props, readOnly: readOnly, clearable: clearable, disabled: disabled, multiple: multiple, renderBackfill: renderBackfill, onClear: onClear, _internalProps: {
|
|
53
|
+
labelKey,
|
|
83
54
|
optionsMap,
|
|
84
55
|
innerValue,
|
|
85
56
|
onToggleSelected: toggleSelected,
|
|
86
|
-
onClear: clearHandler,
|
|
87
57
|
renderPopperContent: (searchValue, toggleSelected) => {
|
|
88
58
|
return actualOptions?.length
|
|
89
|
-
? _jsx(Tree, { ...treeProps, nodes
|
|
59
|
+
? _jsx(Tree, { ...treeProps, nodes,
|
|
60
|
+
labelKey,
|
|
61
|
+
searchTokenKey,
|
|
62
|
+
showLine,
|
|
63
|
+
indent,
|
|
64
|
+
renderExpandIcon,
|
|
65
|
+
showCheckbox,
|
|
66
|
+
readOnly,
|
|
67
|
+
clickLabelToExpand,
|
|
68
|
+
defaultExpanded,
|
|
69
|
+
expanded,
|
|
70
|
+
onExpandedChange,
|
|
71
|
+
sortable,
|
|
72
|
+
showDragHandle,
|
|
73
|
+
onSort,
|
|
74
|
+
primaryKey,
|
|
75
|
+
childrenKey,
|
|
76
|
+
relation,
|
|
77
|
+
integration,
|
|
78
|
+
clearable,
|
|
79
|
+
disabled,
|
|
80
|
+
onToggle, multiple: multiple, nodes: actualOptions, searchable: false, searchValue: searchValue, value: innerValue, onToggle: (checked, value) => toggleSelected(value) })
|
|
90
81
|
: _jsx(Placeholder, {});
|
|
91
82
|
}
|
|
92
83
|
} }));
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -65,9 +65,4 @@ export type SelectableMultipleProps<T> = {
|
|
|
65
65
|
value?: T[];
|
|
66
66
|
onChange?(value: T[]): void;
|
|
67
67
|
};
|
|
68
|
-
export type SelectableProps<T> =
|
|
69
|
-
multiple?: boolean;
|
|
70
|
-
defaultValue?: T | T[];
|
|
71
|
-
value?: T | T[];
|
|
72
|
-
onChange?(value: T | T[]): void;
|
|
73
|
-
};
|
|
68
|
+
export type SelectableProps<T> = SelectableSingleProps<T> | SelectableMultipleProps<T>;
|