@patternfly/react-drag-drop 5.0.0-alpha.0 → 5.2.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 +14 -0
- package/LICENSE +21 -0
- package/dist/cjs.tsbuildinfo +1 -1
- 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/next/components/DragDrop/DragButton.d.ts.map +1 -0
- package/dist/esm/{components → next/components}/DragDrop/DragButton.js +3 -2
- package/dist/esm/next/components/DragDrop/DragButton.js.map +1 -0
- package/dist/esm/{components → next/components}/DragDrop/DragDropSort.d.ts +12 -11
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +1 -0
- package/dist/esm/next/components/DragDrop/DragDropSort.js +70 -0
- package/dist/esm/next/components/DragDrop/DragDropSort.js.map +1 -0
- package/dist/esm/next/components/DragDrop/DragDropUtil.d.ts +10 -0
- package/dist/esm/next/components/DragDrop/DragDropUtil.d.ts.map +1 -0
- package/dist/esm/next/components/DragDrop/DragDropUtil.js +2 -0
- package/dist/esm/next/components/DragDrop/DragDropUtil.js.map +1 -0
- package/dist/{js → esm/next}/components/DragDrop/Draggable.d.ts +2 -4
- package/dist/esm/next/components/DragDrop/Draggable.d.ts.map +1 -0
- package/dist/esm/{components → next/components}/DragDrop/Draggable.js +4 -4
- package/dist/esm/next/components/DragDrop/Draggable.js.map +1 -0
- package/dist/{js → esm/next}/components/DragDrop/DraggableDataListItem.d.ts +1 -3
- package/dist/esm/next/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
- package/dist/esm/{components → next/components}/DragDrop/DraggableDataListItem.js +4 -3
- package/dist/esm/next/components/DragDrop/DraggableDataListItem.js.map +1 -0
- package/dist/esm/{components → next/components}/DragDrop/DraggableDualListSelectorListItem.d.ts +1 -5
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
- package/dist/esm/{components → next/components}/DragDrop/DraggableDualListSelectorListItem.js +7 -5
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
- package/dist/esm/next/components/DragDrop/Droppable.d.ts.map +1 -0
- package/dist/esm/next/components/DragDrop/Droppable.js.map +1 -0
- package/dist/esm/next/components/DragDrop/DroppableContext.d.ts.map +1 -0
- package/dist/esm/next/components/DragDrop/DroppableContext.js.map +1 -0
- package/dist/esm/next/components/DragDrop/index.d.ts +3 -0
- package/dist/esm/next/components/DragDrop/index.d.ts.map +1 -0
- package/dist/esm/next/components/DragDrop/index.js +3 -0
- package/dist/esm/next/components/DragDrop/index.js.map +1 -0
- package/dist/esm/next/components/index.d.ts.map +1 -0
- package/dist/esm/next/components/index.js.map +1 -0
- package/dist/esm/next/index.d.ts +2 -0
- package/dist/esm/next/index.d.ts.map +1 -0
- package/dist/esm/next/index.js +2 -0
- package/dist/esm/next/index.js.map +1 -0
- package/dist/esm.tsbuildinfo +1 -1
- 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/dist/js/next/components/DragDrop/DragButton.d.ts.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/DragButton.js +2 -1
- package/dist/js/next/components/DragDrop/DragButton.js.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/DragDropSort.d.ts +12 -11
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +1 -0
- package/dist/js/next/components/DragDrop/DragDropSort.js +74 -0
- package/dist/js/next/components/DragDrop/DragDropSort.js.map +1 -0
- package/dist/js/next/components/DragDrop/DragDropUtil.d.ts +10 -0
- package/dist/js/next/components/DragDrop/DragDropUtil.d.ts.map +1 -0
- package/dist/js/next/components/DragDrop/DragDropUtil.js +3 -0
- package/dist/js/next/components/DragDrop/DragDropUtil.js.map +1 -0
- package/dist/{esm → js/next}/components/DragDrop/Draggable.d.ts +2 -4
- package/dist/js/next/components/DragDrop/Draggable.d.ts.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/Draggable.js +3 -3
- package/dist/js/next/components/DragDrop/Draggable.js.map +1 -0
- package/dist/{esm → js/next}/components/DragDrop/DraggableDataListItem.d.ts +1 -3
- package/dist/js/next/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/DraggableDataListItem.js +3 -2
- package/dist/js/next/components/DragDrop/DraggableDataListItem.js.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/DraggableDualListSelectorListItem.d.ts +1 -5
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/DraggableDualListSelectorListItem.js +7 -5
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
- package/dist/js/next/components/DragDrop/Droppable.d.ts.map +1 -0
- package/dist/js/next/components/DragDrop/Droppable.js.map +1 -0
- package/dist/js/next/components/DragDrop/DroppableContext.d.ts.map +1 -0
- package/dist/js/next/components/DragDrop/DroppableContext.js.map +1 -0
- package/dist/js/next/components/DragDrop/index.d.ts +3 -0
- package/dist/js/next/components/DragDrop/index.d.ts.map +1 -0
- package/dist/js/{components → next/components}/DragDrop/index.js +1 -0
- package/dist/js/next/components/DragDrop/index.js.map +1 -0
- package/dist/js/next/components/index.d.ts.map +1 -0
- package/dist/js/next/components/index.js.map +1 -0
- package/dist/js/next/index.d.ts +2 -0
- package/dist/js/next/index.d.ts.map +1 -0
- package/dist/js/next/index.js +5 -0
- package/dist/js/next/index.js.map +1 -0
- package/package.json +10 -10
- package/src/index.ts +1 -1
- package/src/{components → next/components}/DragDrop/DragButton.tsx +6 -1
- package/src/next/components/DragDrop/DragDropSort.tsx +174 -0
- package/src/next/components/DragDrop/DragDropUtil.tsx +8 -0
- package/src/{components → next/components}/DragDrop/Draggable.tsx +10 -7
- package/src/{components → next/components}/DragDrop/DraggableDataListItem.tsx +15 -5
- package/src/{components → next/components}/DragDrop/DraggableDualListSelectorListItem.tsx +14 -11
- package/src/{components → next/components}/DragDrop/__tests__/DragDrop.test.tsx +1 -1
- package/src/{components → next/components}/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +31 -29
- package/src/next/components/DragDrop/examples/BasicSorting.tsx +19 -0
- package/src/next/components/DragDrop/examples/BasicSortingWithDragButton.tsx +20 -0
- package/src/{components → next/components}/DragDrop/examples/DataListDraggable.tsx +11 -19
- package/src/next/components/DragDrop/examples/DragDrop.md +32 -0
- package/src/next/components/DragDrop/examples/DragDropDemos.md +37 -0
- package/src/{components → next/components}/DragDrop/examples/DualListSelectorDraggable.tsx +52 -72
- package/src/{components → next/components}/DragDrop/index.ts +1 -0
- package/src/next/index.ts +1 -0
- package/dist/esm/components/DragDrop/DragButton.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/DragButton.js.map +0 -1
- package/dist/esm/components/DragDrop/DragDropSort.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/DragDropSort.js +0 -45
- package/dist/esm/components/DragDrop/DragDropSort.js.map +0 -1
- package/dist/esm/components/DragDrop/Draggable.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/Draggable.js.map +0 -1
- package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/DraggableDataListItem.js.map +0 -1
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js.map +0 -1
- package/dist/esm/components/DragDrop/Droppable.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/Droppable.js.map +0 -1
- package/dist/esm/components/DragDrop/DroppableContext.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/DroppableContext.js.map +0 -1
- package/dist/esm/components/DragDrop/index.d.ts +0 -2
- package/dist/esm/components/DragDrop/index.d.ts.map +0 -1
- package/dist/esm/components/DragDrop/index.js +0 -2
- package/dist/esm/components/DragDrop/index.js.map +0 -1
- package/dist/esm/components/index.d.ts.map +0 -1
- package/dist/esm/components/index.js.map +0 -1
- package/dist/js/components/DragDrop/DragButton.d.ts.map +0 -1
- package/dist/js/components/DragDrop/DragButton.js.map +0 -1
- package/dist/js/components/DragDrop/DragDropSort.d.ts.map +0 -1
- package/dist/js/components/DragDrop/DragDropSort.js +0 -50
- package/dist/js/components/DragDrop/DragDropSort.js.map +0 -1
- package/dist/js/components/DragDrop/Draggable.d.ts.map +0 -1
- package/dist/js/components/DragDrop/Draggable.js.map +0 -1
- package/dist/js/components/DragDrop/DraggableDataListItem.d.ts.map +0 -1
- package/dist/js/components/DragDrop/DraggableDataListItem.js.map +0 -1
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +0 -1
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js.map +0 -1
- package/dist/js/components/DragDrop/Droppable.d.ts.map +0 -1
- package/dist/js/components/DragDrop/Droppable.js.map +0 -1
- package/dist/js/components/DragDrop/DroppableContext.d.ts.map +0 -1
- package/dist/js/components/DragDrop/DroppableContext.js.map +0 -1
- package/dist/js/components/DragDrop/index.d.ts +0 -2
- package/dist/js/components/DragDrop/index.d.ts.map +0 -1
- package/dist/js/components/DragDrop/index.js.map +0 -1
- package/dist/js/components/index.d.ts.map +0 -1
- package/dist/js/components/index.js.map +0 -1
- package/src/components/DragDrop/DragDropSort.tsx +0 -123
- package/src/components/DragDrop/examples/BasicSorting.tsx +0 -24
- package/src/components/DragDrop/examples/BasicSortingWithDragButton.tsx +0 -25
- package/src/components/DragDrop/examples/DragDrop.md +0 -57
- /package/dist/esm/{components → next/components}/DragDrop/DragButton.d.ts +0 -0
- /package/dist/esm/{components → next/components}/DragDrop/Droppable.d.ts +0 -0
- /package/dist/esm/{components → next/components}/DragDrop/Droppable.js +0 -0
- /package/dist/esm/{components → next/components}/DragDrop/DroppableContext.d.ts +0 -0
- /package/dist/esm/{components → next/components}/DragDrop/DroppableContext.js +0 -0
- /package/dist/esm/{components → next/components}/index.d.ts +0 -0
- /package/dist/esm/{components → next/components}/index.js +0 -0
- /package/dist/js/{components → next/components}/DragDrop/DragButton.d.ts +0 -0
- /package/dist/js/{components → next/components}/DragDrop/Droppable.d.ts +0 -0
- /package/dist/js/{components → next/components}/DragDrop/Droppable.js +0 -0
- /package/dist/js/{components → next/components}/DragDrop/DroppableContext.d.ts +0 -0
- /package/dist/js/{components → next/components}/DragDrop/DroppableContext.js +0 -0
- /package/dist/js/{components → next/components}/index.d.ts +0 -0
- /package/dist/js/{components → next/components}/index.js +0 -0
- /package/src/{components → next/components}/DragDrop/Droppable.tsx +0 -0
- /package/src/{components → next/components}/DragDrop/DroppableContext.ts +0 -0
- /package/src/{components → next/components}/index.ts +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { css } from '@patternfly/react-styles';
|
|
3
|
+
import {
|
|
4
|
+
DndContext,
|
|
5
|
+
closestCenter,
|
|
6
|
+
DragOverlay,
|
|
7
|
+
DndContextProps,
|
|
8
|
+
KeyboardSensor,
|
|
9
|
+
PointerSensor,
|
|
10
|
+
useSensor,
|
|
11
|
+
useSensors,
|
|
12
|
+
DragEndEvent,
|
|
13
|
+
DragStartEvent
|
|
14
|
+
} from '@dnd-kit/core';
|
|
15
|
+
import {
|
|
16
|
+
arrayMove,
|
|
17
|
+
SortableContext,
|
|
18
|
+
sortableKeyboardCoordinates,
|
|
19
|
+
verticalListSortingStrategy
|
|
20
|
+
} from '@dnd-kit/sortable';
|
|
21
|
+
import { Draggable } from './Draggable';
|
|
22
|
+
import { DraggableDataListItem } from './DraggableDataListItem';
|
|
23
|
+
import { DraggableDualListSelectorListItem } from './DraggableDualListSelectorListItem';
|
|
24
|
+
import { DraggableObject } from './DragDropUtil';
|
|
25
|
+
import styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
26
|
+
|
|
27
|
+
export type DragDropSortDragEndEvent = DragEndEvent;
|
|
28
|
+
export type DragDropSortDragStartEvent = DragStartEvent;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* DragDropSortProps extends dnd-kit's props which may be viewed at https://docs.dndkit.com/api-documentation/context-provider#props.
|
|
32
|
+
*/
|
|
33
|
+
export interface DragDropSortProps extends DndContextProps {
|
|
34
|
+
/** Custom defined content wrapper for draggable items. By default, draggable items are wrapped in a styled div.
|
|
35
|
+
* Intended to be a 'DataList' or 'DualListSelectorList' without children. */
|
|
36
|
+
children?: React.ReactElement;
|
|
37
|
+
/** Sorted array of draggable objects */
|
|
38
|
+
items: DraggableObject[];
|
|
39
|
+
/** Callback when user drops a draggable object */
|
|
40
|
+
onDrop: (event: DragDropSortDragEndEvent, items: DraggableObject[], oldIndex?: number, newIndex?: number) => void;
|
|
41
|
+
/** Callback when use begins dragging a draggable object */
|
|
42
|
+
onDrag?: (event: DragDropSortDragStartEvent, oldIndex: number) => void;
|
|
43
|
+
/** The variant determines which component wraps the draggable object.
|
|
44
|
+
* Default and defaultWithHandle varaints wrap the draggable object in a div.
|
|
45
|
+
* DataList vairant wraps the draggable object in a DataListItem
|
|
46
|
+
* DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
|
|
47
|
+
* TableComposable variant wraps the draggable objects in TODO
|
|
48
|
+
* */
|
|
49
|
+
variant?: 'default' | 'defaultWithHandle' | 'DataList' | 'DualListSelectorList' | 'TableComposable';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
|
|
53
|
+
items,
|
|
54
|
+
onDrop = () => {},
|
|
55
|
+
onDrag = () => {},
|
|
56
|
+
variant = 'default',
|
|
57
|
+
children,
|
|
58
|
+
...props
|
|
59
|
+
}: DragDropSortProps) => {
|
|
60
|
+
const [activeId, setActiveId] = React.useState<string>(null);
|
|
61
|
+
const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
|
|
62
|
+
|
|
63
|
+
const getItemById = (id: string): DraggableObject => items.find((item) => item.id === id);
|
|
64
|
+
|
|
65
|
+
const sensors = useSensors(
|
|
66
|
+
useSensor(PointerSensor),
|
|
67
|
+
useSensor(KeyboardSensor, {
|
|
68
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const handleDragEnd = (event: DragEndEvent) => {
|
|
73
|
+
const { active, over } = event;
|
|
74
|
+
const oldIndex = itemIds.indexOf(active.id as string);
|
|
75
|
+
const newIndex = itemIds.indexOf(over.id as string);
|
|
76
|
+
const newItems = arrayMove(items, oldIndex, newIndex);
|
|
77
|
+
onDrop(event, newItems, oldIndex, newIndex);
|
|
78
|
+
setActiveId(null);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleDragStart = (event: DragStartEvent) => {
|
|
82
|
+
setActiveId(event.active.id as string);
|
|
83
|
+
onDrag(event, itemIds.indexOf(event.active.id as string));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const getDragOverlay = () => {
|
|
87
|
+
if (!activeId) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const item = getItemById(activeId);
|
|
91
|
+
|
|
92
|
+
let content;
|
|
93
|
+
switch (variant) {
|
|
94
|
+
case 'DualListSelectorList':
|
|
95
|
+
content = (
|
|
96
|
+
<DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
|
|
97
|
+
{item.content}
|
|
98
|
+
</DraggableDualListSelectorListItem>
|
|
99
|
+
);
|
|
100
|
+
break;
|
|
101
|
+
case 'DataList':
|
|
102
|
+
content = (
|
|
103
|
+
<DraggableDataListItem key={item.id} id={item.id} {...item.props}>
|
|
104
|
+
{item.content}
|
|
105
|
+
</DraggableDataListItem>
|
|
106
|
+
);
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
content = (
|
|
110
|
+
<Draggable useDragButton={variant === 'defaultWithHandle'} key={item.id} id={item.id} {...item.props}>
|
|
111
|
+
{item.content}
|
|
112
|
+
</Draggable>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div
|
|
118
|
+
className={css(styles.draggable, styles.modifiers.dragging)}
|
|
119
|
+
style={
|
|
120
|
+
{
|
|
121
|
+
'--pf-v5-c-draggable--m-dragging--BackgroundColor': 'var(--pf-v5-global--BackgroundColor--100)'
|
|
122
|
+
} as React.CSSProperties
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
{content}
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const renderedChildren = (
|
|
131
|
+
<SortableContext items={itemIds} strategy={verticalListSortingStrategy} id="droppable">
|
|
132
|
+
{items.map((item: DraggableObject) => {
|
|
133
|
+
switch (variant) {
|
|
134
|
+
case 'DualListSelectorList':
|
|
135
|
+
return (
|
|
136
|
+
<DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
|
|
137
|
+
{item.content}
|
|
138
|
+
</DraggableDualListSelectorListItem>
|
|
139
|
+
);
|
|
140
|
+
case 'DataList':
|
|
141
|
+
return (
|
|
142
|
+
<DraggableDataListItem key={item.id} id={item.id} {...item.props}>
|
|
143
|
+
{item.content}
|
|
144
|
+
</DraggableDataListItem>
|
|
145
|
+
);
|
|
146
|
+
default:
|
|
147
|
+
return (
|
|
148
|
+
<Draggable useDragButton={variant === 'defaultWithHandle'} key={item.id} id={item.id} {...item.props}>
|
|
149
|
+
{item.content}
|
|
150
|
+
</Draggable>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
})}
|
|
154
|
+
<DragOverlay>{activeId && getDragOverlay()}</DragOverlay>
|
|
155
|
+
</SortableContext>
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<DndContext
|
|
160
|
+
sensors={sensors}
|
|
161
|
+
collisionDetection={closestCenter}
|
|
162
|
+
onDragEnd={handleDragEnd}
|
|
163
|
+
onDragStart={handleDragStart}
|
|
164
|
+
{...props}
|
|
165
|
+
>
|
|
166
|
+
{children &&
|
|
167
|
+
React.cloneElement(children, {
|
|
168
|
+
children: renderedChildren
|
|
169
|
+
})}
|
|
170
|
+
{!children && <div>{renderedChildren}</div>}
|
|
171
|
+
</DndContext>
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
DragDropSort.displayName = 'DragDropSort';
|
|
@@ -8,13 +8,11 @@ import { DragButton } from './DragButton';
|
|
|
8
8
|
export interface DraggableProps extends React.HTMLProps<HTMLDivElement> {
|
|
9
9
|
/** Content rendered inside DragDrop */
|
|
10
10
|
children?: React.ReactNode;
|
|
11
|
-
/** Don't wrap the component in a div. Requires passing a single child. */
|
|
12
|
-
hasNoWrapper?: boolean;
|
|
13
11
|
/** Class to add to outer div */
|
|
14
12
|
className?: string;
|
|
15
|
-
/** */
|
|
13
|
+
/** @hide Id of the sortable context. */
|
|
16
14
|
id?: string;
|
|
17
|
-
/** */
|
|
15
|
+
/** Flag indicating the draggable element should include a drag button. */
|
|
18
16
|
useDragButton?: boolean;
|
|
19
17
|
}
|
|
20
18
|
|
|
@@ -25,7 +23,7 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
25
23
|
useDragButton = false,
|
|
26
24
|
...props
|
|
27
25
|
}: DraggableProps) => {
|
|
28
|
-
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
26
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
29
27
|
id
|
|
30
28
|
});
|
|
31
29
|
|
|
@@ -35,13 +33,18 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
|
|
|
35
33
|
};
|
|
36
34
|
|
|
37
35
|
return useDragButton ? (
|
|
38
|
-
<div
|
|
36
|
+
<div
|
|
37
|
+
className={css(isDragging && styles.droppable, isDragging && styles.modifiers.dragging, className)}
|
|
38
|
+
ref={setNodeRef}
|
|
39
|
+
style={style}
|
|
40
|
+
{...props}
|
|
41
|
+
>
|
|
39
42
|
<DragButton {...attributes} {...listeners} />
|
|
40
43
|
{children}
|
|
41
44
|
</div>
|
|
42
45
|
) : (
|
|
43
46
|
<div
|
|
44
|
-
className={css(styles.
|
|
47
|
+
className={css(isDragging && styles.droppable, isDragging && styles.modifiers.dragging, className)}
|
|
45
48
|
ref={setNodeRef}
|
|
46
49
|
style={style}
|
|
47
50
|
{...listeners}
|
|
@@ -3,6 +3,7 @@ import { useSortable } from '@dnd-kit/sortable';
|
|
|
3
3
|
import { CSS } from '@dnd-kit/utilities';
|
|
4
4
|
import { css } from '@patternfly/react-styles';
|
|
5
5
|
import styles from '@patternfly/react-styles/css/components/DataList/data-list';
|
|
6
|
+
import dragStyles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
6
7
|
import { DragButton } from './DragButton';
|
|
7
8
|
import { DataListItemRow, DataListControl } from '@patternfly/react-core';
|
|
8
9
|
|
|
@@ -14,11 +15,9 @@ export interface DraggableDataListItemObject {
|
|
|
14
15
|
export interface DraggableDataListItemProps extends React.HTMLProps<HTMLLIElement> {
|
|
15
16
|
/** Content rendered inside DragDrop */
|
|
16
17
|
children?: React.ReactNode;
|
|
17
|
-
/** Don't wrap the component in a div. Requires passing a single child. */
|
|
18
|
-
hasNoWrapper?: boolean;
|
|
19
18
|
/** Class to add to outer div */
|
|
20
19
|
className?: string;
|
|
21
|
-
/** */
|
|
20
|
+
/** @hide Id of the sortable context. */
|
|
22
21
|
id?: string;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -28,7 +27,7 @@ export const DraggableDataListItem: React.FunctionComponent<DraggableDataListIte
|
|
|
28
27
|
className,
|
|
29
28
|
...props
|
|
30
29
|
}: DraggableDataListItemProps) => {
|
|
31
|
-
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
30
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
32
31
|
id
|
|
33
32
|
});
|
|
34
33
|
|
|
@@ -38,7 +37,18 @@ export const DraggableDataListItem: React.FunctionComponent<DraggableDataListIte
|
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
return (
|
|
41
|
-
<li
|
|
40
|
+
<li
|
|
41
|
+
id={id}
|
|
42
|
+
className={css(
|
|
43
|
+
styles.dataListItem,
|
|
44
|
+
isDragging && dragStyles.droppable,
|
|
45
|
+
isDragging && dragStyles.modifiers.dragging,
|
|
46
|
+
className
|
|
47
|
+
)}
|
|
48
|
+
{...props}
|
|
49
|
+
ref={setNodeRef}
|
|
50
|
+
style={style}
|
|
51
|
+
>
|
|
42
52
|
<DataListItemRow>
|
|
43
53
|
<DataListControl>
|
|
44
54
|
<DragButton className={css(styles.dataListItemDraggableButton)} {...attributes} {...listeners} />
|
|
@@ -3,13 +3,9 @@ import { useSortable } from '@dnd-kit/sortable';
|
|
|
3
3
|
import { CSS } from '@dnd-kit/utilities';
|
|
4
4
|
import { css } from '@patternfly/react-styles';
|
|
5
5
|
import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
|
|
6
|
+
import dragStyles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
6
7
|
import { DragButton } from './DragButton';
|
|
7
|
-
import { DualListSelectorListContext } from '@patternfly/react-core';
|
|
8
|
-
|
|
9
|
-
export interface DraggableObject {
|
|
10
|
-
id?: string;
|
|
11
|
-
content?: React.ReactNode;
|
|
12
|
-
}
|
|
8
|
+
import { DualListSelectorListContext } from '@patternfly/react-core/dist/esm/components/DualListSelector';
|
|
13
9
|
|
|
14
10
|
export interface DraggableDualListSelectorListItemProps extends React.HTMLProps<HTMLLIElement> {
|
|
15
11
|
/** Content rendered inside DragDrop */
|
|
@@ -18,7 +14,7 @@ export interface DraggableDualListSelectorListItemProps extends React.HTMLProps<
|
|
|
18
14
|
hasNoWrapper?: boolean;
|
|
19
15
|
/** Class to add to outer div */
|
|
20
16
|
className?: string;
|
|
21
|
-
/** */
|
|
17
|
+
/** @hide Id of the sortable context */
|
|
22
18
|
id?: string;
|
|
23
19
|
/** Flag indicating the list item is currently selected. */
|
|
24
20
|
isSelected?: boolean;
|
|
@@ -41,8 +37,9 @@ export const DraggableDualListSelectorListItem: React.FunctionComponent<Draggabl
|
|
|
41
37
|
onOptionSelect,
|
|
42
38
|
...props
|
|
43
39
|
}: DraggableDualListSelectorListItemProps) => {
|
|
44
|
-
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
45
|
-
id
|
|
40
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
41
|
+
id,
|
|
42
|
+
animateLayoutChanges: () => false
|
|
46
43
|
});
|
|
47
44
|
|
|
48
45
|
const { setFocusedOption } = React.useContext(DualListSelectorListContext);
|
|
@@ -54,12 +51,18 @@ export const DraggableDualListSelectorListItem: React.FunctionComponent<Draggabl
|
|
|
54
51
|
|
|
55
52
|
return (
|
|
56
53
|
<li
|
|
57
|
-
className={css(
|
|
54
|
+
className={css(
|
|
55
|
+
styles.dualListSelectorListItem,
|
|
56
|
+
isDragging && dragStyles.droppable,
|
|
57
|
+
isDragging && dragStyles.modifiers.dragging,
|
|
58
|
+
className
|
|
59
|
+
)}
|
|
58
60
|
key={orderIndex}
|
|
59
61
|
id={id}
|
|
62
|
+
role="presentation"
|
|
63
|
+
{...props}
|
|
60
64
|
ref={setNodeRef}
|
|
61
65
|
style={style}
|
|
62
|
-
{...props}
|
|
63
66
|
>
|
|
64
67
|
<div className={css(styles.dualListSelectorListItemRow, isSelected && styles.modifiers.selected)}>
|
|
65
68
|
<DragButton className={css(styles.dualListSelectorDraggable)} {...attributes} {...listeners} />
|
package/src/{components → next/components}/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap
RENAMED
|
@@ -5,35 +5,37 @@ exports[`renders some divs 1`] = `
|
|
|
5
5
|
<div
|
|
6
6
|
class="pf-c-droppable pf-m-dragging"
|
|
7
7
|
>
|
|
8
|
-
<div
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
8
|
+
<div>
|
|
9
|
+
<div
|
|
10
|
+
aria-describedby="DndDescribedBy-0"
|
|
11
|
+
aria-disabled="false"
|
|
12
|
+
aria-roledescription="sortable"
|
|
13
|
+
class=""
|
|
14
|
+
role="button"
|
|
15
|
+
tabindex="0"
|
|
16
|
+
>
|
|
17
|
+
one
|
|
18
|
+
</div>
|
|
19
|
+
<div
|
|
20
|
+
aria-describedby="DndDescribedBy-0"
|
|
21
|
+
aria-disabled="false"
|
|
22
|
+
aria-roledescription="sortable"
|
|
23
|
+
class=""
|
|
24
|
+
role="button"
|
|
25
|
+
tabindex="0"
|
|
26
|
+
>
|
|
27
|
+
two
|
|
28
|
+
</div>
|
|
29
|
+
<div
|
|
30
|
+
aria-describedby="DndDescribedBy-0"
|
|
31
|
+
aria-disabled="false"
|
|
32
|
+
aria-roledescription="sortable"
|
|
33
|
+
class=""
|
|
34
|
+
role="button"
|
|
35
|
+
tabindex="0"
|
|
36
|
+
>
|
|
37
|
+
three
|
|
38
|
+
</div>
|
|
37
39
|
</div>
|
|
38
40
|
<div
|
|
39
41
|
id="DndDescribedBy-0"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
3
|
+
|
|
4
|
+
export const BasicSorting: React.FunctionComponent = () => {
|
|
5
|
+
const [items, setItems] = React.useState<DraggableObject[]>([
|
|
6
|
+
{ id: 'basic-1', content: 'one' },
|
|
7
|
+
{ id: 'basic-2', content: 'two' },
|
|
8
|
+
{ id: 'basic-3', content: 'three' }
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<DragDropSort
|
|
13
|
+
items={items}
|
|
14
|
+
onDrop={(_, newItems) => {
|
|
15
|
+
setItems(newItems);
|
|
16
|
+
}}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
3
|
+
|
|
4
|
+
export const BasicSortingWithDragButton: React.FunctionComponent = () => {
|
|
5
|
+
const [items, setItems] = React.useState<DraggableObject[]>([
|
|
6
|
+
{ id: 'with-button-1', content: 'one' },
|
|
7
|
+
{ id: 'with-button-2', content: 'two' },
|
|
8
|
+
{ id: 'with-button-3', content: 'three' }
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<DragDropSort
|
|
13
|
+
items={items}
|
|
14
|
+
variant="defaultWithHandle"
|
|
15
|
+
onDrop={(_, newItems) => {
|
|
16
|
+
setItems(newItems);
|
|
17
|
+
}}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -3,8 +3,8 @@ import { DataList, DataListCell, DataListCheck, DataListControl, DataListItemCel
|
|
|
3
3
|
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
4
4
|
|
|
5
5
|
const getItems = (count: number): DraggableObject[] =>
|
|
6
|
-
Array.from({ length: count }, (_, idx) => idx).map(idx => ({
|
|
7
|
-
id: `item-${idx}`,
|
|
6
|
+
Array.from({ length: count }, (_, idx) => idx).map((idx) => ({
|
|
7
|
+
id: `data-list-item-${idx}`,
|
|
8
8
|
content: (
|
|
9
9
|
<>
|
|
10
10
|
<DataListControl>
|
|
@@ -21,26 +21,18 @@ const getItems = (count: number): DraggableObject[] =>
|
|
|
21
21
|
)
|
|
22
22
|
}));
|
|
23
23
|
|
|
24
|
-
export const DataListDraggable: React.FunctionComponent = props => {
|
|
24
|
+
export const DataListDraggable: React.FunctionComponent = (props) => {
|
|
25
25
|
const [items, setItems] = React.useState<DraggableObject[]>(getItems(10));
|
|
26
|
-
const [dragging, setDragging] = React.useState(false);
|
|
27
26
|
|
|
28
27
|
return (
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
<DragDropSort
|
|
29
|
+
items={items}
|
|
30
|
+
onDrop={(_, newItems) => {
|
|
31
|
+
setItems(newItems);
|
|
32
|
+
}}
|
|
33
|
+
variant="DataList"
|
|
34
34
|
>
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
onDrop={newItems => {
|
|
38
|
-
setItems(newItems);
|
|
39
|
-
setDragging(false);
|
|
40
|
-
}}
|
|
41
|
-
onDrag={() => setDragging(true)}
|
|
42
|
-
variant="DataList"
|
|
43
|
-
/>
|
|
44
|
-
</DataList>
|
|
35
|
+
<DataList aria-label="draggable data list example" isCompact {...props} />
|
|
36
|
+
</DragDropSort>
|
|
45
37
|
);
|
|
46
38
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Drag and drop
|
|
3
|
+
section: components
|
|
4
|
+
cssPrefix: pf-c-drag-drop
|
|
5
|
+
propComponents: ['DragDropSort', 'DraggableObject']
|
|
6
|
+
hideNavItem: true
|
|
7
|
+
beta: true
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
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)!
|
|
11
|
+
|
|
12
|
+
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
13
|
+
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
14
|
+
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
15
|
+
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
16
|
+
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
17
|
+
|
|
18
|
+
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
19
|
+
|
|
20
|
+
## Sorting examples
|
|
21
|
+
|
|
22
|
+
### Basic drag and drop sorting
|
|
23
|
+
|
|
24
|
+
```ts file="./BasicSorting.tsx"
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Basic drag and drop sorting with drag button
|
|
29
|
+
|
|
30
|
+
```ts file="./BasicSortingWithDragButton.tsx"
|
|
31
|
+
|
|
32
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Drag and drop
|
|
3
|
+
section: components
|
|
4
|
+
source: react-next-demos
|
|
5
|
+
propComponents: ['DragDropSort', 'DraggableObject']
|
|
6
|
+
beta: true
|
|
7
|
+
---
|
|
8
|
+
|
|
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)!
|
|
10
|
+
|
|
11
|
+
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
12
|
+
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
13
|
+
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
14
|
+
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
15
|
+
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
16
|
+
|
|
17
|
+
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
18
|
+
|
|
19
|
+
## Sorting demos
|
|
20
|
+
|
|
21
|
+
To enable drag and drop for compatible components, wrap the component with `<DragDropSort>`, define the `variant` property, and pass both the sortable `items` and `onDrop` callback to `<DragDropSort>`. `<DragDropSort>` will create the component's usual `children` internally based on the `items` property, so `children` should not be passed to the wrapped component.
|
|
22
|
+
|
|
23
|
+
### Drag and drop sortable data list
|
|
24
|
+
|
|
25
|
+
To enable reordering in a `<DataList>`, wrap the `<DataList>` component with `<DragDropSort>` and define the `variant` as "DataList".
|
|
26
|
+
|
|
27
|
+
```ts file="./DataListDraggable.tsx"
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Drag and drop sortable dual list selector
|
|
32
|
+
|
|
33
|
+
To enable reordering in a `<DualListSelector>` pane wrap the `<DualListSelectorList>` component with `<DragDropSort>` and define the `variant` as "DualListSelectorList".
|
|
34
|
+
|
|
35
|
+
```ts file="./DualListSelectorDraggable.tsx"
|
|
36
|
+
|
|
37
|
+
```
|