@canlooks/can-ui 0.0.201 → 0.0.203
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/dataGrid/dataGrid.d.ts +2 -1
- package/dist/cjs/components/dataGrid/dataGrid.js +2 -2
- package/dist/cjs/components/pickerDialog/pickerDialog.d.ts +5 -7
- package/dist/cjs/components/pickerDialog/pickerDialog.js +14 -21
- package/dist/cjs/components/selectedList/selectedList.style.js +4 -0
- package/dist/esm/components/dataGrid/dataGrid.d.ts +2 -1
- package/dist/esm/components/dataGrid/dataGrid.js +2 -2
- package/dist/esm/components/pickerDialog/pickerDialog.d.ts +5 -7
- package/dist/esm/components/pickerDialog/pickerDialog.js +15 -22
- package/dist/esm/components/selectedList/selectedList.style.js +4 -0
- package/package.json +1 -1
|
@@ -72,7 +72,7 @@ interface DataGridSharedProps<R extends RowType = RowType> extends SlotsAndProps
|
|
|
72
72
|
renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode;
|
|
73
73
|
}
|
|
74
74
|
export type OrderType = 'ascend' | 'descend';
|
|
75
|
-
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onChange'> {
|
|
75
|
+
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onToggle' | 'onChange'> {
|
|
76
76
|
columns?: (ColumnType<R> | symbol)[];
|
|
77
77
|
rows?: R[];
|
|
78
78
|
filterProps?: FormProps;
|
|
@@ -99,6 +99,7 @@ export interface DataGridBaseProps<R extends RowType = RowType> extends DataGrid
|
|
|
99
99
|
/** 是否允许全选,默认为true */
|
|
100
100
|
allowSelectAll?: boolean;
|
|
101
101
|
selectorProps?(row: R, index: number, rows: R[]): CheckboxProps | RadioProps;
|
|
102
|
+
onToggle?(checked: boolean, value: Id, option?: R): void;
|
|
102
103
|
defaultExpanded?: Id[];
|
|
103
104
|
expanded?: Id[];
|
|
104
105
|
onExpandedChange?(expanded: Id[], key: Id, isExpand: boolean): void;
|
|
@@ -19,7 +19,7 @@ const DataGridContext = (0, react_1.createContext)({});
|
|
|
19
19
|
function useDataGridContext() {
|
|
20
20
|
return (0, react_1.useContext)(DataGridContext);
|
|
21
21
|
}
|
|
22
|
-
exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
22
|
+
exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, onToggle, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
23
23
|
/**
|
|
24
24
|
* ---------------------------------------------------------------
|
|
25
25
|
* 选择行
|
|
@@ -135,7 +135,7 @@ exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProp
|
|
|
135
135
|
const renderedContent = ((0, jsx_runtime_1.jsx)(columnResize_1.ColumnResizeContext, { columnResizable: columnResizable, children: ({ scrollerRef, tableRef }) => (0, jsx_runtime_1.jsxs)(Container, { ...(0, utils_1.mergeComponentProps)(containerProps, {
|
|
136
136
|
ref: scrollerRef,
|
|
137
137
|
className: dataGrid_style_1.classes.container
|
|
138
|
-
}), children: [(0, jsx_runtime_1.jsx)(table_1.Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: (0, utils_1.cloneRef)(tableProps?.ref, tableRef), children: (0, jsx_runtime_1.jsxs)(selectionContext_1.SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, children: [(0, jsx_runtime_1.jsx)(dataGridHead_1.DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsx)(DataGridContext, { value: (0, react_1.useMemo)(() => ({
|
|
138
|
+
}), children: [(0, jsx_runtime_1.jsx)(table_1.Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: (0, utils_1.cloneRef)(tableProps?.ref, tableRef), children: (0, jsx_runtime_1.jsxs)(selectionContext_1.SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, onToggle: onToggle, children: [(0, jsx_runtime_1.jsx)(dataGridHead_1.DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsx)(DataGridContext, { value: (0, react_1.useMemo)(() => ({
|
|
139
139
|
slots, slotProps,
|
|
140
140
|
rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
|
|
141
141
|
expandedSet, flattedColumns, toggleExpanded
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { ReactElement,
|
|
1
|
+
import { ReactElement, Ref } from 'react';
|
|
2
2
|
import { DialogProps } from '../dialog';
|
|
3
3
|
import { OptionType, SelectionContextBaseProps } from '../selectionContext';
|
|
4
4
|
import { SelectedListProps } from '../selectedList';
|
|
5
|
-
import { Id } from '../../types';
|
|
5
|
+
import { Id, SelectableProps } from '../../types';
|
|
6
6
|
export type PickerDialogRef<V extends Id = Id> = {
|
|
7
7
|
open(value?: V | V[]): Promise<V | V[]>;
|
|
8
8
|
};
|
|
9
|
-
export interface
|
|
9
|
+
export interface PickerDialogBaseProps<O extends OptionType<V>, V extends Id = Id> extends Omit<DialogProps, 'ref' | 'onConfirm' | 'onToggle' | 'onChange'>, SelectionContextBaseProps<O, V> {
|
|
10
10
|
ref?: Ref<PickerDialogRef<V>>;
|
|
11
11
|
/** 默认的ref已被PickerDialogRef取代,需要dialogRef指向dialog元素 */
|
|
12
12
|
dialogRef?: Ref<HTMLDivElement>;
|
|
13
|
-
multiple?: boolean;
|
|
14
|
-
children?: ReactNode | ((selectionProps: Omit<SelectionContextBaseProps<O, V>, 'children'> & {
|
|
15
|
-
multiple?: boolean;
|
|
16
|
-
}) => ReactNode);
|
|
17
13
|
showSelectedList?: boolean;
|
|
18
14
|
/** 已选列表的位置,默认为`right` */
|
|
19
15
|
selectedListPlacement?: 'left' | 'right';
|
|
20
16
|
selectedListProps?: SelectedListProps<V>;
|
|
21
17
|
selectedItemProps?: SelectedListProps<V>['itemProps'];
|
|
22
18
|
onConfirm?(value: V | V[]): void;
|
|
19
|
+
onClear?(): void;
|
|
23
20
|
/** @alias {@link options} */
|
|
24
21
|
rows?: O[];
|
|
25
22
|
/** @alias {@link options} */
|
|
26
23
|
nodes?: O[];
|
|
27
24
|
}
|
|
25
|
+
export type PickerDialogProps<O extends OptionType<V>, V extends Id = Id> = PickerDialogBaseProps<O, V> & SelectableProps<V>;
|
|
28
26
|
export declare const PickerDialog: <O extends OptionType<V>, V extends Id = Id>(props: PickerDialogProps<O, V>) => ReactElement;
|
|
@@ -12,9 +12,9 @@ const selectedList_1 = require("../selectedList");
|
|
|
12
12
|
const button_1 = require("../button");
|
|
13
13
|
const icon_1 = require("../icon");
|
|
14
14
|
const faTrashCan_1 = require("@fortawesome/free-regular-svg-icons/faTrashCan");
|
|
15
|
-
exports.PickerDialog = (({ ref, dialogRef, multiple,
|
|
16
|
-
// 以下属性从
|
|
17
|
-
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, ...props }) => {
|
|
15
|
+
exports.PickerDialog = (({ ref, dialogRef, multiple, showSelectedList = !!multiple, selectedListPlacement = 'right', selectedListProps, selectedItemProps, onConfirm, onClear, rows, nodes,
|
|
16
|
+
// 以下属性从SelectionContextProps继承
|
|
17
|
+
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, defaultValue, value, onChange, ...props }) => {
|
|
18
18
|
const resolvers = (0, react_1.useRef)(void 0);
|
|
19
19
|
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
20
20
|
open(value) {
|
|
@@ -24,12 +24,16 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
24
24
|
return promise;
|
|
25
25
|
}
|
|
26
26
|
}));
|
|
27
|
-
const [innerValue, _setInnerValue] = (0,
|
|
27
|
+
const [innerValue, _setInnerValue] = (0, utils_1.useControlled)(defaultValue || (multiple ? [] : null), value, onChange);
|
|
28
28
|
const setInnerValue = (value) => {
|
|
29
29
|
_setInnerValue(value);
|
|
30
30
|
// 单选模式,值每次改变都触发确认
|
|
31
31
|
!multiple && confirmHandler(value);
|
|
32
32
|
};
|
|
33
|
+
const clearHandler = () => {
|
|
34
|
+
onClear?.();
|
|
35
|
+
setInnerValue(multiple ? [] : null);
|
|
36
|
+
};
|
|
33
37
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(props.defaultOpen, props.open);
|
|
34
38
|
const closeHandler = (reason) => {
|
|
35
39
|
if (reason === 'confirmed') {
|
|
@@ -39,12 +43,12 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
39
43
|
if (!open) {
|
|
40
44
|
resolvers.current?.reject({
|
|
41
45
|
type: 'canceled',
|
|
42
|
-
value: innerValue
|
|
46
|
+
value: innerValue.current
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
setInnerOpen(false);
|
|
46
50
|
};
|
|
47
|
-
const confirmHandler = (value = innerValue) => {
|
|
51
|
+
const confirmHandler = (value = innerValue.current) => {
|
|
48
52
|
onConfirm?.(value);
|
|
49
53
|
resolvers.current?.resolve(value);
|
|
50
54
|
setInnerOpen(false);
|
|
@@ -52,18 +56,7 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
52
56
|
const onExited = () => {
|
|
53
57
|
_setInnerValue(null);
|
|
54
58
|
};
|
|
55
|
-
const
|
|
56
|
-
const selectionProps = { rows, nodes, options, primaryKey, relation, integration, disabled, multiple };
|
|
57
|
-
return typeof children === 'function'
|
|
58
|
-
? children(selectionProps)
|
|
59
|
-
: (0, react_1.isValidElement)(children)
|
|
60
|
-
? (0, react_1.cloneElement)(children, {
|
|
61
|
-
...selectionProps,
|
|
62
|
-
...children.props
|
|
63
|
-
})
|
|
64
|
-
: children;
|
|
65
|
-
};
|
|
66
|
-
const selectedCount = (0, utils_1.toArray)(innerValue)?.length || 0;
|
|
59
|
+
const selectedCount = (0, utils_1.toArray)(innerValue.current)?.length || 0;
|
|
67
60
|
return ((0, jsx_runtime_1.jsx)(selectionContext_1.SelectionContext, { options,
|
|
68
61
|
primaryKey,
|
|
69
62
|
childrenKey,
|
|
@@ -71,7 +64,7 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
71
64
|
integration,
|
|
72
65
|
disabled,
|
|
73
66
|
clearable,
|
|
74
|
-
multiple, value: innerValue, onChange: setInnerValue, onToggle: onToggle, children: (0, jsx_runtime_1.jsx)(dialog_1.Dialog, { ...(0, utils_1.mergeComponentProps)({
|
|
67
|
+
multiple, value: innerValue.current, onChange: setInnerValue, onToggle: onToggle, children: (0, jsx_runtime_1.jsx)(dialog_1.Dialog, { ...(0, utils_1.mergeComponentProps)({
|
|
75
68
|
width: multiple ? '90%' : 1080,
|
|
76
69
|
footer: null,
|
|
77
70
|
maskClosable: false
|
|
@@ -83,6 +76,6 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
83
76
|
modalProps: (0, utils_1.mergeComponentProps)(props.modalProps, { onExited })
|
|
84
77
|
}), onClose: closeHandler, ...showSelectedList && {
|
|
85
78
|
[selectedListPlacement === 'left' ? 'prefix' : 'suffix']: ((0, jsx_runtime_1.jsxs)("div", { className: pickerDialog_style_1.classes.selectedArea, children: [(0, jsx_runtime_1.jsxs)(divider_1.Divider, { className: pickerDialog_style_1.classes.count, textAlign: "start", children: [(0, jsx_runtime_1.jsxs)("div", { children: ["\u5DF2\u9009\u62E9", (0, jsx_runtime_1.jsx)("b", { children: selectedCount }), "\u9879"] }), clearable &&
|
|
86
|
-
(0, jsx_runtime_1.jsx)(button_1.Button, { prefix: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faTrashCan_1.faTrashCan }), variant: "plain", color: "text.secondary", onClick:
|
|
87
|
-
}, children:
|
|
79
|
+
(0, jsx_runtime_1.jsx)(button_1.Button, { prefix: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faTrashCan_1.faTrashCan }), variant: "plain", color: "text.secondary", onClick: clearHandler, children: "\u6E05\u7A7A" })] }), (0, jsx_runtime_1.jsx)(selectedList_1.SelectedList, { itemProps: selectedItemProps, ...selectedListProps, className: (0, utils_1.clsx)(pickerDialog_style_1.classes.list, selectedListProps?.className) }), (0, jsx_runtime_1.jsx)(button_1.Button, { className: pickerDialog_style_1.classes.confirm, disabled: selectedCount === 0, onClick: () => confirmHandler(), children: "\u786E\u5B9A" })] }))
|
|
80
|
+
}, children: props.children }) }));
|
|
88
81
|
});
|
|
@@ -72,7 +72,7 @@ interface DataGridSharedProps<R extends RowType = RowType> extends SlotsAndProps
|
|
|
72
72
|
renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode;
|
|
73
73
|
}
|
|
74
74
|
export type OrderType = 'ascend' | 'descend';
|
|
75
|
-
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onChange'> {
|
|
75
|
+
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onToggle' | 'onChange'> {
|
|
76
76
|
columns?: (ColumnType<R> | symbol)[];
|
|
77
77
|
rows?: R[];
|
|
78
78
|
filterProps?: FormProps;
|
|
@@ -99,6 +99,7 @@ export interface DataGridBaseProps<R extends RowType = RowType> extends DataGrid
|
|
|
99
99
|
/** 是否允许全选,默认为true */
|
|
100
100
|
allowSelectAll?: boolean;
|
|
101
101
|
selectorProps?(row: R, index: number, rows: R[]): CheckboxProps | RadioProps;
|
|
102
|
+
onToggle?(checked: boolean, value: Id, option?: R): void;
|
|
102
103
|
defaultExpanded?: Id[];
|
|
103
104
|
expanded?: Id[];
|
|
104
105
|
onExpandedChange?(expanded: Id[], key: Id, isExpand: boolean): void;
|
|
@@ -15,7 +15,7 @@ const DataGridContext = createContext({});
|
|
|
15
15
|
export function useDataGridContext() {
|
|
16
16
|
return useContext(DataGridContext);
|
|
17
17
|
}
|
|
18
|
-
export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
18
|
+
export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, onToggle, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
19
19
|
/**
|
|
20
20
|
* ---------------------------------------------------------------
|
|
21
21
|
* 选择行
|
|
@@ -131,7 +131,7 @@ export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, prima
|
|
|
131
131
|
const renderedContent = (_jsx(ColumnResizeContext, { columnResizable: columnResizable, children: ({ scrollerRef, tableRef }) => _jsxs(Container, { ...mergeComponentProps(containerProps, {
|
|
132
132
|
ref: scrollerRef,
|
|
133
133
|
className: classes.container
|
|
134
|
-
}), children: [_jsx(Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: cloneRef(tableProps?.ref, tableRef), children: _jsxs(SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, children: [_jsx(DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), _jsx("tbody", { children: _jsx(DataGridContext, { value: useMemo(() => ({
|
|
134
|
+
}), children: [_jsx(Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: cloneRef(tableProps?.ref, tableRef), children: _jsxs(SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, onToggle: onToggle, children: [_jsx(DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), _jsx("tbody", { children: _jsx(DataGridContext, { value: useMemo(() => ({
|
|
135
135
|
slots, slotProps,
|
|
136
136
|
rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
|
|
137
137
|
expandedSet, flattedColumns, toggleExpanded
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { ReactElement,
|
|
1
|
+
import { ReactElement, Ref } from 'react';
|
|
2
2
|
import { DialogProps } from '../dialog/index.js';
|
|
3
3
|
import { OptionType, SelectionContextBaseProps } from '../selectionContext/index.js';
|
|
4
4
|
import { SelectedListProps } from '../selectedList/index.js';
|
|
5
|
-
import { Id } from '../../types.js';
|
|
5
|
+
import { Id, SelectableProps } from '../../types.js';
|
|
6
6
|
export type PickerDialogRef<V extends Id = Id> = {
|
|
7
7
|
open(value?: V | V[]): Promise<V | V[]>;
|
|
8
8
|
};
|
|
9
|
-
export interface
|
|
9
|
+
export interface PickerDialogBaseProps<O extends OptionType<V>, V extends Id = Id> extends Omit<DialogProps, 'ref' | 'onConfirm' | 'onToggle' | 'onChange'>, SelectionContextBaseProps<O, V> {
|
|
10
10
|
ref?: Ref<PickerDialogRef<V>>;
|
|
11
11
|
/** 默认的ref已被PickerDialogRef取代,需要dialogRef指向dialog元素 */
|
|
12
12
|
dialogRef?: Ref<HTMLDivElement>;
|
|
13
|
-
multiple?: boolean;
|
|
14
|
-
children?: ReactNode | ((selectionProps: Omit<SelectionContextBaseProps<O, V>, 'children'> & {
|
|
15
|
-
multiple?: boolean;
|
|
16
|
-
}) => ReactNode);
|
|
17
13
|
showSelectedList?: boolean;
|
|
18
14
|
/** 已选列表的位置,默认为`right` */
|
|
19
15
|
selectedListPlacement?: 'left' | 'right';
|
|
20
16
|
selectedListProps?: SelectedListProps<V>;
|
|
21
17
|
selectedItemProps?: SelectedListProps<V>['itemProps'];
|
|
22
18
|
onConfirm?(value: V | V[]): void;
|
|
19
|
+
onClear?(): void;
|
|
23
20
|
/** @alias {@link options} */
|
|
24
21
|
rows?: O[];
|
|
25
22
|
/** @alias {@link options} */
|
|
26
23
|
nodes?: O[];
|
|
27
24
|
}
|
|
25
|
+
export type PickerDialogProps<O extends OptionType<V>, V extends Id = Id> = PickerDialogBaseProps<O, V> & SelectableProps<V>;
|
|
28
26
|
export declare const PickerDialog: <O extends OptionType<V>, V extends Id = Id>(props: PickerDialogProps<O, V>) => ReactElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useImperativeHandle, useRef } from 'react';
|
|
3
3
|
import { Dialog } from '../dialog/index.js';
|
|
4
4
|
import { clsx, mergeComponentProps, toArray, useControlled } from '../../utils/index.js';
|
|
5
5
|
import { classes, style } from './pickerDialog.style.js';
|
|
@@ -9,9 +9,9 @@ import { SelectedList } from '../selectedList/index.js';
|
|
|
9
9
|
import { Button } from '../button/index.js';
|
|
10
10
|
import { Icon } from '../icon/index.js';
|
|
11
11
|
import { faTrashCan } from '@fortawesome/free-regular-svg-icons/faTrashCan';
|
|
12
|
-
export const PickerDialog = (({ ref, dialogRef, multiple,
|
|
13
|
-
// 以下属性从
|
|
14
|
-
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, ...props }) => {
|
|
12
|
+
export const PickerDialog = (({ ref, dialogRef, multiple, showSelectedList = !!multiple, selectedListPlacement = 'right', selectedListProps, selectedItemProps, onConfirm, onClear, rows, nodes,
|
|
13
|
+
// 以下属性从SelectionContextProps继承
|
|
14
|
+
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, defaultValue, value, onChange, ...props }) => {
|
|
15
15
|
const resolvers = useRef(void 0);
|
|
16
16
|
useImperativeHandle(ref, () => ({
|
|
17
17
|
open(value) {
|
|
@@ -21,12 +21,16 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
21
21
|
return promise;
|
|
22
22
|
}
|
|
23
23
|
}));
|
|
24
|
-
const [innerValue, _setInnerValue] =
|
|
24
|
+
const [innerValue, _setInnerValue] = useControlled(defaultValue || (multiple ? [] : null), value, onChange);
|
|
25
25
|
const setInnerValue = (value) => {
|
|
26
26
|
_setInnerValue(value);
|
|
27
27
|
// 单选模式,值每次改变都触发确认
|
|
28
28
|
!multiple && confirmHandler(value);
|
|
29
29
|
};
|
|
30
|
+
const clearHandler = () => {
|
|
31
|
+
onClear?.();
|
|
32
|
+
setInnerValue(multiple ? [] : null);
|
|
33
|
+
};
|
|
30
34
|
const [innerOpen, setInnerOpen] = useControlled(props.defaultOpen, props.open);
|
|
31
35
|
const closeHandler = (reason) => {
|
|
32
36
|
if (reason === 'confirmed') {
|
|
@@ -36,12 +40,12 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
36
40
|
if (!open) {
|
|
37
41
|
resolvers.current?.reject({
|
|
38
42
|
type: 'canceled',
|
|
39
|
-
value: innerValue
|
|
43
|
+
value: innerValue.current
|
|
40
44
|
});
|
|
41
45
|
}
|
|
42
46
|
setInnerOpen(false);
|
|
43
47
|
};
|
|
44
|
-
const confirmHandler = (value = innerValue) => {
|
|
48
|
+
const confirmHandler = (value = innerValue.current) => {
|
|
45
49
|
onConfirm?.(value);
|
|
46
50
|
resolvers.current?.resolve(value);
|
|
47
51
|
setInnerOpen(false);
|
|
@@ -49,18 +53,7 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
49
53
|
const onExited = () => {
|
|
50
54
|
_setInnerValue(null);
|
|
51
55
|
};
|
|
52
|
-
const
|
|
53
|
-
const selectionProps = { rows, nodes, options, primaryKey, relation, integration, disabled, multiple };
|
|
54
|
-
return typeof children === 'function'
|
|
55
|
-
? children(selectionProps)
|
|
56
|
-
: isValidElement(children)
|
|
57
|
-
? cloneElement(children, {
|
|
58
|
-
...selectionProps,
|
|
59
|
-
...children.props
|
|
60
|
-
})
|
|
61
|
-
: children;
|
|
62
|
-
};
|
|
63
|
-
const selectedCount = toArray(innerValue)?.length || 0;
|
|
56
|
+
const selectedCount = toArray(innerValue.current)?.length || 0;
|
|
64
57
|
return (_jsx(SelectionContext, { options,
|
|
65
58
|
primaryKey,
|
|
66
59
|
childrenKey,
|
|
@@ -68,7 +61,7 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
68
61
|
integration,
|
|
69
62
|
disabled,
|
|
70
63
|
clearable,
|
|
71
|
-
multiple, value: innerValue, onChange: setInnerValue, onToggle: onToggle, children: _jsx(Dialog, { ...mergeComponentProps({
|
|
64
|
+
multiple, value: innerValue.current, onChange: setInnerValue, onToggle: onToggle, children: _jsx(Dialog, { ...mergeComponentProps({
|
|
72
65
|
width: multiple ? '90%' : 1080,
|
|
73
66
|
footer: null,
|
|
74
67
|
maskClosable: false
|
|
@@ -80,6 +73,6 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
80
73
|
modalProps: mergeComponentProps(props.modalProps, { onExited })
|
|
81
74
|
}), onClose: closeHandler, ...showSelectedList && {
|
|
82
75
|
[selectedListPlacement === 'left' ? 'prefix' : 'suffix']: (_jsxs("div", { className: classes.selectedArea, children: [_jsxs(Divider, { className: classes.count, textAlign: "start", children: [_jsxs("div", { children: ["\u5DF2\u9009\u62E9", _jsx("b", { children: selectedCount }), "\u9879"] }), clearable &&
|
|
83
|
-
_jsx(Button, { prefix: _jsx(Icon, { icon: faTrashCan }), variant: "plain", color: "text.secondary", onClick:
|
|
84
|
-
}, children:
|
|
76
|
+
_jsx(Button, { prefix: _jsx(Icon, { icon: faTrashCan }), variant: "plain", color: "text.secondary", onClick: clearHandler, children: "\u6E05\u7A7A" })] }), _jsx(SelectedList, { itemProps: selectedItemProps, ...selectedListProps, className: clsx(classes.list, selectedListProps?.className) }), _jsx(Button, { className: classes.confirm, disabled: selectedCount === 0, onClick: () => confirmHandler(), children: "\u786E\u5B9A" })] }))
|
|
77
|
+
}, children: props.children }) }));
|
|
85
78
|
});
|