@patternfly/react-drag-drop 6.0.0-alpha.9 → 6.0.0-prerelease.1
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/CHANGELOG.md +579 -0
- package/dist/cjs.tsbuildinfo +1 -1
- package/dist/esm/{next/components → components}/DragDrop/DragButton.d.ts +5 -1
- package/dist/esm/components/DragDrop/DragButton.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DragButton.js +13 -0
- package/dist/esm/components/DragDrop/DragButton.js.map +1 -0
- package/dist/esm/components/DragDrop/DragDropContainer.d.ts +41 -0
- package/dist/esm/components/DragDrop/DragDropContainer.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DragDropContainer.js +147 -0
- package/dist/esm/components/DragDrop/DragDropContainer.js.map +1 -0
- package/dist/esm/{next/components → components}/DragDrop/DragDropSort.d.ts +8 -14
- package/dist/esm/components/DragDrop/DragDropSort.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DragDropSort.js +22 -0
- package/dist/esm/components/DragDrop/DragDropSort.js.map +1 -0
- package/dist/esm/components/DragDrop/Draggable.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/Draggable.js.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDataListItem.js.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
- package/dist/esm/{next/components → components}/DragDrop/DraggableDualListSelectorListItem.js +1 -1
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
- package/dist/esm/components/DragDrop/Droppable.d.ts +22 -0
- package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/Droppable.js +28 -0
- package/dist/esm/components/DragDrop/Droppable.js.map +1 -0
- package/dist/esm/components/DragDrop/index.d.ts +4 -0
- package/dist/esm/components/DragDrop/index.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/index.js +4 -0
- package/dist/esm/components/DragDrop/index.js.map +1 -0
- package/dist/esm/components/index.d.ts.map +1 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm.tsbuildinfo +1 -1
- package/dist/js/{next/components → components}/DragDrop/DragButton.d.ts +5 -1
- package/dist/js/components/DragDrop/DragButton.d.ts.map +1 -0
- package/dist/js/{next/components → components}/DragDrop/DragButton.js +4 -5
- package/dist/js/components/DragDrop/DragButton.js.map +1 -0
- package/dist/js/components/DragDrop/DragDropContainer.d.ts +41 -0
- package/dist/js/components/DragDrop/DragDropContainer.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DragDropContainer.js +151 -0
- package/dist/js/components/DragDrop/DragDropContainer.js.map +1 -0
- package/dist/js/{next/components → components}/DragDrop/DragDropSort.d.ts +8 -14
- package/dist/js/components/DragDrop/DragDropSort.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DragDropSort.js +26 -0
- package/dist/js/components/DragDrop/DragDropSort.js.map +1 -0
- package/dist/js/components/DragDrop/Draggable.d.ts.map +1 -0
- package/dist/js/components/DragDrop/Draggable.js.map +1 -0
- package/dist/js/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DraggableDataListItem.js.map +1 -0
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
- package/dist/js/{next/components → components}/DragDrop/DraggableDualListSelectorListItem.js +2 -2
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
- package/dist/js/components/DragDrop/Droppable.d.ts +22 -0
- package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -0
- package/dist/js/components/DragDrop/Droppable.js +32 -0
- package/dist/js/components/DragDrop/Droppable.js.map +1 -0
- package/dist/js/components/DragDrop/index.d.ts +4 -0
- package/dist/js/components/DragDrop/index.d.ts.map +1 -0
- package/dist/js/{next/components → components}/DragDrop/index.js +2 -0
- package/dist/js/components/DragDrop/index.js.map +1 -0
- package/dist/js/components/index.d.ts.map +1 -0
- package/dist/js/components/index.js.map +1 -0
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.d.ts.map +1 -1
- package/dist/js/index.js +1 -1
- package/dist/js/index.js.map +1 -1
- package/package.json +6 -11
- package/src/components/DragDrop/DragButton.tsx +39 -0
- package/src/components/DragDrop/DragDropContainer.tsx +305 -0
- package/src/components/DragDrop/DragDropSort.tsx +67 -0
- package/src/{next/components → components}/DragDrop/DraggableDualListSelectorListItem.tsx +1 -1
- package/src/components/DragDrop/Droppable.tsx +76 -0
- package/src/{next/components → components}/DragDrop/__tests__/DragDrop.test.tsx +5 -0
- package/src/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +149 -0
- package/src/{next/components → components}/DragDrop/examples/DataListDraggable.tsx +1 -0
- package/src/{next/components → components}/DragDrop/examples/DragDrop.md +3 -4
- package/src/components/DragDrop/examples/DragDropContainerBasic.tsx +45 -0
- package/src/components/DragDrop/examples/DragDropContainerDataList.tsx +75 -0
- package/src/components/DragDrop/examples/DragDropContainerDualListSelector.tsx +191 -0
- package/src/{next/components → components}/DragDrop/examples/DragDropDemos.md +26 -3
- package/src/{next/components → components}/DragDrop/examples/DualListSelectorDraggable.tsx +8 -12
- package/src/components/DragDrop/index.ts +3 -0
- package/src/index.ts +1 -1
- package/dist/esm/next/components/DragDrop/DragButton.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/DragButton.js +0 -14
- package/dist/esm/next/components/DragDrop/DragButton.js.map +0 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.js +0 -70
- package/dist/esm/next/components/DragDrop/DragDropSort.js.map +0 -1
- package/dist/esm/next/components/DragDrop/Draggable.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/Draggable.js.map +0 -1
- package/dist/esm/next/components/DragDrop/DraggableDataListItem.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/DraggableDataListItem.js.map +0 -1
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +0 -1
- package/dist/esm/next/components/DragDrop/Droppable.d.ts +0 -16
- package/dist/esm/next/components/DragDrop/Droppable.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/Droppable.js +0 -11
- package/dist/esm/next/components/DragDrop/Droppable.js.map +0 -1
- package/dist/esm/next/components/DragDrop/DroppableContext.d.ts +0 -6
- package/dist/esm/next/components/DragDrop/DroppableContext.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/DroppableContext.js +0 -6
- package/dist/esm/next/components/DragDrop/DroppableContext.js.map +0 -1
- package/dist/esm/next/components/DragDrop/index.d.ts +0 -2
- package/dist/esm/next/components/DragDrop/index.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/index.js +0 -2
- package/dist/esm/next/components/DragDrop/index.js.map +0 -1
- package/dist/esm/next/components/index.d.ts.map +0 -1
- package/dist/esm/next/components/index.js.map +0 -1
- package/dist/esm/next/index.d.ts +0 -2
- package/dist/esm/next/index.d.ts.map +0 -1
- package/dist/esm/next/index.js +0 -2
- package/dist/esm/next/index.js.map +0 -1
- package/dist/js/next/components/DragDrop/DragButton.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/DragButton.js.map +0 -1
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/DragDropSort.js +0 -74
- package/dist/js/next/components/DragDrop/DragDropSort.js.map +0 -1
- package/dist/js/next/components/DragDrop/Draggable.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/Draggable.js.map +0 -1
- package/dist/js/next/components/DragDrop/DraggableDataListItem.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/DraggableDataListItem.js.map +0 -1
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +0 -1
- package/dist/js/next/components/DragDrop/Droppable.d.ts +0 -16
- package/dist/js/next/components/DragDrop/Droppable.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/Droppable.js +0 -15
- package/dist/js/next/components/DragDrop/Droppable.js.map +0 -1
- package/dist/js/next/components/DragDrop/DroppableContext.d.ts +0 -6
- package/dist/js/next/components/DragDrop/DroppableContext.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/DroppableContext.js +0 -10
- package/dist/js/next/components/DragDrop/DroppableContext.js.map +0 -1
- package/dist/js/next/components/DragDrop/index.d.ts +0 -2
- package/dist/js/next/components/DragDrop/index.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/index.js.map +0 -1
- package/dist/js/next/components/index.d.ts.map +0 -1
- package/dist/js/next/components/index.js.map +0 -1
- package/dist/js/next/index.d.ts +0 -2
- package/dist/js/next/index.d.ts.map +0 -1
- package/dist/js/next/index.js +0 -5
- package/dist/js/next/index.js.map +0 -1
- package/src/next/components/DragDrop/DragButton.tsx +0 -27
- package/src/next/components/DragDrop/DragDropSort.tsx +0 -182
- package/src/next/components/DragDrop/Droppable.tsx +0 -27
- package/src/next/components/DragDrop/DroppableContext.ts +0 -6
- package/src/next/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +0 -59
- package/src/next/components/DragDrop/examples/BasicSortingWithDragButton.tsx +0 -20
- package/src/next/components/DragDrop/index.ts +0 -1
- package/src/next/index.ts +0 -1
- /package/dist/esm/{next/components → components}/DragDrop/Draggable.d.ts +0 -0
- /package/dist/esm/{next/components → components}/DragDrop/Draggable.js +0 -0
- /package/dist/esm/{next/components → components}/DragDrop/DraggableDataListItem.d.ts +0 -0
- /package/dist/esm/{next/components → components}/DragDrop/DraggableDataListItem.js +0 -0
- /package/dist/esm/{next/components → components}/DragDrop/DraggableDualListSelectorListItem.d.ts +0 -0
- /package/dist/esm/{next/components → components}/index.d.ts +0 -0
- /package/dist/esm/{next/components → components}/index.js +0 -0
- /package/dist/js/{next/components → components}/DragDrop/Draggable.d.ts +0 -0
- /package/dist/js/{next/components → components}/DragDrop/Draggable.js +0 -0
- /package/dist/js/{next/components → components}/DragDrop/DraggableDataListItem.d.ts +0 -0
- /package/dist/js/{next/components → components}/DragDrop/DraggableDataListItem.js +0 -0
- /package/dist/js/{next/components → components}/DragDrop/DraggableDualListSelectorListItem.d.ts +0 -0
- /package/dist/js/{next/components → components}/index.d.ts +0 -0
- /package/dist/js/{next/components → components}/index.js +0 -0
- /package/src/{next/components → components}/DragDrop/Draggable.tsx +0 -0
- /package/src/{next/components → components}/DragDrop/DraggableDataListItem.tsx +0 -0
- /package/src/{next/components → components}/DragDrop/examples/BasicSorting.tsx +0 -0
- /package/src/{next/components → components}/index.ts +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ReactDOM from 'react-dom';
|
|
3
|
+
import { css } from '@patternfly/react-styles';
|
|
4
|
+
import {
|
|
5
|
+
DndContext,
|
|
6
|
+
closestCenter,
|
|
7
|
+
DragOverlay,
|
|
8
|
+
DndContextProps,
|
|
9
|
+
KeyboardSensor,
|
|
10
|
+
PointerSensor,
|
|
11
|
+
useSensor,
|
|
12
|
+
useSensors,
|
|
13
|
+
DragEndEvent,
|
|
14
|
+
DragStartEvent,
|
|
15
|
+
UniqueIdentifier,
|
|
16
|
+
DragOverEvent,
|
|
17
|
+
CollisionDetection,
|
|
18
|
+
pointerWithin,
|
|
19
|
+
rectIntersection,
|
|
20
|
+
getFirstCollision,
|
|
21
|
+
DragCancelEvent
|
|
22
|
+
} from '@dnd-kit/core';
|
|
23
|
+
import { arrayMove, sortableKeyboardCoordinates } from '@dnd-kit/sortable';
|
|
24
|
+
import { Draggable } from './Draggable';
|
|
25
|
+
import { DraggableDataListItem } from './DraggableDataListItem';
|
|
26
|
+
import { DraggableDualListSelectorListItem } from './DraggableDualListSelectorListItem';
|
|
27
|
+
import styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
28
|
+
import { DataList, canUseDOM } from '@patternfly/react-core';
|
|
29
|
+
|
|
30
|
+
export type DragDropContainerDragStartEvent = DragStartEvent;
|
|
31
|
+
export type DragDropContainerDragOverEvent = DragOverEvent;
|
|
32
|
+
export type DragDropContainerDragEndEvent = DragEndEvent;
|
|
33
|
+
export type DragDropContainerDragCancelEvent = DragCancelEvent;
|
|
34
|
+
|
|
35
|
+
export interface DraggableObject {
|
|
36
|
+
/** Unique id of the draggable object */
|
|
37
|
+
id: string | number;
|
|
38
|
+
/** Content rendered in the draggable object */
|
|
39
|
+
content: React.ReactNode;
|
|
40
|
+
/** Props spread to the rendered wrapper of the draggable object */
|
|
41
|
+
props?: any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* DragDropSortProps extends dnd-kit's props which may be viewed at https://docs.dndkit.com/api-documentation/context-provider#props.
|
|
46
|
+
*/
|
|
47
|
+
export interface DragDropContainerProps extends DndContextProps {
|
|
48
|
+
/** Content containing one or more Droppable zones. */
|
|
49
|
+
children?: React.ReactNode;
|
|
50
|
+
/** Set of records of all child droppables - their zone IDs and their draggable items. */
|
|
51
|
+
items: Record<string, DraggableObject[]>;
|
|
52
|
+
/** Callback when use begins dragging a draggable object */
|
|
53
|
+
onDrag?: (event: DragDropContainerDragStartEvent) => void;
|
|
54
|
+
/** Callback when an item is dragged to another container */
|
|
55
|
+
onContainerMove?: (event: DragDropContainerDragOverEvent, items: Record<string, DraggableObject[]>) => void;
|
|
56
|
+
/** Callback when user drops a draggable object */
|
|
57
|
+
onDrop: (event: DragDropContainerDragEndEvent, items: Record<string, DraggableObject[]>) => void;
|
|
58
|
+
/** Callback when drag is cancelled */
|
|
59
|
+
onCancel?: (event: DragDropContainerDragCancelEvent, items: Record<string, DraggableObject[]>) => void;
|
|
60
|
+
/** The variant determines which component wraps the draggable object.
|
|
61
|
+
* Default variant wraps the draggable object in a div.
|
|
62
|
+
* DataList variant wraps the draggable object in a DataListItem
|
|
63
|
+
* DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
|
|
64
|
+
* */
|
|
65
|
+
variant?: 'default' | 'DataList' | 'DualListSelectorList';
|
|
66
|
+
/** Additional classes to apply to the drag overlay */
|
|
67
|
+
overlayProps?: any;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const DragDropContainer: React.FunctionComponent<DragDropContainerProps> = ({
|
|
71
|
+
children,
|
|
72
|
+
items,
|
|
73
|
+
onDrag = () => {},
|
|
74
|
+
onContainerMove = () => {},
|
|
75
|
+
onDrop = () => {},
|
|
76
|
+
onCancel = () => {},
|
|
77
|
+
variant = 'default',
|
|
78
|
+
overlayProps,
|
|
79
|
+
...props
|
|
80
|
+
}: DragDropContainerProps) => {
|
|
81
|
+
const itemsCopy = React.useRef<Record<string, DraggableObject[]> | null>(null);
|
|
82
|
+
const hasRecentlyMovedContainer = React.useRef(false);
|
|
83
|
+
const [activeId, setActiveId] = React.useState<UniqueIdentifier>(null);
|
|
84
|
+
const lastOverId = React.useRef<UniqueIdentifier | null>(null);
|
|
85
|
+
|
|
86
|
+
const findItem = React.useCallback(
|
|
87
|
+
(id: UniqueIdentifier, containerId: UniqueIdentifier) => items[containerId].find((item) => item.id === id),
|
|
88
|
+
[items]
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const findContainer = React.useCallback(
|
|
92
|
+
(id: UniqueIdentifier) => {
|
|
93
|
+
if (id in items) {
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
96
|
+
return Object.keys(items).find((key) => items[key].find((obj) => obj.id === id));
|
|
97
|
+
},
|
|
98
|
+
[items]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const sensors = useSensors(
|
|
102
|
+
useSensor(PointerSensor),
|
|
103
|
+
useSensor(KeyboardSensor, {
|
|
104
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const collisionDetectionStrategy: CollisionDetection = React.useCallback(
|
|
109
|
+
(args) => {
|
|
110
|
+
if (activeId && activeId in items) {
|
|
111
|
+
return closestCenter({
|
|
112
|
+
...args,
|
|
113
|
+
droppableContainers: args.droppableContainers.filter((container) => container.id in items)
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const pointerIntersections = pointerWithin(args);
|
|
118
|
+
const intersections = pointerIntersections.length > 0 ? pointerIntersections : rectIntersection(args);
|
|
119
|
+
let overId = getFirstCollision(intersections, 'id');
|
|
120
|
+
|
|
121
|
+
if (overId != null) {
|
|
122
|
+
if (overId in items) {
|
|
123
|
+
const containerItems = items[overId];
|
|
124
|
+
|
|
125
|
+
if (containerItems.length > 0) {
|
|
126
|
+
overId = closestCenter({
|
|
127
|
+
...args,
|
|
128
|
+
droppableContainers: args.droppableContainers.filter(
|
|
129
|
+
(container) => container.id !== overId && containerItems.find((obj) => obj.id === container.id)
|
|
130
|
+
)
|
|
131
|
+
})[0]?.id;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
lastOverId.current = overId;
|
|
136
|
+
|
|
137
|
+
return [{ id: overId }];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (hasRecentlyMovedContainer.current) {
|
|
141
|
+
lastOverId.current = activeId;
|
|
142
|
+
}
|
|
143
|
+
return lastOverId.current ? [{ id: lastOverId.current }] : [];
|
|
144
|
+
},
|
|
145
|
+
[activeId, items]
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
React.useEffect(() => {
|
|
149
|
+
requestAnimationFrame(() => {
|
|
150
|
+
hasRecentlyMovedContainer.current = false;
|
|
151
|
+
});
|
|
152
|
+
}, [items]);
|
|
153
|
+
|
|
154
|
+
const handleDragStart = (event: DragStartEvent) => {
|
|
155
|
+
const { active } = event;
|
|
156
|
+
itemsCopy.current = { ...items };
|
|
157
|
+
setActiveId(active.id);
|
|
158
|
+
|
|
159
|
+
onDrag(event);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const handleDragOver = (event: DragOverEvent) => {
|
|
163
|
+
const { active, over } = event;
|
|
164
|
+
const { id: activeId } = active;
|
|
165
|
+
const { id: overId } = over;
|
|
166
|
+
|
|
167
|
+
if (!overId || activeId in items) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const activeContainer = findContainer(activeId);
|
|
172
|
+
const overContainer = findContainer(overId);
|
|
173
|
+
|
|
174
|
+
if (!overContainer || !activeContainer) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (activeContainer !== overContainer) {
|
|
179
|
+
const activeItems = items[activeContainer];
|
|
180
|
+
const overItems = items[overContainer];
|
|
181
|
+
const overIndex = overItems.findIndex((draggableItem) => draggableItem.id === overId);
|
|
182
|
+
const activeIndex = activeItems.findIndex((draggableItem) => draggableItem.id === activeId);
|
|
183
|
+
|
|
184
|
+
const isBelowOverItem =
|
|
185
|
+
over && active.rect.current.translated && active.rect.current.translated.top > over.rect.top + over.rect.height;
|
|
186
|
+
|
|
187
|
+
const modifier = isBelowOverItem ? 1 : 0;
|
|
188
|
+
const newIndex = overIndex >= 0 ? overIndex + modifier : overItems.length + 1;
|
|
189
|
+
|
|
190
|
+
const newItems = {
|
|
191
|
+
...items,
|
|
192
|
+
[activeContainer]: items[activeContainer].filter((item) => item.id !== active.id),
|
|
193
|
+
[overContainer]: [
|
|
194
|
+
...items[overContainer].slice(0, newIndex),
|
|
195
|
+
items[activeContainer][activeIndex],
|
|
196
|
+
...items[overContainer].slice(newIndex, items[overContainer].length)
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
hasRecentlyMovedContainer.current = true;
|
|
201
|
+
onContainerMove(event, newItems);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const handleDragEnd = (event: DragEndEvent) => {
|
|
206
|
+
const { active, over } = event;
|
|
207
|
+
const { id: activeId } = active;
|
|
208
|
+
const { id: overId } = over;
|
|
209
|
+
|
|
210
|
+
const activeContainer = findContainer(activeId);
|
|
211
|
+
if (!over || !activeContainer) {
|
|
212
|
+
setActiveId(null);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const overContainer = findContainer(overId);
|
|
217
|
+
if (!overContainer) {
|
|
218
|
+
setActiveId(null);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const activeIndex = items[activeContainer].findIndex((draggableItem) => draggableItem.id === activeId);
|
|
223
|
+
const overIndex = items[overContainer].findIndex((draggableItem) => draggableItem.id === overId);
|
|
224
|
+
|
|
225
|
+
if (activeIndex !== overIndex) {
|
|
226
|
+
const newItems = { ...items, [overContainer]: arrayMove(items[overContainer], activeIndex, overIndex) };
|
|
227
|
+
onDrop(event, newItems);
|
|
228
|
+
}
|
|
229
|
+
setActiveId(null);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const handleDragCancel = (event: DragCancelEvent) => {
|
|
233
|
+
onCancel(event, itemsCopy.current);
|
|
234
|
+
itemsCopy.current = null;
|
|
235
|
+
setActiveId(null);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const getDragOverlay = () => {
|
|
239
|
+
if (!activeId) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const item = findItem(activeId, findContainer(activeId));
|
|
243
|
+
|
|
244
|
+
let content;
|
|
245
|
+
switch (variant) {
|
|
246
|
+
case 'DualListSelectorList':
|
|
247
|
+
content = (
|
|
248
|
+
<DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
|
|
249
|
+
{item.content}
|
|
250
|
+
</DraggableDualListSelectorListItem>
|
|
251
|
+
);
|
|
252
|
+
break;
|
|
253
|
+
case 'DataList':
|
|
254
|
+
content = (
|
|
255
|
+
<DraggableDataListItem key={item.id} id={item.id} {...item.props}>
|
|
256
|
+
{item.content}
|
|
257
|
+
</DraggableDataListItem>
|
|
258
|
+
);
|
|
259
|
+
break;
|
|
260
|
+
default:
|
|
261
|
+
content = (
|
|
262
|
+
<Draggable useDragButton={variant === 'default'} key={item.id} id={item.id} {...item.props}>
|
|
263
|
+
{item.content}
|
|
264
|
+
</Draggable>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<div
|
|
270
|
+
className={css(styles.draggable, styles.modifiers.dragging)}
|
|
271
|
+
style={
|
|
272
|
+
{
|
|
273
|
+
'--pf-v6-c-draggable--m-dragging--BackgroundColor':
|
|
274
|
+
'var(--pf-t--global--background--color--primary--default)'
|
|
275
|
+
} as React.CSSProperties
|
|
276
|
+
}
|
|
277
|
+
>
|
|
278
|
+
{variant === 'DualListSelectorList' && <ul className="pf-v6-c-dual-list-selector">{content}</ul>}
|
|
279
|
+
{variant === 'DataList' && (
|
|
280
|
+
<DataList aria-label="draggable overlay" {...overlayProps}>
|
|
281
|
+
{content}
|
|
282
|
+
</DataList>
|
|
283
|
+
)}
|
|
284
|
+
{variant !== 'DualListSelectorList' && variant !== 'DataList' && content}
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const dragOverlay = <DragOverlay>{activeId && getDragOverlay()}</DragOverlay>;
|
|
290
|
+
return (
|
|
291
|
+
<DndContext
|
|
292
|
+
sensors={sensors}
|
|
293
|
+
collisionDetection={collisionDetectionStrategy}
|
|
294
|
+
onDragEnd={handleDragEnd}
|
|
295
|
+
onDragOver={handleDragOver}
|
|
296
|
+
onDragStart={handleDragStart}
|
|
297
|
+
onDragCancel={handleDragCancel}
|
|
298
|
+
{...props}
|
|
299
|
+
>
|
|
300
|
+
{children}
|
|
301
|
+
{canUseDOM ? ReactDOM.createPortal(dragOverlay, document.getElementById('root')) : dragOverlay}
|
|
302
|
+
</DndContext>
|
|
303
|
+
);
|
|
304
|
+
};
|
|
305
|
+
DragDropContainer.displayName = 'DragDropContainer';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DndContextProps, DragEndEvent, DragStartEvent } from '@dnd-kit/core';
|
|
3
|
+
import { Droppable } from './Droppable';
|
|
4
|
+
import { DragDropContainer, DraggableObject } from './DragDropContainer';
|
|
5
|
+
|
|
6
|
+
export type DragDropSortDragEndEvent = DragEndEvent;
|
|
7
|
+
export type DragDropSortDragStartEvent = DragStartEvent;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* DragDropSortProps extends dnd-kit's props which may be viewed at https://docs.dndkit.com/api-documentation/context-provider#props.
|
|
11
|
+
*/
|
|
12
|
+
export interface DragDropSortProps extends DndContextProps {
|
|
13
|
+
/** Custom defined content wrapper for draggable items. By default, draggable items are wrapped in a styled div.
|
|
14
|
+
* Intended to be a 'DataList' or 'DualListSelectorList' without children. */
|
|
15
|
+
children?: React.ReactElement;
|
|
16
|
+
/** Sorted array of draggable objects */
|
|
17
|
+
items: DraggableObject[];
|
|
18
|
+
/** Callback when user drops a draggable object */
|
|
19
|
+
onDrop: (event: DragDropSortDragEndEvent, items: DraggableObject[], oldIndex?: number, newIndex?: number) => void;
|
|
20
|
+
/** Callback when use begins dragging a draggable object */
|
|
21
|
+
onDrag?: (event: DragDropSortDragStartEvent, oldIndex: number) => void;
|
|
22
|
+
/** The variant determines which component wraps the draggable object.
|
|
23
|
+
* Default variant wraps the draggable object in a div.
|
|
24
|
+
* DataList variant wraps the draggable object in a DataListItem
|
|
25
|
+
* DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
|
|
26
|
+
* */
|
|
27
|
+
variant?: 'default' | 'DataList' | 'DualListSelectorList';
|
|
28
|
+
/** Additional classes to apply to the drag overlay */
|
|
29
|
+
overlayProps?: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
|
|
33
|
+
items,
|
|
34
|
+
onDrop = () => {},
|
|
35
|
+
onDrag = () => {},
|
|
36
|
+
variant = 'default',
|
|
37
|
+
children,
|
|
38
|
+
overlayProps,
|
|
39
|
+
...props
|
|
40
|
+
}: DragDropSortProps) => {
|
|
41
|
+
const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
|
|
42
|
+
|
|
43
|
+
const handleDragStart = (event: DragStartEvent) => {
|
|
44
|
+
onDrag(event, itemIds.indexOf(event.active.id as string));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleDragEnd = (event: DragEndEvent, newItems: Record<string, DraggableObject[]>) => {
|
|
48
|
+
const { active, over } = event;
|
|
49
|
+
const oldIndex = itemIds.indexOf(active.id as string);
|
|
50
|
+
const newIndex = itemIds.indexOf(over.id as string);
|
|
51
|
+
onDrop(event, newItems[dropZoneId], oldIndex, newIndex);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const dropZoneId = props.id ? props.id : 'droppable';
|
|
55
|
+
return (
|
|
56
|
+
<DragDropContainer
|
|
57
|
+
variant={variant}
|
|
58
|
+
items={{ [dropZoneId]: items }}
|
|
59
|
+
onDrag={handleDragStart}
|
|
60
|
+
onDrop={handleDragEnd}
|
|
61
|
+
overlayProps={overlayProps}
|
|
62
|
+
>
|
|
63
|
+
<Droppable items={items} id={dropZoneId} variant={variant} {...(children && { wrapper: children })} />
|
|
64
|
+
</DragDropContainer>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
DragDropSort.displayName = 'DragDropSort';
|
|
@@ -5,7 +5,7 @@ import { css } from '@patternfly/react-styles';
|
|
|
5
5
|
import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
|
|
6
6
|
import dragStyles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
7
7
|
import { DragButton } from './DragButton';
|
|
8
|
-
import { DualListSelectorListContext } from '@patternfly/react-core/dist/esm/components/DualListSelector';
|
|
8
|
+
import { DualListSelectorListContext } from '@patternfly/react-core/dist/esm/components/DualListSelector/DualListSelectorContext';
|
|
9
9
|
|
|
10
10
|
export interface DraggableDualListSelectorListItemProps extends React.HTMLProps<HTMLLIElement> {
|
|
11
11
|
/** Content rendered inside DragDrop */
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useDroppable } from '@dnd-kit/core';
|
|
3
|
+
import { DraggableObject } from './DragDropContainer';
|
|
4
|
+
import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
|
5
|
+
import { DraggableDualListSelectorListItem } from './DraggableDualListSelectorListItem';
|
|
6
|
+
import { DraggableDataListItem } from './DraggableDataListItem';
|
|
7
|
+
import { Draggable } from './Draggable';
|
|
8
|
+
|
|
9
|
+
interface DroppableProps extends React.HTMLProps<HTMLDivElement> {
|
|
10
|
+
/** ID of the drop zone */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Additional classes added to the div, or cloned element if wrapper is used */
|
|
13
|
+
className?: string;
|
|
14
|
+
/** Array of draggable objects */
|
|
15
|
+
items: DraggableObject[];
|
|
16
|
+
/** Alternative to wrapping drop zone in a div, will override any ref and style set on the element. */
|
|
17
|
+
wrapper?: React.ReactElement;
|
|
18
|
+
/** The variant determines which component wraps the draggable object.
|
|
19
|
+
* Default variant wraps the draggable object in a div.
|
|
20
|
+
* DataList vairant wraps the draggable object in a DataListItem
|
|
21
|
+
* DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
|
|
22
|
+
* TableComposable variant wraps the draggable objects in TODO
|
|
23
|
+
* */
|
|
24
|
+
variant?: 'default' | 'DataList' | 'DualListSelectorList' | 'TableComposable';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const Droppable: React.FunctionComponent<DroppableProps> = ({
|
|
28
|
+
items,
|
|
29
|
+
id = 'droppable',
|
|
30
|
+
variant = 'default',
|
|
31
|
+
wrapper,
|
|
32
|
+
...props
|
|
33
|
+
}: DroppableProps) => {
|
|
34
|
+
const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
|
|
35
|
+
const { setNodeRef } = useDroppable({ id: id ? id : 'droppable' });
|
|
36
|
+
|
|
37
|
+
const content = items.map((item: DraggableObject) => {
|
|
38
|
+
switch (variant) {
|
|
39
|
+
case 'DualListSelectorList':
|
|
40
|
+
return (
|
|
41
|
+
<DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
|
|
42
|
+
{item.content}
|
|
43
|
+
</DraggableDualListSelectorListItem>
|
|
44
|
+
);
|
|
45
|
+
case 'DataList':
|
|
46
|
+
return (
|
|
47
|
+
<DraggableDataListItem key={item.id} id={item.id} {...item.props}>
|
|
48
|
+
{item.content}
|
|
49
|
+
</DraggableDataListItem>
|
|
50
|
+
);
|
|
51
|
+
default:
|
|
52
|
+
return (
|
|
53
|
+
<Draggable useDragButton key={item.id} id={item.id} {...item.props}>
|
|
54
|
+
{item.content}
|
|
55
|
+
</Draggable>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<SortableContext items={itemIds} strategy={verticalListSortingStrategy} id={id}>
|
|
62
|
+
{wrapper &&
|
|
63
|
+
React.cloneElement(wrapper, {
|
|
64
|
+
children: content,
|
|
65
|
+
ref: setNodeRef,
|
|
66
|
+
...props
|
|
67
|
+
})}
|
|
68
|
+
{!wrapper && (
|
|
69
|
+
<div ref={setNodeRef} {...props}>
|
|
70
|
+
{content}
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
</SortableContext>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
Droppable.displayName = 'Droppable';
|
|
@@ -2,6 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { DragDropSort } from '../';
|
|
4
4
|
|
|
5
|
+
jest.mock('react-dom', () => ({
|
|
6
|
+
...jest.requireActual('react-dom'),
|
|
7
|
+
createPortal: jest.fn((node) => node)
|
|
8
|
+
}));
|
|
9
|
+
|
|
5
10
|
test('renders some divs', () => {
|
|
6
11
|
const { asFragment } = render(
|
|
7
12
|
<div className="pf-c-droppable pf-m-dragging">
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`renders some divs 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="pf-c-droppable pf-m-dragging"
|
|
7
|
+
>
|
|
8
|
+
<div>
|
|
9
|
+
<div
|
|
10
|
+
class=""
|
|
11
|
+
>
|
|
12
|
+
<button
|
|
13
|
+
aria-describedby="DndDescribedBy-0"
|
|
14
|
+
aria-disabled="false"
|
|
15
|
+
aria-label="Drag button"
|
|
16
|
+
aria-roledescription="sortable"
|
|
17
|
+
class="pf-v6-c-button pf-m-plain"
|
|
18
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-1"
|
|
19
|
+
data-ouia-component-type="PF6/Button"
|
|
20
|
+
data-ouia-safe="true"
|
|
21
|
+
role="button"
|
|
22
|
+
tabindex="0"
|
|
23
|
+
type="button"
|
|
24
|
+
>
|
|
25
|
+
<span
|
|
26
|
+
class="pf-v6-c-button__icon"
|
|
27
|
+
>
|
|
28
|
+
<span
|
|
29
|
+
class="pf-v6-c-data-list__item-draggable-icon"
|
|
30
|
+
>
|
|
31
|
+
<svg
|
|
32
|
+
aria-hidden="true"
|
|
33
|
+
class="pf-v6-svg"
|
|
34
|
+
fill="currentColor"
|
|
35
|
+
height="1em"
|
|
36
|
+
role="img"
|
|
37
|
+
viewBox="0 0 320 512"
|
|
38
|
+
width="1em"
|
|
39
|
+
>
|
|
40
|
+
<path
|
|
41
|
+
d="M96 32H32C14.33 32 0 46.33 0 64v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zM288 32h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32z"
|
|
42
|
+
/>
|
|
43
|
+
</svg>
|
|
44
|
+
</span>
|
|
45
|
+
</span>
|
|
46
|
+
</button>
|
|
47
|
+
one
|
|
48
|
+
</div>
|
|
49
|
+
<div
|
|
50
|
+
class=""
|
|
51
|
+
>
|
|
52
|
+
<button
|
|
53
|
+
aria-describedby="DndDescribedBy-0"
|
|
54
|
+
aria-disabled="false"
|
|
55
|
+
aria-label="Drag button"
|
|
56
|
+
aria-roledescription="sortable"
|
|
57
|
+
class="pf-v6-c-button pf-m-plain"
|
|
58
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-2"
|
|
59
|
+
data-ouia-component-type="PF6/Button"
|
|
60
|
+
data-ouia-safe="true"
|
|
61
|
+
role="button"
|
|
62
|
+
tabindex="0"
|
|
63
|
+
type="button"
|
|
64
|
+
>
|
|
65
|
+
<span
|
|
66
|
+
class="pf-v6-c-button__icon"
|
|
67
|
+
>
|
|
68
|
+
<span
|
|
69
|
+
class="pf-v6-c-data-list__item-draggable-icon"
|
|
70
|
+
>
|
|
71
|
+
<svg
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
class="pf-v6-svg"
|
|
74
|
+
fill="currentColor"
|
|
75
|
+
height="1em"
|
|
76
|
+
role="img"
|
|
77
|
+
viewBox="0 0 320 512"
|
|
78
|
+
width="1em"
|
|
79
|
+
>
|
|
80
|
+
<path
|
|
81
|
+
d="M96 32H32C14.33 32 0 46.33 0 64v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zM288 32h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32z"
|
|
82
|
+
/>
|
|
83
|
+
</svg>
|
|
84
|
+
</span>
|
|
85
|
+
</span>
|
|
86
|
+
</button>
|
|
87
|
+
two
|
|
88
|
+
</div>
|
|
89
|
+
<div
|
|
90
|
+
class=""
|
|
91
|
+
>
|
|
92
|
+
<button
|
|
93
|
+
aria-describedby="DndDescribedBy-0"
|
|
94
|
+
aria-disabled="false"
|
|
95
|
+
aria-label="Drag button"
|
|
96
|
+
aria-roledescription="sortable"
|
|
97
|
+
class="pf-v6-c-button pf-m-plain"
|
|
98
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-3"
|
|
99
|
+
data-ouia-component-type="PF6/Button"
|
|
100
|
+
data-ouia-safe="true"
|
|
101
|
+
role="button"
|
|
102
|
+
tabindex="0"
|
|
103
|
+
type="button"
|
|
104
|
+
>
|
|
105
|
+
<span
|
|
106
|
+
class="pf-v6-c-button__icon"
|
|
107
|
+
>
|
|
108
|
+
<span
|
|
109
|
+
class="pf-v6-c-data-list__item-draggable-icon"
|
|
110
|
+
>
|
|
111
|
+
<svg
|
|
112
|
+
aria-hidden="true"
|
|
113
|
+
class="pf-v6-svg"
|
|
114
|
+
fill="currentColor"
|
|
115
|
+
height="1em"
|
|
116
|
+
role="img"
|
|
117
|
+
viewBox="0 0 320 512"
|
|
118
|
+
width="1em"
|
|
119
|
+
>
|
|
120
|
+
<path
|
|
121
|
+
d="M96 32H32C14.33 32 0 46.33 0 64v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160H32c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zM288 32h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32V64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32zm0 160h-64c-17.67 0-32 14.33-32 32v64c0 17.67 14.33 32 32 32h64c17.67 0 32-14.33 32-32v-64c0-17.67-14.33-32-32-32z"
|
|
122
|
+
/>
|
|
123
|
+
</svg>
|
|
124
|
+
</span>
|
|
125
|
+
</span>
|
|
126
|
+
</button>
|
|
127
|
+
three
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
<div
|
|
131
|
+
id="DndDescribedBy-0"
|
|
132
|
+
style="display: none;"
|
|
133
|
+
>
|
|
134
|
+
|
|
135
|
+
To pick up a draggable item, press the space bar.
|
|
136
|
+
While dragging, use the arrow keys to move the item.
|
|
137
|
+
Press space again to drop the item in its new position, or press escape to cancel.
|
|
138
|
+
|
|
139
|
+
</div>
|
|
140
|
+
<div
|
|
141
|
+
aria-atomic="true"
|
|
142
|
+
aria-live="assertive"
|
|
143
|
+
id="DndLiveRegion-0"
|
|
144
|
+
role="status"
|
|
145
|
+
style="position: fixed; width: 1px; height: 1px; margin: -1px; border: 0px; padding: 0px; overflow: hidden; clip-path: inset(100%); white-space: nowrap;"
|
|
146
|
+
/>
|
|
147
|
+
</div>
|
|
148
|
+
</DocumentFragment>
|
|
149
|
+
`;
|
|
@@ -4,7 +4,6 @@ section: components
|
|
|
4
4
|
cssPrefix: pf-c-drag-drop
|
|
5
5
|
propComponents: ['DragDropSort', 'DraggableObject']
|
|
6
6
|
hideNavItem: true
|
|
7
|
-
beta: true
|
|
8
7
|
---
|
|
9
8
|
|
|
10
9
|
Note: This drag and drop implementation lives in its own package at [@patternfly/react-drag-drop](https://www.npmjs.com/package/@patternfly/react-drag-drop)!
|
|
@@ -15,7 +14,7 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
|
|
|
15
14
|
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
16
15
|
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
17
16
|
|
|
18
|
-
import { DragDropSort } from '@patternfly/react-drag-drop';
|
|
17
|
+
import { DragDropSort, DragDropContainer, Droppable as NewDroppable } from '@patternfly/react-drag-drop';
|
|
19
18
|
|
|
20
19
|
## Sorting examples
|
|
21
20
|
|
|
@@ -25,8 +24,8 @@ import { DragDropSort } from '@patternfly/react-drag-drop';
|
|
|
25
24
|
|
|
26
25
|
```
|
|
27
26
|
|
|
28
|
-
###
|
|
27
|
+
### Multiple drop zones
|
|
29
28
|
|
|
30
|
-
```ts file="./
|
|
29
|
+
```ts file="./DragDropContainerBasic.tsx"
|
|
31
30
|
|
|
32
31
|
```
|