@canlooks/can-ui 0.0.206 → 0.0.207
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.
|
@@ -7,5 +7,6 @@ export type SelectedListProps<V extends Id = Id> = Omit<TransitionGroupProps, 'r
|
|
|
7
7
|
value?: V[];
|
|
8
8
|
itemProps?(value: V, index: number): AlertProps | Promise<AlertProps>;
|
|
9
9
|
onClose?(value: V, index: number): void;
|
|
10
|
+
onSort?(value: V[]): void;
|
|
10
11
|
};
|
|
11
12
|
export declare const SelectedList: <V extends Id = Id>(props: SelectedListProps<V>) => ReactElement;
|
|
@@ -9,7 +9,7 @@ const react_transition_group_1 = require("react-transition-group");
|
|
|
9
9
|
const selectionContext_1 = require("../selectionContext");
|
|
10
10
|
const selectedItem_1 = require("./selectedItem");
|
|
11
11
|
const react_2 = require("@dnd-kit/react");
|
|
12
|
-
exports.SelectedList = (0, react_1.memo)(({ value, itemProps, onClose, ...props }) => {
|
|
12
|
+
exports.SelectedList = (0, react_1.memo)(({ value, itemProps, onClose, onSort, ...props }) => {
|
|
13
13
|
const { value: innerValue, setValue: setInnerValue } = (0, selectionContext_1.useSelectionContext)();
|
|
14
14
|
const arr = (0, utils_1.toArray)(value || innerValue);
|
|
15
15
|
const closeHandler = (v, i) => {
|
|
@@ -18,7 +18,10 @@ exports.SelectedList = (0, react_1.memo)(({ value, itemProps, onClose, ...props
|
|
|
18
18
|
};
|
|
19
19
|
const dragEndHandler = e => {
|
|
20
20
|
const newValue = (0, utils_1.onDndDragEnd)(e, arr);
|
|
21
|
-
|
|
21
|
+
if (newValue) {
|
|
22
|
+
onSort?.(newValue);
|
|
23
|
+
setInnerValue?.(newValue);
|
|
24
|
+
}
|
|
22
25
|
};
|
|
23
26
|
return ((0, jsx_runtime_1.jsx)(react_2.DragDropProvider, { sensors: utils_1.defaultSensors, onDragEnd: dragEndHandler, children: (0, jsx_runtime_1.jsx)(react_transition_group_1.TransitionGroup, { ...props, css: selectedList_style_1.style, className: (0, utils_1.clsx)(selectedList_style_1.classes.root, props.className), children: arr?.map((v, i) => (0, jsx_runtime_1.jsx)(selectedItem_1.SelectedItem, { value: v, index: i, itemProps: itemProps, onClose: closeHandler }, v)) }) }));
|
|
24
27
|
});
|
|
@@ -7,5 +7,6 @@ export type SelectedListProps<V extends Id = Id> = Omit<TransitionGroupProps, 'r
|
|
|
7
7
|
value?: V[];
|
|
8
8
|
itemProps?(value: V, index: number): AlertProps | Promise<AlertProps>;
|
|
9
9
|
onClose?(value: V, index: number): void;
|
|
10
|
+
onSort?(value: V[]): void;
|
|
10
11
|
};
|
|
11
12
|
export declare const SelectedList: <V extends Id = Id>(props: SelectedListProps<V>) => ReactElement;
|
|
@@ -6,7 +6,7 @@ import { TransitionGroup } from 'react-transition-group';
|
|
|
6
6
|
import { useSelectionContext } from '../selectionContext/index.js';
|
|
7
7
|
import { SelectedItem } from './selectedItem.js';
|
|
8
8
|
import { DragDropProvider } from '@dnd-kit/react';
|
|
9
|
-
export const SelectedList = memo(({ value, itemProps, onClose, ...props }) => {
|
|
9
|
+
export const SelectedList = memo(({ value, itemProps, onClose, onSort, ...props }) => {
|
|
10
10
|
const { value: innerValue, setValue: setInnerValue } = useSelectionContext();
|
|
11
11
|
const arr = toArray(value || innerValue);
|
|
12
12
|
const closeHandler = (v, i) => {
|
|
@@ -15,7 +15,10 @@ export const SelectedList = memo(({ value, itemProps, onClose, ...props }) => {
|
|
|
15
15
|
};
|
|
16
16
|
const dragEndHandler = e => {
|
|
17
17
|
const newValue = onDndDragEnd(e, arr);
|
|
18
|
-
|
|
18
|
+
if (newValue) {
|
|
19
|
+
onSort?.(newValue);
|
|
20
|
+
setInnerValue?.(newValue);
|
|
21
|
+
}
|
|
19
22
|
};
|
|
20
23
|
return (_jsx(DragDropProvider, { sensors: defaultSensors, onDragEnd: dragEndHandler, children: _jsx(TransitionGroup, { ...props, css: style, className: clsx(classes.root, props.className), children: arr?.map((v, i) => _jsx(SelectedItem, { value: v, index: i, itemProps: itemProps, onClose: closeHandler }, v)) }) }));
|
|
21
24
|
});
|