@patternfly/react-drag-drop 6.0.0-alpha.5 → 6.0.0-alpha.51

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +434 -0
  2. package/dist/cjs.tsbuildinfo +1 -1
  3. package/dist/esm/components/DragDrop/DragButton.d.ts +11 -0
  4. package/dist/esm/components/DragDrop/DragButton.d.ts.map +1 -0
  5. package/dist/esm/components/DragDrop/DragButton.js +14 -0
  6. package/dist/esm/components/DragDrop/DragButton.js.map +1 -0
  7. package/dist/esm/components/DragDrop/DragDropSort.d.ts +35 -0
  8. package/dist/esm/components/DragDrop/DragDropSort.d.ts.map +1 -0
  9. package/dist/esm/components/DragDrop/DragDropSort.js +70 -0
  10. package/dist/esm/components/DragDrop/DragDropSort.js.map +1 -0
  11. package/dist/esm/components/DragDrop/Draggable.d.ts +13 -0
  12. package/dist/esm/components/DragDrop/Draggable.d.ts.map +1 -0
  13. package/dist/esm/components/DragDrop/Draggable.js +22 -0
  14. package/dist/esm/components/DragDrop/Draggable.js.map +1 -0
  15. package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts +15 -0
  16. package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
  17. package/dist/esm/components/DragDrop/DraggableDataListItem.js +26 -0
  18. package/dist/esm/components/DragDrop/DraggableDataListItem.js.map +1 -0
  19. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts +23 -0
  20. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
  21. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js +37 -0
  22. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
  23. package/dist/esm/components/DragDrop/Droppable.d.ts +16 -0
  24. package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -0
  25. package/dist/esm/components/DragDrop/Droppable.js +11 -0
  26. package/dist/esm/components/DragDrop/Droppable.js.map +1 -0
  27. package/dist/esm/components/DragDrop/DroppableContext.d.ts +6 -0
  28. package/dist/esm/components/DragDrop/DroppableContext.d.ts.map +1 -0
  29. package/dist/esm/components/DragDrop/DroppableContext.js +6 -0
  30. package/dist/esm/components/DragDrop/DroppableContext.js.map +1 -0
  31. package/dist/esm/components/DragDrop/index.d.ts +2 -0
  32. package/dist/esm/components/DragDrop/index.d.ts.map +1 -0
  33. package/dist/esm/components/DragDrop/index.js +2 -0
  34. package/dist/esm/components/DragDrop/index.js.map +1 -0
  35. package/dist/esm/components/index.d.ts +2 -0
  36. package/dist/esm/components/index.d.ts.map +1 -0
  37. package/dist/esm/components/index.js +2 -0
  38. package/dist/esm/components/index.js.map +1 -0
  39. package/dist/esm/index.d.ts +1 -1
  40. package/dist/esm/index.d.ts.map +1 -1
  41. package/dist/esm/index.js +1 -1
  42. package/dist/esm/index.js.map +1 -1
  43. package/dist/esm/next/components/DragDrop/DragDropSort.d.ts +2 -2
  44. package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
  45. package/dist/esm/next/components/DragDrop/DragDropSort.js +4 -1
  46. package/dist/esm/next/components/DragDrop/DragDropSort.js.map +1 -1
  47. package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
  48. package/dist/esm.tsbuildinfo +1 -1
  49. package/dist/js/components/DragDrop/DragButton.d.ts +11 -0
  50. package/dist/js/components/DragDrop/DragButton.d.ts.map +1 -0
  51. package/dist/js/components/DragDrop/DragButton.js +18 -0
  52. package/dist/js/components/DragDrop/DragButton.js.map +1 -0
  53. package/dist/js/components/DragDrop/DragDropSort.d.ts +35 -0
  54. package/dist/js/components/DragDrop/DragDropSort.d.ts.map +1 -0
  55. package/dist/js/components/DragDrop/DragDropSort.js +74 -0
  56. package/dist/js/components/DragDrop/DragDropSort.js.map +1 -0
  57. package/dist/js/components/DragDrop/Draggable.d.ts +13 -0
  58. package/dist/js/components/DragDrop/Draggable.d.ts.map +1 -0
  59. package/dist/js/components/DragDrop/Draggable.js +26 -0
  60. package/dist/js/components/DragDrop/Draggable.js.map +1 -0
  61. package/dist/js/components/DragDrop/DraggableDataListItem.d.ts +15 -0
  62. package/dist/js/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
  63. package/dist/js/components/DragDrop/DraggableDataListItem.js +30 -0
  64. package/dist/js/components/DragDrop/DraggableDataListItem.js.map +1 -0
  65. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts +23 -0
  66. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
  67. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js +41 -0
  68. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
  69. package/dist/js/components/DragDrop/Droppable.d.ts +16 -0
  70. package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -0
  71. package/dist/js/components/DragDrop/Droppable.js +15 -0
  72. package/dist/js/components/DragDrop/Droppable.js.map +1 -0
  73. package/dist/js/components/DragDrop/DroppableContext.d.ts +6 -0
  74. package/dist/js/components/DragDrop/DroppableContext.d.ts.map +1 -0
  75. package/dist/js/components/DragDrop/DroppableContext.js +10 -0
  76. package/dist/js/components/DragDrop/DroppableContext.js.map +1 -0
  77. package/dist/js/components/DragDrop/index.d.ts +2 -0
  78. package/dist/js/components/DragDrop/index.d.ts.map +1 -0
  79. package/dist/js/components/DragDrop/index.js +5 -0
  80. package/dist/js/components/DragDrop/index.js.map +1 -0
  81. package/dist/js/components/index.d.ts +2 -0
  82. package/dist/js/components/index.d.ts.map +1 -0
  83. package/dist/js/components/index.js +5 -0
  84. package/dist/js/components/index.js.map +1 -0
  85. package/dist/js/index.d.ts +1 -1
  86. package/dist/js/index.d.ts.map +1 -1
  87. package/dist/js/index.js +1 -1
  88. package/dist/js/index.js.map +1 -1
  89. package/dist/js/next/components/DragDrop/DragButton.js.map +1 -1
  90. package/dist/js/next/components/DragDrop/DragDropSort.d.ts +2 -2
  91. package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
  92. package/dist/js/next/components/DragDrop/DragDropSort.js +4 -1
  93. package/dist/js/next/components/DragDrop/DragDropSort.js.map +1 -1
  94. package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
  95. package/package.json +5 -9
  96. package/src/components/DragDrop/DragButton.tsx +27 -0
  97. package/src/components/DragDrop/DragDropSort.tsx +182 -0
  98. package/src/components/DragDrop/Draggable.tsx +58 -0
  99. package/src/components/DragDrop/DraggableDataListItem.tsx +61 -0
  100. package/src/components/DragDrop/DraggableDualListSelectorListItem.tsx +93 -0
  101. package/src/components/DragDrop/Droppable.tsx +27 -0
  102. package/src/components/DragDrop/DroppableContext.ts +6 -0
  103. package/src/components/DragDrop/__tests__/DragDrop.test.tsx +19 -0
  104. package/src/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +125 -0
  105. package/src/components/DragDrop/examples/BasicSortingWithDragButton.tsx +19 -0
  106. package/src/components/DragDrop/examples/DataListDraggable.tsx +38 -0
  107. package/src/components/DragDrop/examples/DragDrop.md +26 -0
  108. package/src/components/DragDrop/examples/DragDropDemos.md +37 -0
  109. package/src/components/DragDrop/examples/DualListSelectorDraggable.tsx +154 -0
  110. package/src/components/DragDrop/index.ts +1 -0
  111. package/src/components/index.ts +1 -0
  112. package/src/index.ts +1 -1
  113. package/src/next/components/DragDrop/DragDropSort.tsx +5 -1
  114. package/src/next/components/DragDrop/__tests__/DragDrop.test.tsx +5 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-drag-drop",
3
- "version": "6.0.0-alpha.5",
3
+ "version": "6.0.0-alpha.51",
4
4
  "description": "PatternFly drag and drop solution",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -32,9 +32,9 @@
32
32
  "@dnd-kit/core": "^6.0.8",
33
33
  "@dnd-kit/modifiers": "^6.0.1",
34
34
  "@dnd-kit/sortable": "^7.0.2",
35
- "@patternfly/react-core": "^6.0.0-alpha.24",
36
- "@patternfly/react-icons": "^6.0.0-alpha.11",
37
- "@patternfly/react-styles": "^6.0.0-alpha.11",
35
+ "@patternfly/react-core": "^6.0.0-alpha.69",
36
+ "@patternfly/react-icons": "^6.0.0-alpha.24",
37
+ "@patternfly/react-styles": "^6.0.0-alpha.24",
38
38
  "memoize-one": "^5.1.0",
39
39
  "resize-observer-polyfill": "^1.5.1"
40
40
  },
@@ -42,9 +42,5 @@
42
42
  "react": "^17 || ^18",
43
43
  "react-dom": "^17 || ^18"
44
44
  },
45
- "devDependencies": {
46
- "rimraf": "^2.6.2",
47
- "typescript": "^4.7.4"
48
- },
49
- "gitHead": "8ea069949f2c22f8122ffecab5451f278edfb8f7"
45
+ "gitHead": "1199f35a15534c4e13b62e0b7dcde52603ea1285"
50
46
  }
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { css } from '@patternfly/react-styles';
3
+ import dragButtonStyles from '@patternfly/react-styles/css/components/DataList/data-list';
4
+ import buttonStyles from '@patternfly/react-styles/css/components/Button/button';
5
+ import GripVerticalIcon from '@patternfly/react-icons/dist/esm/icons/grip-vertical-icon';
6
+
7
+ export interface DragButtonProps extends React.HTMLProps<HTMLButtonElement> {
8
+ /** Additional classes added to the drag button */
9
+ className?: string;
10
+ /** Sets button type */
11
+ type?: 'button' | 'submit' | 'reset';
12
+ /** Flag indicating if drag is disabled for the item */
13
+ isDisabled?: boolean;
14
+ }
15
+
16
+ export const DragButton: React.FunctionComponent<DragButtonProps> = ({ className, ...props }: DragButtonProps) => (
17
+ <button
18
+ className={css(className, buttonStyles.button, buttonStyles.modifiers.plain)}
19
+ aria-label="Drag button"
20
+ {...props}
21
+ >
22
+ <span className={css(dragButtonStyles.dataListItemDraggableIcon)}>
23
+ <GripVerticalIcon />
24
+ </span>
25
+ </button>
26
+ );
27
+ DragButton.displayName = 'DragButton';
@@ -0,0 +1,182 @@
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 styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
25
+
26
+ export type DragDropSortDragEndEvent = DragEndEvent;
27
+ export type DragDropSortDragStartEvent = DragStartEvent;
28
+
29
+ export interface DraggableObject {
30
+ /** Unique id of the draggable object */
31
+ id: string;
32
+ /** Content rendered in the draggable object */
33
+ content: React.ReactNode;
34
+ /** Props spread to the rendered wrapper of the draggable object */
35
+ props?: any;
36
+ }
37
+
38
+ /**
39
+ * DragDropSortProps extends dnd-kit's props which may be viewed at https://docs.dndkit.com/api-documentation/context-provider#props.
40
+ */
41
+ export interface DragDropSortProps extends DndContextProps {
42
+ /** Custom defined content wrapper for draggable items. By default, draggable items are wrapped in a styled div.
43
+ * Intended to be a 'DataList' or 'DualListSelectorList' without children. */
44
+ children?: React.ReactElement;
45
+ /** Sorted array of draggable objects */
46
+ items: DraggableObject[];
47
+ /** Callback when user drops a draggable object */
48
+ onDrop: (event: DragDropSortDragEndEvent, items: DraggableObject[], oldIndex?: number, newIndex?: number) => void;
49
+ /** Callback when use begins dragging a draggable object */
50
+ onDrag?: (event: DragDropSortDragStartEvent, oldIndex: number) => void;
51
+ /** The variant determines which component wraps the draggable object.
52
+ * Default variant wraps the draggable object in a div.
53
+ * DataList vairant wraps the draggable object in a DataListItem
54
+ * DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
55
+ * TableComposable variant wraps the draggable objects in TODO
56
+ * */
57
+ variant?: 'default' | 'DataList' | 'DualListSelectorList' | 'TableComposable';
58
+ }
59
+
60
+ export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
61
+ items,
62
+ onDrop = () => {},
63
+ onDrag = () => {},
64
+ variant = 'default',
65
+ children,
66
+ ...props
67
+ }: DragDropSortProps) => {
68
+ const [activeId, setActiveId] = React.useState<string>(null);
69
+ const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
70
+
71
+ const getItemById = (id: string): DraggableObject => items.find((item) => item.id === id);
72
+
73
+ const sensors = useSensors(
74
+ useSensor(PointerSensor),
75
+ useSensor(KeyboardSensor, {
76
+ coordinateGetter: sortableKeyboardCoordinates
77
+ })
78
+ );
79
+
80
+ const handleDragEnd = (event: DragEndEvent) => {
81
+ const { active, over } = event;
82
+ const oldIndex = itemIds.indexOf(active.id as string);
83
+ const newIndex = itemIds.indexOf(over.id as string);
84
+ const newItems = arrayMove(items, oldIndex, newIndex);
85
+ onDrop(event, newItems, oldIndex, newIndex);
86
+ setActiveId(null);
87
+ };
88
+
89
+ const handleDragStart = (event: DragStartEvent) => {
90
+ setActiveId(event.active.id as string);
91
+ onDrag(event, itemIds.indexOf(event.active.id as string));
92
+ };
93
+
94
+ const getDragOverlay = () => {
95
+ if (!activeId) {
96
+ return;
97
+ }
98
+ const item = getItemById(activeId);
99
+
100
+ let content;
101
+ switch (variant) {
102
+ case 'DualListSelectorList':
103
+ content = (
104
+ <DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
105
+ {item.content}
106
+ </DraggableDualListSelectorListItem>
107
+ );
108
+ break;
109
+ case 'DataList':
110
+ content = (
111
+ <DraggableDataListItem key={item.id} id={item.id} {...item.props}>
112
+ {item.content}
113
+ </DraggableDataListItem>
114
+ );
115
+ break;
116
+ default:
117
+ content = (
118
+ <Draggable useDragButton={variant === 'default'} key={item.id} id={item.id} {...item.props}>
119
+ {item.content}
120
+ </Draggable>
121
+ );
122
+ }
123
+
124
+ return (
125
+ <div
126
+ className={css(styles.draggable, styles.modifiers.dragging)}
127
+ style={
128
+ {
129
+ '--pf-v6-c-draggable--m-dragging--BackgroundColor': 'var(--pf-v6-global--BackgroundColor--100)'
130
+ } as React.CSSProperties
131
+ }
132
+ >
133
+ {content}
134
+ </div>
135
+ );
136
+ };
137
+
138
+ const renderedChildren = (
139
+ <SortableContext items={itemIds} strategy={verticalListSortingStrategy} id="droppable">
140
+ {items.map((item: DraggableObject) => {
141
+ switch (variant) {
142
+ case 'DualListSelectorList':
143
+ return (
144
+ <DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
145
+ {item.content}
146
+ </DraggableDualListSelectorListItem>
147
+ );
148
+ case 'DataList':
149
+ return (
150
+ <DraggableDataListItem key={item.id} id={item.id} {...item.props}>
151
+ {item.content}
152
+ </DraggableDataListItem>
153
+ );
154
+ default:
155
+ return (
156
+ <Draggable useDragButton={variant === 'default'} key={item.id} id={item.id} {...item.props}>
157
+ {item.content}
158
+ </Draggable>
159
+ );
160
+ }
161
+ })}
162
+ <DragOverlay>{activeId && getDragOverlay()}</DragOverlay>
163
+ </SortableContext>
164
+ );
165
+
166
+ return (
167
+ <DndContext
168
+ sensors={sensors}
169
+ collisionDetection={closestCenter}
170
+ onDragEnd={handleDragEnd}
171
+ onDragStart={handleDragStart}
172
+ {...props}
173
+ >
174
+ {children &&
175
+ React.cloneElement(children, {
176
+ children: renderedChildren
177
+ })}
178
+ {!children && <div>{renderedChildren}</div>}
179
+ </DndContext>
180
+ );
181
+ };
182
+ DragDropSort.displayName = 'DragDropSort';
@@ -0,0 +1,58 @@
1
+ import * as React from 'react';
2
+ import { useSortable } from '@dnd-kit/sortable';
3
+ import { CSS } from '@dnd-kit/utilities';
4
+ import { css } from '@patternfly/react-styles';
5
+ import styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
6
+ import { DragButton } from './DragButton';
7
+
8
+ export interface DraggableProps extends React.HTMLProps<HTMLDivElement> {
9
+ /** Content rendered inside DragDrop */
10
+ children?: React.ReactNode;
11
+ /** Class to add to outer div */
12
+ className?: string;
13
+ /** @hide Id of the sortable context. */
14
+ id?: string;
15
+ /** Flag indicating the draggable element should include a drag button. */
16
+ useDragButton?: boolean;
17
+ }
18
+
19
+ export const Draggable: React.FunctionComponent<DraggableProps> = ({
20
+ children,
21
+ id,
22
+ className,
23
+ useDragButton = false,
24
+ ...props
25
+ }: DraggableProps) => {
26
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
27
+ id
28
+ });
29
+
30
+ const style = {
31
+ transform: CSS.Transform.toString(transform),
32
+ transition
33
+ };
34
+
35
+ return useDragButton ? (
36
+ <div
37
+ className={css(isDragging && styles.droppable, isDragging && styles.modifiers.dragging, className)}
38
+ ref={setNodeRef}
39
+ style={style}
40
+ {...props}
41
+ >
42
+ <DragButton {...attributes} {...listeners} />
43
+ {children}
44
+ </div>
45
+ ) : (
46
+ <div
47
+ className={css(isDragging && styles.droppable, isDragging && styles.modifiers.dragging, className)}
48
+ ref={setNodeRef}
49
+ style={style}
50
+ {...listeners}
51
+ {...attributes}
52
+ {...props}
53
+ >
54
+ {children}
55
+ </div>
56
+ );
57
+ };
58
+ Draggable.displayName = 'Draggable';
@@ -0,0 +1,61 @@
1
+ import * as React from 'react';
2
+ import { useSortable } from '@dnd-kit/sortable';
3
+ import { CSS } from '@dnd-kit/utilities';
4
+ import { css } from '@patternfly/react-styles';
5
+ import styles from '@patternfly/react-styles/css/components/DataList/data-list';
6
+ import dragStyles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
7
+ import { DragButton } from './DragButton';
8
+ import { DataListItemRow, DataListControl } from '@patternfly/react-core';
9
+
10
+ export interface DraggableDataListItemObject {
11
+ id?: string;
12
+ content?: React.ReactNode;
13
+ }
14
+
15
+ export interface DraggableDataListItemProps extends React.HTMLProps<HTMLLIElement> {
16
+ /** Content rendered inside DragDrop */
17
+ children?: React.ReactNode;
18
+ /** Class to add to outer div */
19
+ className?: string;
20
+ /** @hide Id of the sortable context. */
21
+ id?: string;
22
+ }
23
+
24
+ export const DraggableDataListItem: React.FunctionComponent<DraggableDataListItemProps> = ({
25
+ children,
26
+ id,
27
+ className,
28
+ ...props
29
+ }: DraggableDataListItemProps) => {
30
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
31
+ id
32
+ });
33
+
34
+ const style = {
35
+ transform: CSS.Transform.toString(transform),
36
+ transition
37
+ };
38
+
39
+ return (
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
+ >
52
+ <DataListItemRow>
53
+ <DataListControl>
54
+ <DragButton className={css(styles.dataListItemDraggableButton)} {...attributes} {...listeners} />
55
+ </DataListControl>
56
+ {children}
57
+ </DataListItemRow>
58
+ </li>
59
+ );
60
+ };
61
+ DraggableDataListItem.displayName = 'DraggableDataListItem';
@@ -0,0 +1,93 @@
1
+ import * as React from 'react';
2
+ import { useSortable } from '@dnd-kit/sortable';
3
+ import { CSS } from '@dnd-kit/utilities';
4
+ import { css } from '@patternfly/react-styles';
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';
7
+ import { DragButton } from './DragButton';
8
+ import { DualListSelectorListContext } from '@patternfly/react-core/dist/esm/components/DualListSelector';
9
+
10
+ export interface DraggableDualListSelectorListItemProps extends React.HTMLProps<HTMLLIElement> {
11
+ /** Content rendered inside DragDrop */
12
+ children?: React.ReactNode;
13
+ /** Don't wrap the component in a div. Requires passing a single child. */
14
+ hasNoWrapper?: boolean;
15
+ /** Class to add to outer div */
16
+ className?: string;
17
+ /** @hide Id of the sortable context */
18
+ id?: string;
19
+ /** Flag indicating the list item is currently selected. */
20
+ isSelected?: boolean;
21
+ /** Callback fired when an option is selected. */
22
+ onOptionSelect?: (e: React.MouseEvent | React.ChangeEvent | React.KeyboardEvent, id?: string) => void;
23
+ /** @hide Internal field used to keep track of order of unfiltered options. */
24
+ orderIndex?: number;
25
+ /** @hide Forwarded ref */
26
+ innerRef?: React.RefObject<HTMLLIElement>;
27
+ /** Flag indicating if the dual list selector is in a disabled state */
28
+ isDisabled?: boolean;
29
+ }
30
+
31
+ export const DraggableDualListSelectorListItem: React.FunctionComponent<DraggableDualListSelectorListItemProps> = ({
32
+ children,
33
+ id,
34
+ className,
35
+ orderIndex,
36
+ isSelected,
37
+ onOptionSelect,
38
+ ...props
39
+ }: DraggableDualListSelectorListItemProps) => {
40
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
41
+ id,
42
+ animateLayoutChanges: () => false
43
+ });
44
+
45
+ const { setFocusedOption } = React.useContext(DualListSelectorListContext);
46
+
47
+ const style = {
48
+ transform: CSS.Transform.toString(transform),
49
+ transition
50
+ };
51
+
52
+ return (
53
+ <li
54
+ className={css(
55
+ styles.dualListSelectorListItem,
56
+ isDragging && dragStyles.droppable,
57
+ isDragging && dragStyles.modifiers.dragging,
58
+ className
59
+ )}
60
+ key={orderIndex}
61
+ id={id}
62
+ role="presentation"
63
+ {...props}
64
+ ref={setNodeRef}
65
+ style={style}
66
+ >
67
+ <div className={css(styles.dualListSelectorListItemRow, isSelected && styles.modifiers.selected)}>
68
+ <DragButton className={css(styles.dualListSelectorDraggable)} {...attributes} {...listeners} />
69
+ <span
70
+ className={css(styles.dualListSelectorItem)}
71
+ onKeyDown={(e: React.KeyboardEvent) => {
72
+ if (e.key === ' ' || e.key === 'Enter') {
73
+ (document.activeElement as HTMLElement).click();
74
+ e.preventDefault();
75
+ }
76
+ }}
77
+ aria-selected={isSelected}
78
+ onClick={(e: React.MouseEvent) => {
79
+ setFocusedOption(id);
80
+ onOptionSelect(e, id);
81
+ }}
82
+ role="option"
83
+ tabIndex={-1}
84
+ >
85
+ <span className={css(styles.dualListSelectorItemMain)}>
86
+ <span className={css(styles.dualListSelectorItemText)}>{children}</span>
87
+ </span>
88
+ </span>
89
+ </div>
90
+ </li>
91
+ );
92
+ };
93
+ DraggableDualListSelectorListItem.displayName = 'DraggableDualListSelectorListItem';
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { useDroppable } from '@dnd-kit/core';
3
+
4
+ interface DroppableProps extends React.HTMLProps<HTMLDivElement> {
5
+ /** Content rendered inside DragDrop */
6
+ children?: React.ReactNode;
7
+ /** Class to add to outer div */
8
+ className?: string;
9
+ /** Name of zone that items can be dragged between. Should specify if there is more than one Droppable on the page. */
10
+ zone?: string;
11
+ /** Id to be passed back on drop events */
12
+ droppableId?: string;
13
+ /** Don't wrap the component in a div. Requires passing a single child. */
14
+ hasNoWrapper?: boolean;
15
+ }
16
+
17
+ export const Droppable: React.FunctionComponent<DroppableProps> = ({ children, ...props }: DroppableProps) => {
18
+ const { isOver, setNodeRef } = useDroppable({ id: 'droppable' });
19
+ const style = { color: isOver ? 'green' : undefined };
20
+
21
+ return (
22
+ <div ref={setNodeRef} style={style} {...props}>
23
+ {children}
24
+ </div>
25
+ );
26
+ };
27
+ Droppable.displayName = 'Droppable';
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+
3
+ export const DroppableContext = React.createContext({
4
+ zone: 'defaultDroppableZone',
5
+ droppableId: 'defaultDroppableId'
6
+ });
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { DragDropSort } from '../';
4
+
5
+ test('renders some divs', () => {
6
+ const { asFragment } = render(
7
+ <div className="pf-c-droppable pf-m-dragging">
8
+ <DragDropSort
9
+ items={[
10
+ { id: '1', content: 'one' },
11
+ { id: '2', content: 'two' },
12
+ { id: '3', content: 'three' }
13
+ ]}
14
+ onDrop={() => {}}
15
+ />
16
+ </div>
17
+ );
18
+ expect(asFragment()).toMatchSnapshot();
19
+ });
@@ -0,0 +1,125 @@
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
+ role="button"
19
+ tabindex="0"
20
+ >
21
+ <span
22
+ class="pf-v6-c-data-list__item-draggable-icon"
23
+ >
24
+ <svg
25
+ aria-hidden="true"
26
+ class="pf-v6-svg"
27
+ fill="currentColor"
28
+ height="1em"
29
+ role="img"
30
+ viewBox="0 0 320 512"
31
+ width="1em"
32
+ >
33
+ <path
34
+ 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"
35
+ />
36
+ </svg>
37
+ </span>
38
+ </button>
39
+ one
40
+ </div>
41
+ <div
42
+ class=""
43
+ >
44
+ <button
45
+ aria-describedby="DndDescribedBy-0"
46
+ aria-disabled="false"
47
+ aria-label="Drag button"
48
+ aria-roledescription="sortable"
49
+ class="pf-v6-c-button pf-m-plain"
50
+ role="button"
51
+ tabindex="0"
52
+ >
53
+ <span
54
+ class="pf-v6-c-data-list__item-draggable-icon"
55
+ >
56
+ <svg
57
+ aria-hidden="true"
58
+ class="pf-v6-svg"
59
+ fill="currentColor"
60
+ height="1em"
61
+ role="img"
62
+ viewBox="0 0 320 512"
63
+ width="1em"
64
+ >
65
+ <path
66
+ 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"
67
+ />
68
+ </svg>
69
+ </span>
70
+ </button>
71
+ two
72
+ </div>
73
+ <div
74
+ class=""
75
+ >
76
+ <button
77
+ aria-describedby="DndDescribedBy-0"
78
+ aria-disabled="false"
79
+ aria-label="Drag button"
80
+ aria-roledescription="sortable"
81
+ class="pf-v6-c-button pf-m-plain"
82
+ role="button"
83
+ tabindex="0"
84
+ >
85
+ <span
86
+ class="pf-v6-c-data-list__item-draggable-icon"
87
+ >
88
+ <svg
89
+ aria-hidden="true"
90
+ class="pf-v6-svg"
91
+ fill="currentColor"
92
+ height="1em"
93
+ role="img"
94
+ viewBox="0 0 320 512"
95
+ width="1em"
96
+ >
97
+ <path
98
+ 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"
99
+ />
100
+ </svg>
101
+ </span>
102
+ </button>
103
+ three
104
+ </div>
105
+ </div>
106
+ <div
107
+ id="DndDescribedBy-0"
108
+ style="display: none;"
109
+ >
110
+
111
+ To pick up a draggable item, press the space bar.
112
+ While dragging, use the arrow keys to move the item.
113
+ Press space again to drop the item in its new position, or press escape to cancel.
114
+
115
+ </div>
116
+ <div
117
+ aria-atomic="true"
118
+ aria-live="assertive"
119
+ id="DndLiveRegion-0"
120
+ role="status"
121
+ style="position: fixed; width: 1px; height: 1px; margin: -1px; border: 0px; padding: 0px; overflow: hidden; clip-path: inset(100%); white-space: nowrap;"
122
+ />
123
+ </div>
124
+ </DocumentFragment>
125
+ `;
@@ -0,0 +1,19 @@
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
+ onDrop={(_, newItems) => {
15
+ setItems(newItems);
16
+ }}
17
+ />
18
+ );
19
+ };