@etsoo/react 1.4.10 → 1.4.11
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/lib/mu/DnDList.d.ts +4 -0
- package/lib/mu/DnDList.js +6 -3
- package/package.json +1 -1
- package/src/mu/DnDList.tsx +11 -2
package/lib/mu/DnDList.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ export interface DnDListProps<D extends {}, E extends React.ElementType> {
|
|
|
36
36
|
* Data change handler
|
|
37
37
|
*/
|
|
38
38
|
onChange?: (items: D[]) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Drag end handler
|
|
41
|
+
*/
|
|
42
|
+
onDragEnd?: (items: D[]) => void;
|
|
39
43
|
/**
|
|
40
44
|
* Top and bottom sides renderer
|
|
41
45
|
*/
|
package/lib/mu/DnDList.js
CHANGED
|
@@ -9,7 +9,7 @@ import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
|
|
|
9
9
|
*/
|
|
10
10
|
export function DnDList(props) {
|
|
11
11
|
// Destruct
|
|
12
|
-
const { children, Component = 'div', componentProps, getItemStyle = (_isDragging) => ({}), getListStyle = () => undefined, labelField, loadData, name, onChange, sideRenderer } = props;
|
|
12
|
+
const { children, Component = 'div', componentProps, getItemStyle = (_isDragging) => ({}), getListStyle = () => undefined, labelField, loadData, name, onChange, onDragEnd, sideRenderer } = props;
|
|
13
13
|
// State
|
|
14
14
|
const [items, setItems] = React.useState([]);
|
|
15
15
|
const changeItems = (items) => {
|
|
@@ -20,7 +20,7 @@ export function DnDList(props) {
|
|
|
20
20
|
setItems(items);
|
|
21
21
|
};
|
|
22
22
|
// Drag end handler
|
|
23
|
-
const
|
|
23
|
+
const onDragEndLocal = (result) => {
|
|
24
24
|
// Dropped outside the list
|
|
25
25
|
if (!result.destination) {
|
|
26
26
|
return;
|
|
@@ -33,6 +33,9 @@ export function DnDList(props) {
|
|
|
33
33
|
newItems.splice(result.destination.index, 0, removed);
|
|
34
34
|
// Update the state
|
|
35
35
|
changeItems(newItems);
|
|
36
|
+
// Drag end handler
|
|
37
|
+
if (onDragEnd)
|
|
38
|
+
onDragEnd(newItems);
|
|
36
39
|
};
|
|
37
40
|
// Add item
|
|
38
41
|
const addItem = (newItem) => {
|
|
@@ -95,7 +98,7 @@ export function DnDList(props) {
|
|
|
95
98
|
return (React.createElement(React.Fragment, null,
|
|
96
99
|
sideRenderer && sideRenderer(true, addItem, addItems),
|
|
97
100
|
React.createElement(Component, { ...componentProps },
|
|
98
|
-
React.createElement(DragDropContext, { onDragEnd:
|
|
101
|
+
React.createElement(DragDropContext, { onDragEnd: onDragEndLocal },
|
|
99
102
|
React.createElement(Droppable, { droppableId: name }, (provided, snapshot) => (React.createElement("div", { ...provided.droppableProps, ref: provided.innerRef, style: getListStyle(snapshot.isDraggingOver) },
|
|
100
103
|
items.map((item, index) => {
|
|
101
104
|
// Id
|
package/package.json
CHANGED
package/src/mu/DnDList.tsx
CHANGED
|
@@ -57,6 +57,11 @@ export interface DnDListProps<D extends {}, E extends React.ElementType> {
|
|
|
57
57
|
*/
|
|
58
58
|
onChange?: (items: D[]) => void;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Drag end handler
|
|
62
|
+
*/
|
|
63
|
+
onDragEnd?: (items: D[]) => void;
|
|
64
|
+
|
|
60
65
|
/**
|
|
61
66
|
* Top and bottom sides renderer
|
|
62
67
|
*/
|
|
@@ -93,6 +98,7 @@ export function DnDList<
|
|
|
93
98
|
loadData,
|
|
94
99
|
name,
|
|
95
100
|
onChange,
|
|
101
|
+
onDragEnd,
|
|
96
102
|
sideRenderer
|
|
97
103
|
} = props;
|
|
98
104
|
|
|
@@ -108,7 +114,7 @@ export function DnDList<
|
|
|
108
114
|
};
|
|
109
115
|
|
|
110
116
|
// Drag end handler
|
|
111
|
-
const
|
|
117
|
+
const onDragEndLocal = (result: DropResult) => {
|
|
112
118
|
// Dropped outside the list
|
|
113
119
|
if (!result.destination) {
|
|
114
120
|
return;
|
|
@@ -125,6 +131,9 @@ export function DnDList<
|
|
|
125
131
|
|
|
126
132
|
// Update the state
|
|
127
133
|
changeItems(newItems);
|
|
134
|
+
|
|
135
|
+
// Drag end handler
|
|
136
|
+
if (onDragEnd) onDragEnd(newItems);
|
|
128
137
|
};
|
|
129
138
|
|
|
130
139
|
// Add item
|
|
@@ -211,7 +220,7 @@ export function DnDList<
|
|
|
211
220
|
<React.Fragment>
|
|
212
221
|
{sideRenderer && sideRenderer(true, addItem, addItems)}
|
|
213
222
|
<Component {...componentProps}>
|
|
214
|
-
<DragDropContext onDragEnd={
|
|
223
|
+
<DragDropContext onDragEnd={onDragEndLocal}>
|
|
215
224
|
<Droppable droppableId={name}>
|
|
216
225
|
{(provided, snapshot) => (
|
|
217
226
|
<div
|