@patternfly/react-drag-drop 6.0.0-alpha.71 → 6.0.0-alpha.72

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 (160) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/cjs.tsbuildinfo +1 -1
  3. package/dist/esm/components/DragDrop/DragDropContainer.d.ts +41 -0
  4. package/dist/esm/components/DragDrop/DragDropContainer.d.ts.map +1 -0
  5. package/dist/esm/components/DragDrop/DragDropContainer.js +147 -0
  6. package/dist/esm/components/DragDrop/DragDropContainer.js.map +1 -0
  7. package/dist/esm/components/DragDrop/DragDropSort.d.ts +5 -11
  8. package/dist/esm/components/DragDrop/DragDropSort.d.ts.map +1 -1
  9. package/dist/esm/components/DragDrop/DragDropSort.js +11 -59
  10. package/dist/esm/components/DragDrop/DragDropSort.js.map +1 -1
  11. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js +2 -2
  12. package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
  13. package/dist/esm/components/DragDrop/Droppable.d.ts +15 -9
  14. package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -1
  15. package/dist/esm/components/DragDrop/Droppable.js +21 -4
  16. package/dist/esm/components/DragDrop/Droppable.js.map +1 -1
  17. package/dist/esm/components/DragDrop/index.d.ts +2 -0
  18. package/dist/esm/components/DragDrop/index.d.ts.map +1 -1
  19. package/dist/esm/components/DragDrop/index.js +2 -0
  20. package/dist/esm/components/DragDrop/index.js.map +1 -1
  21. package/dist/esm.tsbuildinfo +1 -1
  22. package/dist/js/components/DragDrop/DragDropContainer.d.ts +41 -0
  23. package/dist/js/components/DragDrop/DragDropContainer.d.ts.map +1 -0
  24. package/dist/js/components/DragDrop/DragDropContainer.js +151 -0
  25. package/dist/js/components/DragDrop/DragDropContainer.js.map +1 -0
  26. package/dist/js/components/DragDrop/DragDropSort.d.ts +5 -11
  27. package/dist/js/components/DragDrop/DragDropSort.d.ts.map +1 -1
  28. package/dist/js/components/DragDrop/DragDropSort.js +11 -59
  29. package/dist/js/components/DragDrop/DragDropSort.js.map +1 -1
  30. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js +2 -2
  31. package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
  32. package/dist/js/components/DragDrop/Droppable.d.ts +15 -9
  33. package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -1
  34. package/dist/js/components/DragDrop/Droppable.js +21 -4
  35. package/dist/js/components/DragDrop/Droppable.js.map +1 -1
  36. package/dist/js/components/DragDrop/index.d.ts +2 -0
  37. package/dist/js/components/DragDrop/index.d.ts.map +1 -1
  38. package/dist/js/components/DragDrop/index.js +2 -0
  39. package/dist/js/components/DragDrop/index.js.map +1 -1
  40. package/package.json +3 -3
  41. package/src/components/DragDrop/DragDropContainer.tsx +305 -0
  42. package/src/components/DragDrop/DragDropSort.tsx +22 -137
  43. package/src/components/DragDrop/DraggableDualListSelectorListItem.tsx +2 -2
  44. package/src/components/DragDrop/Droppable.tsx +64 -15
  45. package/src/components/DragDrop/__tests__/DragDrop.test.tsx +5 -0
  46. package/src/components/DragDrop/examples/DataListDraggable.tsx +1 -0
  47. package/src/components/DragDrop/examples/DragDrop.md +8 -2
  48. package/src/components/DragDrop/examples/DragDropContainerBasic.tsx +45 -0
  49. package/src/components/DragDrop/examples/DragDropContainerDataList.tsx +75 -0
  50. package/src/components/DragDrop/examples/DragDropContainerDualListSelector.tsx +191 -0
  51. package/src/components/DragDrop/examples/DragDropDemos.md +25 -1
  52. package/src/components/DragDrop/index.ts +2 -0
  53. package/dist/esm/components/DragDrop/DroppableContext.d.ts +0 -6
  54. package/dist/esm/components/DragDrop/DroppableContext.d.ts.map +0 -1
  55. package/dist/esm/components/DragDrop/DroppableContext.js +0 -6
  56. package/dist/esm/components/DragDrop/DroppableContext.js.map +0 -1
  57. package/dist/esm/next/components/DragDrop/DragButton.d.ts +0 -11
  58. package/dist/esm/next/components/DragDrop/DragButton.d.ts.map +0 -1
  59. package/dist/esm/next/components/DragDrop/DragButton.js +0 -14
  60. package/dist/esm/next/components/DragDrop/DragButton.js.map +0 -1
  61. package/dist/esm/next/components/DragDrop/DragDropSort.d.ts +0 -35
  62. package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +0 -1
  63. package/dist/esm/next/components/DragDrop/DragDropSort.js +0 -73
  64. package/dist/esm/next/components/DragDrop/DragDropSort.js.map +0 -1
  65. package/dist/esm/next/components/DragDrop/Draggable.d.ts +0 -13
  66. package/dist/esm/next/components/DragDrop/Draggable.d.ts.map +0 -1
  67. package/dist/esm/next/components/DragDrop/Draggable.js +0 -22
  68. package/dist/esm/next/components/DragDrop/Draggable.js.map +0 -1
  69. package/dist/esm/next/components/DragDrop/DraggableDataListItem.d.ts +0 -15
  70. package/dist/esm/next/components/DragDrop/DraggableDataListItem.d.ts.map +0 -1
  71. package/dist/esm/next/components/DragDrop/DraggableDataListItem.js +0 -26
  72. package/dist/esm/next/components/DragDrop/DraggableDataListItem.js.map +0 -1
  73. package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts +0 -23
  74. package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +0 -1
  75. package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js +0 -37
  76. package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +0 -1
  77. package/dist/esm/next/components/DragDrop/Droppable.d.ts +0 -16
  78. package/dist/esm/next/components/DragDrop/Droppable.d.ts.map +0 -1
  79. package/dist/esm/next/components/DragDrop/Droppable.js +0 -11
  80. package/dist/esm/next/components/DragDrop/Droppable.js.map +0 -1
  81. package/dist/esm/next/components/DragDrop/DroppableContext.d.ts +0 -6
  82. package/dist/esm/next/components/DragDrop/DroppableContext.d.ts.map +0 -1
  83. package/dist/esm/next/components/DragDrop/DroppableContext.js +0 -6
  84. package/dist/esm/next/components/DragDrop/DroppableContext.js.map +0 -1
  85. package/dist/esm/next/components/DragDrop/index.d.ts +0 -2
  86. package/dist/esm/next/components/DragDrop/index.d.ts.map +0 -1
  87. package/dist/esm/next/components/DragDrop/index.js +0 -2
  88. package/dist/esm/next/components/DragDrop/index.js.map +0 -1
  89. package/dist/esm/next/components/index.d.ts +0 -2
  90. package/dist/esm/next/components/index.d.ts.map +0 -1
  91. package/dist/esm/next/components/index.js +0 -2
  92. package/dist/esm/next/components/index.js.map +0 -1
  93. package/dist/esm/next/index.d.ts +0 -2
  94. package/dist/esm/next/index.d.ts.map +0 -1
  95. package/dist/esm/next/index.js +0 -2
  96. package/dist/esm/next/index.js.map +0 -1
  97. package/dist/js/components/DragDrop/DroppableContext.d.ts +0 -6
  98. package/dist/js/components/DragDrop/DroppableContext.d.ts.map +0 -1
  99. package/dist/js/components/DragDrop/DroppableContext.js +0 -10
  100. package/dist/js/components/DragDrop/DroppableContext.js.map +0 -1
  101. package/dist/js/next/components/DragDrop/DragButton.d.ts +0 -11
  102. package/dist/js/next/components/DragDrop/DragButton.d.ts.map +0 -1
  103. package/dist/js/next/components/DragDrop/DragButton.js +0 -18
  104. package/dist/js/next/components/DragDrop/DragButton.js.map +0 -1
  105. package/dist/js/next/components/DragDrop/DragDropSort.d.ts +0 -35
  106. package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +0 -1
  107. package/dist/js/next/components/DragDrop/DragDropSort.js +0 -77
  108. package/dist/js/next/components/DragDrop/DragDropSort.js.map +0 -1
  109. package/dist/js/next/components/DragDrop/Draggable.d.ts +0 -13
  110. package/dist/js/next/components/DragDrop/Draggable.d.ts.map +0 -1
  111. package/dist/js/next/components/DragDrop/Draggable.js +0 -26
  112. package/dist/js/next/components/DragDrop/Draggable.js.map +0 -1
  113. package/dist/js/next/components/DragDrop/DraggableDataListItem.d.ts +0 -15
  114. package/dist/js/next/components/DragDrop/DraggableDataListItem.d.ts.map +0 -1
  115. package/dist/js/next/components/DragDrop/DraggableDataListItem.js +0 -30
  116. package/dist/js/next/components/DragDrop/DraggableDataListItem.js.map +0 -1
  117. package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts +0 -23
  118. package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +0 -1
  119. package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js +0 -41
  120. package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +0 -1
  121. package/dist/js/next/components/DragDrop/Droppable.d.ts +0 -16
  122. package/dist/js/next/components/DragDrop/Droppable.d.ts.map +0 -1
  123. package/dist/js/next/components/DragDrop/Droppable.js +0 -15
  124. package/dist/js/next/components/DragDrop/Droppable.js.map +0 -1
  125. package/dist/js/next/components/DragDrop/DroppableContext.d.ts +0 -6
  126. package/dist/js/next/components/DragDrop/DroppableContext.d.ts.map +0 -1
  127. package/dist/js/next/components/DragDrop/DroppableContext.js +0 -10
  128. package/dist/js/next/components/DragDrop/DroppableContext.js.map +0 -1
  129. package/dist/js/next/components/DragDrop/index.d.ts +0 -2
  130. package/dist/js/next/components/DragDrop/index.d.ts.map +0 -1
  131. package/dist/js/next/components/DragDrop/index.js +0 -5
  132. package/dist/js/next/components/DragDrop/index.js.map +0 -1
  133. package/dist/js/next/components/index.d.ts +0 -2
  134. package/dist/js/next/components/index.d.ts.map +0 -1
  135. package/dist/js/next/components/index.js +0 -5
  136. package/dist/js/next/components/index.js.map +0 -1
  137. package/dist/js/next/index.d.ts +0 -2
  138. package/dist/js/next/index.d.ts.map +0 -1
  139. package/dist/js/next/index.js +0 -5
  140. package/dist/js/next/index.js.map +0 -1
  141. package/src/components/DragDrop/DroppableContext.ts +0 -6
  142. package/src/components/DragDrop/examples/BasicSortingWithDragButton.tsx +0 -19
  143. package/src/next/components/DragDrop/DragButton.tsx +0 -27
  144. package/src/next/components/DragDrop/DragDropSort.tsx +0 -186
  145. package/src/next/components/DragDrop/Draggable.tsx +0 -58
  146. package/src/next/components/DragDrop/DraggableDataListItem.tsx +0 -61
  147. package/src/next/components/DragDrop/DraggableDualListSelectorListItem.tsx +0 -93
  148. package/src/next/components/DragDrop/Droppable.tsx +0 -27
  149. package/src/next/components/DragDrop/DroppableContext.ts +0 -6
  150. package/src/next/components/DragDrop/__tests__/DragDrop.test.tsx +0 -24
  151. package/src/next/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +0 -59
  152. package/src/next/components/DragDrop/examples/BasicSortingWithDragButton.tsx +0 -20
  153. package/src/next/components/DragDrop/examples/DataListDraggable.tsx +0 -38
  154. package/src/next/components/DragDrop/examples/DragDrop.md +0 -32
  155. package/src/next/components/DragDrop/examples/DragDropDemos.md +0 -37
  156. package/src/next/components/DragDrop/examples/DualListSelectorDraggable.tsx +0 -150
  157. package/src/next/components/DragDrop/index.ts +0 -1
  158. package/src/next/components/index.ts +0 -1
  159. package/src/next/index.ts +0 -1
  160. /package/src/{next/components → components}/DragDrop/examples/BasicSorting.tsx +0 -0
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Droppable = void 0;
4
- const tslib_1 = require("tslib");
5
- const React = tslib_1.__importStar(require("react"));
6
- const core_1 = require("@dnd-kit/core");
7
- const Droppable = (_a) => {
8
- var { children } = _a, props = tslib_1.__rest(_a, ["children"]);
9
- const { isOver, setNodeRef } = (0, core_1.useDroppable)({ id: 'droppable' });
10
- const style = { color: isOver ? 'green' : undefined };
11
- return (React.createElement("div", Object.assign({ ref: setNodeRef, style: style }, props), children));
12
- };
13
- exports.Droppable = Droppable;
14
- exports.Droppable.displayName = 'Droppable';
15
- //# sourceMappingURL=Droppable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Droppable.js","sourceRoot":"","sources":["../../../../../src/next/components/DragDrop/Droppable.tsx"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAC/B,wCAA6C;AAetC,MAAM,SAAS,GAA4C,CAAC,EAAsC,EAAE,EAAE;QAA1C,EAAE,QAAQ,OAA4B,EAAvB,KAAK,sBAApB,YAAsB,CAAF;IACrF,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,mBAAY,EAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IACjE,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAEtD,OAAO,CACL,2CAAK,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,IAAM,KAAK,GAC1C,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,SAAS,aASpB;AACF,iBAAS,CAAC,WAAW,GAAG,WAAW,CAAC"}
@@ -1,6 +0,0 @@
1
- import * as React from 'react';
2
- export declare const DroppableContext: React.Context<{
3
- zone: string;
4
- droppableId: string;
5
- }>;
6
- //# sourceMappingURL=DroppableContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DroppableContext.d.ts","sourceRoot":"","sources":["../../../../../src/next/components/DragDrop/DroppableContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,eAAO,MAAM,gBAAgB;;;EAG3B,CAAC"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DroppableContext = void 0;
4
- const tslib_1 = require("tslib");
5
- const React = tslib_1.__importStar(require("react"));
6
- exports.DroppableContext = React.createContext({
7
- zone: 'defaultDroppableZone',
8
- droppableId: 'defaultDroppableId'
9
- });
10
- //# sourceMappingURL=DroppableContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DroppableContext.js","sourceRoot":"","sources":["../../../../../src/next/components/DragDrop/DroppableContext.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAElB,QAAA,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAC;IAClD,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,oBAAoB;CAClC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './DragDropSort';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/next/components/DragDrop/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./DragDropSort"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/next/components/DragDrop/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B"}
@@ -1,2 +0,0 @@
1
- export * from './DragDrop';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/next/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./DragDrop"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/next/components/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B"}
@@ -1,2 +0,0 @@
1
- export * from './components';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./components"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B"}
@@ -1,6 +0,0 @@
1
- import * as React from 'react';
2
-
3
- export const DroppableContext = React.createContext({
4
- zone: 'defaultDroppableZone',
5
- droppableId: 'defaultDroppableId'
6
- });
@@ -1,19 +0,0 @@
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
- };
@@ -1,27 +0,0 @@
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';
@@ -1,186 +0,0 @@
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
- } from '@dnd-kit/core';
16
- import {
17
- arrayMove,
18
- SortableContext,
19
- sortableKeyboardCoordinates,
20
- verticalListSortingStrategy
21
- } from '@dnd-kit/sortable';
22
- import { Draggable } from './Draggable';
23
- import { DraggableDataListItem } from './DraggableDataListItem';
24
- import { DraggableDualListSelectorListItem } from './DraggableDualListSelectorListItem';
25
- import styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
26
- import { canUseDOM } from '@patternfly/react-core';
27
-
28
- export type DragDropSortDragEndEvent = DragEndEvent;
29
- export type DragDropSortDragStartEvent = DragStartEvent;
30
-
31
- export interface DraggableObject {
32
- /** Unique id of the draggable object */
33
- id: string;
34
- /** Content rendered in the draggable object */
35
- content: React.ReactNode;
36
- /** Props spread to the rendered wrapper of the draggable object */
37
- props?: any;
38
- }
39
-
40
- /**
41
- * DragDropSortProps extends dnd-kit's props which may be viewed at https://docs.dndkit.com/api-documentation/context-provider#props.
42
- */
43
- export interface DragDropSortProps extends DndContextProps {
44
- /** Custom defined content wrapper for draggable items. By default, draggable items are wrapped in a styled div.
45
- * Intended to be a 'DataList' or 'DualListSelectorList' without children. */
46
- children?: React.ReactElement;
47
- /** Sorted array of draggable objects */
48
- items: DraggableObject[];
49
- /** Callback when user drops a draggable object */
50
- onDrop: (event: DragDropSortDragEndEvent, items: DraggableObject[], oldIndex?: number, newIndex?: number) => void;
51
- /** Callback when use begins dragging a draggable object */
52
- onDrag?: (event: DragDropSortDragStartEvent, oldIndex: number) => void;
53
- /** The variant determines which component wraps the draggable object.
54
- * Default and defaultWithHandle varaints wrap the draggable object in a div.
55
- * DataList vairant wraps the draggable object in a DataListItem
56
- * DualListSelectorList variant wraps the draggable objects in a DualListSelectorListItem and a div.pf-c-dual-list-selector__item-text element
57
- * TableComposable variant wraps the draggable objects in TODO
58
- * */
59
- variant?: 'default' | 'defaultWithHandle' | 'DataList' | 'DualListSelectorList' | 'TableComposable';
60
- }
61
-
62
- export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
63
- items,
64
- onDrop = () => {},
65
- onDrag = () => {},
66
- variant = 'default',
67
- children,
68
- ...props
69
- }: DragDropSortProps) => {
70
- const [activeId, setActiveId] = React.useState<string>(null);
71
- const itemIds = React.useMemo(() => (items ? Array.from(items, (item) => item.id as string) : []), [items]);
72
-
73
- const getItemById = (id: string): DraggableObject => items.find((item) => item.id === id);
74
-
75
- const sensors = useSensors(
76
- useSensor(PointerSensor),
77
- useSensor(KeyboardSensor, {
78
- coordinateGetter: sortableKeyboardCoordinates
79
- })
80
- );
81
-
82
- const handleDragEnd = (event: DragEndEvent) => {
83
- const { active, over } = event;
84
- const oldIndex = itemIds.indexOf(active.id as string);
85
- const newIndex = itemIds.indexOf(over.id as string);
86
- const newItems = arrayMove(items, oldIndex, newIndex);
87
- onDrop(event, newItems, oldIndex, newIndex);
88
- setActiveId(null);
89
- };
90
-
91
- const handleDragStart = (event: DragStartEvent) => {
92
- setActiveId(event.active.id as string);
93
- onDrag(event, itemIds.indexOf(event.active.id as string));
94
- };
95
-
96
- const getDragOverlay = () => {
97
- if (!activeId) {
98
- return;
99
- }
100
- const item = getItemById(activeId);
101
-
102
- let content;
103
- switch (variant) {
104
- case 'DualListSelectorList':
105
- content = (
106
- <DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
107
- {item.content}
108
- </DraggableDualListSelectorListItem>
109
- );
110
- break;
111
- case 'DataList':
112
- content = (
113
- <DraggableDataListItem key={item.id} id={item.id} {...item.props}>
114
- {item.content}
115
- </DraggableDataListItem>
116
- );
117
- break;
118
- default:
119
- content = (
120
- <Draggable useDragButton={variant === 'defaultWithHandle'} key={item.id} id={item.id} {...item.props}>
121
- {item.content}
122
- </Draggable>
123
- );
124
- }
125
-
126
- return (
127
- <div
128
- className={css(styles.draggable, styles.modifiers.dragging)}
129
- style={
130
- {
131
- '--pf-v5-c-draggable--m-dragging--BackgroundColor': 'var(--pf-v5-global--BackgroundColor--100)'
132
- } as React.CSSProperties
133
- }
134
- >
135
- {content}
136
- </div>
137
- );
138
- };
139
-
140
- const dragOverlay = <DragOverlay>{activeId && getDragOverlay()}</DragOverlay>;
141
-
142
- const renderedChildren = (
143
- <SortableContext items={itemIds} strategy={verticalListSortingStrategy} id="droppable">
144
- {items.map((item: DraggableObject) => {
145
- switch (variant) {
146
- case 'DualListSelectorList':
147
- return (
148
- <DraggableDualListSelectorListItem key={item.id} id={item.id} {...item.props}>
149
- {item.content}
150
- </DraggableDualListSelectorListItem>
151
- );
152
- case 'DataList':
153
- return (
154
- <DraggableDataListItem key={item.id} id={item.id} {...item.props}>
155
- {item.content}
156
- </DraggableDataListItem>
157
- );
158
- default:
159
- return (
160
- <Draggable useDragButton={variant === 'defaultWithHandle'} key={item.id} id={item.id} {...item.props}>
161
- {item.content}
162
- </Draggable>
163
- );
164
- }
165
- })}
166
- {canUseDOM ? ReactDOM.createPortal(dragOverlay, document.getElementById('root')) : dragOverlay}
167
- </SortableContext>
168
- );
169
-
170
- return (
171
- <DndContext
172
- sensors={sensors}
173
- collisionDetection={closestCenter}
174
- onDragEnd={handleDragEnd}
175
- onDragStart={handleDragStart}
176
- {...props}
177
- >
178
- {children &&
179
- React.cloneElement(children, {
180
- children: renderedChildren
181
- })}
182
- {!children && <div>{renderedChildren}</div>}
183
- </DndContext>
184
- );
185
- };
186
- DragDropSort.displayName = 'DragDropSort';
@@ -1,58 +0,0 @@
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';
@@ -1,61 +0,0 @@
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';
@@ -1,93 +0,0 @@
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/deprecated/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';
@@ -1,27 +0,0 @@
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';
@@ -1,6 +0,0 @@
1
- import * as React from 'react';
2
-
3
- export const DroppableContext = React.createContext({
4
- zone: 'defaultDroppableZone',
5
- droppableId: 'defaultDroppableId'
6
- });
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { DragDropSort } from '../';
4
-
5
- jest.mock('react-dom', () => ({
6
- ...jest.requireActual('react-dom'),
7
- createPortal: jest.fn((node) => node)
8
- }));
9
-
10
- test('renders some divs', () => {
11
- const { asFragment } = render(
12
- <div className="pf-c-droppable pf-m-dragging">
13
- <DragDropSort
14
- items={[
15
- { id: '1', content: 'one' },
16
- { id: '2', content: 'two' },
17
- { id: '3', content: 'three' }
18
- ]}
19
- onDrop={() => {}}
20
- />
21
- </div>
22
- );
23
- expect(asFragment()).toMatchSnapshot();
24
- });