@patternfly/react-drag-drop 5.4.0-prerelease.3 → 5.4.0-prerelease.30
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 +119 -0
- package/dist/cjs.tsbuildinfo +1 -1
- package/dist/esm/next/components/DragDrop/DragDropContainer.d.ts +42 -0
- package/dist/esm/next/components/DragDrop/DragDropContainer.d.ts.map +1 -0
- package/dist/esm/next/components/DragDrop/DragDropContainer.js +147 -0
- package/dist/esm/next/components/DragDrop/DragDropContainer.js.map +1 -0
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts +5 -10
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.js +12 -59
- package/dist/esm/next/components/DragDrop/DragDropSort.js.map +1 -1
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
- package/dist/esm/next/components/DragDrop/Droppable.d.ts +15 -9
- package/dist/esm/next/components/DragDrop/Droppable.d.ts.map +1 -1
- package/dist/esm/next/components/DragDrop/Droppable.js +21 -4
- package/dist/esm/next/components/DragDrop/Droppable.js.map +1 -1
- package/dist/esm/next/components/DragDrop/index.d.ts +2 -0
- package/dist/esm/next/components/DragDrop/index.d.ts.map +1 -1
- package/dist/esm/next/components/DragDrop/index.js +2 -0
- package/dist/esm/next/components/DragDrop/index.js.map +1 -1
- package/dist/esm.tsbuildinfo +1 -1
- package/dist/js/next/components/DragDrop/DragButton.js.map +1 -1
- package/dist/js/next/components/DragDrop/DragDropContainer.d.ts +42 -0
- package/dist/js/next/components/DragDrop/DragDropContainer.d.ts.map +1 -0
- package/dist/js/next/components/DragDrop/DragDropContainer.js +151 -0
- package/dist/js/next/components/DragDrop/DragDropContainer.js.map +1 -0
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts +5 -10
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
- package/dist/js/next/components/DragDrop/DragDropSort.js +12 -59
- package/dist/js/next/components/DragDrop/DragDropSort.js.map +1 -1
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
- package/dist/js/next/components/DragDrop/Droppable.d.ts +15 -9
- package/dist/js/next/components/DragDrop/Droppable.d.ts.map +1 -1
- package/dist/js/next/components/DragDrop/Droppable.js +21 -4
- package/dist/js/next/components/DragDrop/Droppable.js.map +1 -1
- package/dist/js/next/components/DragDrop/index.d.ts +2 -0
- package/dist/js/next/components/DragDrop/index.d.ts.map +1 -1
- package/dist/js/next/components/DragDrop/index.js +2 -0
- package/dist/js/next/components/DragDrop/index.js.map +1 -1
- package/package.json +6 -10
- package/src/next/components/DragDrop/DragDropContainer.tsx +305 -0
- package/src/next/components/DragDrop/DragDropSort.tsx +21 -133
- package/src/next/components/DragDrop/Droppable.tsx +69 -15
- package/src/next/components/DragDrop/__tests__/DragDrop.test.tsx +5 -0
- package/src/next/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +81 -15
- package/src/next/components/DragDrop/examples/BasicSortingWithDragButton.tsx +0 -1
- package/src/next/components/DragDrop/examples/DataListDraggable.tsx +1 -0
- package/src/next/components/DragDrop/examples/DragDrop.md +4 -4
- package/src/next/components/DragDrop/examples/DragDropContainerBasic.tsx +45 -0
- package/src/next/components/DragDrop/examples/DragDropContainerDataList.tsx +75 -0
- package/src/next/components/DragDrop/examples/DragDropContainerDualListSelector.tsx +191 -0
- package/src/next/components/DragDrop/examples/DragDropDemos.md +25 -1
- package/src/next/components/DragDrop/index.ts +2 -0
- package/dist/esm/next/components/DragDrop/DroppableContext.d.ts +0 -6
- package/dist/esm/next/components/DragDrop/DroppableContext.d.ts.map +0 -1
- package/dist/esm/next/components/DragDrop/DroppableContext.js +0 -6
- package/dist/esm/next/components/DragDrop/DroppableContext.js.map +0 -1
- package/dist/js/next/components/DragDrop/DroppableContext.d.ts +0 -6
- package/dist/js/next/components/DragDrop/DroppableContext.d.ts.map +0 -1
- package/dist/js/next/components/DragDrop/DroppableContext.js +0 -10
- package/dist/js/next/components/DragDrop/DroppableContext.js.map +0 -1
- package/src/next/components/DragDrop/DroppableContext.ts +0 -6
- package/src/next/components/DragDrop/examples/BasicSorting.tsx +0 -19
|
@@ -7,33 +7,99 @@ exports[`renders some divs 1`] = `
|
|
|
7
7
|
>
|
|
8
8
|
<div>
|
|
9
9
|
<div
|
|
10
|
-
aria-describedby="DndDescribedBy-0"
|
|
11
|
-
aria-disabled="false"
|
|
12
|
-
aria-roledescription="sortable"
|
|
13
10
|
class=""
|
|
14
|
-
role="button"
|
|
15
|
-
tabindex="0"
|
|
16
11
|
>
|
|
12
|
+
<button
|
|
13
|
+
aria-describedby="DndDescribedBy-0"
|
|
14
|
+
aria-disabled="false"
|
|
15
|
+
aria-label="Drag button"
|
|
16
|
+
aria-roledescription="sortable"
|
|
17
|
+
class="pf-v5-c-button pf-m-plain"
|
|
18
|
+
role="button"
|
|
19
|
+
tabindex="0"
|
|
20
|
+
>
|
|
21
|
+
<span
|
|
22
|
+
class="pf-v5-c-data-list__item-draggable-icon"
|
|
23
|
+
>
|
|
24
|
+
<svg
|
|
25
|
+
aria-hidden="true"
|
|
26
|
+
class="pf-v5-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>
|
|
17
39
|
one
|
|
18
40
|
</div>
|
|
19
41
|
<div
|
|
20
|
-
aria-describedby="DndDescribedBy-0"
|
|
21
|
-
aria-disabled="false"
|
|
22
|
-
aria-roledescription="sortable"
|
|
23
42
|
class=""
|
|
24
|
-
role="button"
|
|
25
|
-
tabindex="0"
|
|
26
43
|
>
|
|
44
|
+
<button
|
|
45
|
+
aria-describedby="DndDescribedBy-0"
|
|
46
|
+
aria-disabled="false"
|
|
47
|
+
aria-label="Drag button"
|
|
48
|
+
aria-roledescription="sortable"
|
|
49
|
+
class="pf-v5-c-button pf-m-plain"
|
|
50
|
+
role="button"
|
|
51
|
+
tabindex="0"
|
|
52
|
+
>
|
|
53
|
+
<span
|
|
54
|
+
class="pf-v5-c-data-list__item-draggable-icon"
|
|
55
|
+
>
|
|
56
|
+
<svg
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
class="pf-v5-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>
|
|
27
71
|
two
|
|
28
72
|
</div>
|
|
29
73
|
<div
|
|
30
|
-
aria-describedby="DndDescribedBy-0"
|
|
31
|
-
aria-disabled="false"
|
|
32
|
-
aria-roledescription="sortable"
|
|
33
74
|
class=""
|
|
34
|
-
role="button"
|
|
35
|
-
tabindex="0"
|
|
36
75
|
>
|
|
76
|
+
<button
|
|
77
|
+
aria-describedby="DndDescribedBy-0"
|
|
78
|
+
aria-disabled="false"
|
|
79
|
+
aria-label="Drag button"
|
|
80
|
+
aria-roledescription="sortable"
|
|
81
|
+
class="pf-v5-c-button pf-m-plain"
|
|
82
|
+
role="button"
|
|
83
|
+
tabindex="0"
|
|
84
|
+
>
|
|
85
|
+
<span
|
|
86
|
+
class="pf-v5-c-data-list__item-draggable-icon"
|
|
87
|
+
>
|
|
88
|
+
<svg
|
|
89
|
+
aria-hidden="true"
|
|
90
|
+
class="pf-v5-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>
|
|
37
103
|
three
|
|
38
104
|
</div>
|
|
39
105
|
</div>
|
|
@@ -15,18 +15,18 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
|
|
|
15
15
|
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
16
16
|
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
17
17
|
|
|
18
|
-
import { DragDropSort } from '@patternfly/react-drag-drop';
|
|
18
|
+
import { DragDropSort, DragDropContainer, Droppable as NewDroppable } from '@patternfly/react-drag-drop';
|
|
19
19
|
|
|
20
20
|
## Sorting examples
|
|
21
21
|
|
|
22
22
|
### Basic drag and drop sorting
|
|
23
23
|
|
|
24
|
-
```ts file="./
|
|
24
|
+
```ts file="./BasicSortingWithDragButton.tsx"
|
|
25
25
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
###
|
|
28
|
+
### Multiple drop zones
|
|
29
29
|
|
|
30
|
-
```ts file="./
|
|
30
|
+
```ts file="./DragDropContainerBasic.tsx"
|
|
31
31
|
|
|
32
32
|
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Droppable as NewDroppable,
|
|
4
|
+
DraggableObject,
|
|
5
|
+
DragDropContainer,
|
|
6
|
+
DragDropContainerDragOverEvent,
|
|
7
|
+
DragDropContainerDragEndEvent,
|
|
8
|
+
DragDropContainerDragCancelEvent
|
|
9
|
+
} from '@patternfly/react-drag-drop';
|
|
10
|
+
|
|
11
|
+
export const DragDropContainerBasic: React.FunctionComponent = () => {
|
|
12
|
+
const [allItems, setAllItems] = React.useState<Record<string, DraggableObject[]>>({
|
|
13
|
+
container1: [
|
|
14
|
+
{ id: 'button-1', content: 'one' },
|
|
15
|
+
{ id: 'button-2', content: 'two' },
|
|
16
|
+
{ id: 'button-3', content: 'three' }
|
|
17
|
+
],
|
|
18
|
+
container2: [
|
|
19
|
+
{ id: 'button-4', content: 'four' },
|
|
20
|
+
{ id: 'button-5', content: 'five' },
|
|
21
|
+
{ id: 'button-6', content: 'six' }
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<DragDropContainer
|
|
27
|
+
items={allItems}
|
|
28
|
+
onDrop={(_event: DragDropContainerDragEndEvent, newItems: Record<string, DraggableObject[]>) => {
|
|
29
|
+
setAllItems(newItems);
|
|
30
|
+
}}
|
|
31
|
+
onContainerMove={(_event: DragDropContainerDragOverEvent, newItems: Record<string, DraggableObject[]>) => {
|
|
32
|
+
setAllItems(newItems);
|
|
33
|
+
}}
|
|
34
|
+
onCancel={(_event: DragDropContainerDragCancelEvent, prevItems: Record<string, DraggableObject[]>) => {
|
|
35
|
+
setAllItems(prevItems);
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<h1>group 1</h1>
|
|
39
|
+
<NewDroppable items={allItems.container1} id="container1" />
|
|
40
|
+
<br />
|
|
41
|
+
<h1>group 2</h1>
|
|
42
|
+
<NewDroppable items={allItems.container2} id="container2" />
|
|
43
|
+
</DragDropContainer>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
DataList,
|
|
4
|
+
DataListCell,
|
|
5
|
+
DataListCheck,
|
|
6
|
+
DataListControl,
|
|
7
|
+
DataListItemCells,
|
|
8
|
+
Grid,
|
|
9
|
+
GridItem
|
|
10
|
+
} from '@patternfly/react-core';
|
|
11
|
+
import { DragDropContainer, DraggableObject, Droppable as NewDroppable } from '@patternfly/react-drag-drop';
|
|
12
|
+
|
|
13
|
+
const getItems = (from: number, count: number): DraggableObject[] =>
|
|
14
|
+
Array.from({ length: count }, (_, idx) => from + idx).map((idx) => ({
|
|
15
|
+
id: `data-list-item-${idx}`,
|
|
16
|
+
content: (
|
|
17
|
+
<>
|
|
18
|
+
<DataListControl>
|
|
19
|
+
<DataListCheck aria-labelledby={`item-${idx}`} name={`item-${idx}`} otherControls />
|
|
20
|
+
</DataListControl>
|
|
21
|
+
<DataListItemCells
|
|
22
|
+
dataListCells={[
|
|
23
|
+
<DataListCell key={`item-${idx}`}>
|
|
24
|
+
<span id={`item-${idx}`}>{`item-${idx}`}</span>
|
|
25
|
+
</DataListCell>
|
|
26
|
+
]}
|
|
27
|
+
/>
|
|
28
|
+
</>
|
|
29
|
+
)
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
export const DataListDraggable: React.FunctionComponent = (props) => {
|
|
33
|
+
const [items, setItems] = React.useState<Record<string, DraggableObject[]>>({
|
|
34
|
+
group1: getItems(0, 5),
|
|
35
|
+
group2: getItems(5, 5)
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<DragDropContainer
|
|
40
|
+
items={items}
|
|
41
|
+
onDrop={(_, newItems) => {
|
|
42
|
+
setItems(newItems);
|
|
43
|
+
}}
|
|
44
|
+
onContainerMove={(_, newItems) => {
|
|
45
|
+
setItems(newItems);
|
|
46
|
+
}}
|
|
47
|
+
onCancel={(_, prevItems) => {
|
|
48
|
+
setItems(prevItems);
|
|
49
|
+
}}
|
|
50
|
+
variant="DataList"
|
|
51
|
+
overlayProps={{ isCompact: true }}
|
|
52
|
+
>
|
|
53
|
+
<Grid hasGutter>
|
|
54
|
+
<GridItem span={6}>
|
|
55
|
+
<h1>group 1</h1>
|
|
56
|
+
<NewDroppable
|
|
57
|
+
id="group1"
|
|
58
|
+
items={items.group1}
|
|
59
|
+
variant="DataList"
|
|
60
|
+
wrapper={<DataList aria-label="draggable data list example" isCompact {...props} />}
|
|
61
|
+
/>
|
|
62
|
+
</GridItem>
|
|
63
|
+
<GridItem span={6}>
|
|
64
|
+
<h1>group 2</h1>
|
|
65
|
+
<NewDroppable
|
|
66
|
+
id="group2"
|
|
67
|
+
items={items.group2}
|
|
68
|
+
variant="DataList"
|
|
69
|
+
wrapper={<DataList aria-label="draggable data list example" isCompact {...props} />}
|
|
70
|
+
/>
|
|
71
|
+
</GridItem>
|
|
72
|
+
</Grid>
|
|
73
|
+
</DragDropContainer>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
DualListSelector,
|
|
4
|
+
DualListSelectorPane,
|
|
5
|
+
DualListSelectorList,
|
|
6
|
+
DualListSelectorControlsWrapper,
|
|
7
|
+
DualListSelectorControl
|
|
8
|
+
} from '@patternfly/react-core';
|
|
9
|
+
import { DragDropContainer, DraggableObject, Droppable as NewDroppable } from '@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
|
+
|
|
16
|
+
export const DragDropContainerDualListSelector: React.FunctionComponent = () => {
|
|
17
|
+
const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = React.useState(false);
|
|
18
|
+
const [availableOptions, setAvailableOptions] = React.useState<DraggableObject[]>([
|
|
19
|
+
{ id: 'Apple', content: 'Apple', props: { key: 'Apple', isSelected: false } },
|
|
20
|
+
{ id: 'Banana', content: 'Banana', props: { key: 'Banana', isSelected: false } },
|
|
21
|
+
{ id: 'Pineapple', content: 'Pineapple', props: { key: 'Pineapple', isSelected: false } }
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const [chosenOptions, setChosenOptions] = React.useState<DraggableObject[]>([
|
|
25
|
+
{ id: 'Orange', content: 'Orange', props: { key: 'Orange', isSelected: false } },
|
|
26
|
+
{ id: 'Grape', content: 'Grape', props: { key: 'Grape', isSelected: false } },
|
|
27
|
+
{ id: 'Peach', content: 'Peach', props: { key: 'Peach', isSelected: false } },
|
|
28
|
+
{ id: 'Strawberry', content: 'Strawberry', props: { key: 'Strawberry', isSelected: false } }
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const [allDraggableItems, setAllItems] = React.useState<Record<string, DraggableObject[]>>({
|
|
32
|
+
available: availableOptions.map((option, index) => ({
|
|
33
|
+
...option,
|
|
34
|
+
props: {
|
|
35
|
+
key: option.props.key,
|
|
36
|
+
isSelected: option.props.isSelected,
|
|
37
|
+
onOptionSelect: (e) => onOptionSelect(e, index, false)
|
|
38
|
+
}
|
|
39
|
+
})),
|
|
40
|
+
chosen: chosenOptions.map((option, index) => ({
|
|
41
|
+
...option,
|
|
42
|
+
props: {
|
|
43
|
+
key: option.props.key,
|
|
44
|
+
isSelected: option.props.isSelected,
|
|
45
|
+
onOptionSelect: (e) => onOptionSelect(e, index, true)
|
|
46
|
+
}
|
|
47
|
+
}))
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const handleDragOperation = (_event: any, items: Record<string, DraggableObject[]>) => {
|
|
51
|
+
setAvailableOptions(items.available);
|
|
52
|
+
setChosenOptions(items.chosen);
|
|
53
|
+
setAllItems(items);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
setAllItems({
|
|
58
|
+
available: availableOptions.map((option, index) => ({
|
|
59
|
+
...option,
|
|
60
|
+
props: {
|
|
61
|
+
key: option.props.key,
|
|
62
|
+
isSelected: option.props.isSelected,
|
|
63
|
+
onOptionSelect: (e) => onOptionSelect(e, index, false)
|
|
64
|
+
}
|
|
65
|
+
})),
|
|
66
|
+
chosen: chosenOptions.map((option, index) => ({
|
|
67
|
+
...option,
|
|
68
|
+
props: {
|
|
69
|
+
key: option.props.key,
|
|
70
|
+
isSelected: option.props.isSelected,
|
|
71
|
+
onOptionSelect: (e) => onOptionSelect(e, index, true)
|
|
72
|
+
}
|
|
73
|
+
}))
|
|
74
|
+
});
|
|
75
|
+
}, [availableOptions, chosenOptions]);
|
|
76
|
+
|
|
77
|
+
const moveSelected = (fromAvailable) => {
|
|
78
|
+
const sourceOptions = fromAvailable ? availableOptions : chosenOptions;
|
|
79
|
+
const destinationOptions = fromAvailable ? chosenOptions : availableOptions;
|
|
80
|
+
for (let i = 0; i < sourceOptions.length; i++) {
|
|
81
|
+
const option = sourceOptions[i];
|
|
82
|
+
if (option.props.isSelected) {
|
|
83
|
+
sourceOptions.splice(i, 1);
|
|
84
|
+
destinationOptions.push(option);
|
|
85
|
+
option.props.isSelected = false;
|
|
86
|
+
i--;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (fromAvailable) {
|
|
90
|
+
setAvailableOptions([...sourceOptions]);
|
|
91
|
+
setChosenOptions([...destinationOptions]);
|
|
92
|
+
} else {
|
|
93
|
+
setChosenOptions([...sourceOptions]);
|
|
94
|
+
setAvailableOptions([...destinationOptions]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const moveAll = (fromAvailable) => {
|
|
99
|
+
if (fromAvailable) {
|
|
100
|
+
setChosenOptions([...availableOptions, ...chosenOptions]);
|
|
101
|
+
setAvailableOptions([]);
|
|
102
|
+
} else {
|
|
103
|
+
setAvailableOptions([...chosenOptions, ...availableOptions]);
|
|
104
|
+
setChosenOptions([]);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const onOptionSelect = (event, index, isChosen) => {
|
|
109
|
+
if (ignoreNextOptionSelect) {
|
|
110
|
+
setIgnoreNextOptionSelect(false);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (isChosen) {
|
|
114
|
+
const newChosen = [...chosenOptions];
|
|
115
|
+
newChosen[index].props.isSelected = !chosenOptions[index].props.isSelected;
|
|
116
|
+
setChosenOptions(newChosen);
|
|
117
|
+
} else {
|
|
118
|
+
const newAvailable = [...availableOptions];
|
|
119
|
+
newAvailable[index].props.isSelected = !availableOptions[index].props.isSelected;
|
|
120
|
+
setAvailableOptions(newAvailable);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<DragDropContainer
|
|
126
|
+
items={allDraggableItems}
|
|
127
|
+
onDrop={handleDragOperation}
|
|
128
|
+
onContainerMove={handleDragOperation}
|
|
129
|
+
onCancel={handleDragOperation}
|
|
130
|
+
variant="DualListSelectorList"
|
|
131
|
+
>
|
|
132
|
+
<DualListSelector>
|
|
133
|
+
<DualListSelectorPane
|
|
134
|
+
title="Available"
|
|
135
|
+
status={`${availableOptions.filter((x) => x.props.isSelected).length} of ${
|
|
136
|
+
availableOptions.length
|
|
137
|
+
} options selected`}
|
|
138
|
+
>
|
|
139
|
+
<NewDroppable
|
|
140
|
+
id="available"
|
|
141
|
+
items={allDraggableItems.available}
|
|
142
|
+
variant="DualListSelectorList"
|
|
143
|
+
wrapper={<DualListSelectorList />}
|
|
144
|
+
/>
|
|
145
|
+
</DualListSelectorPane>
|
|
146
|
+
<DualListSelectorControlsWrapper aria-label="Selector controls">
|
|
147
|
+
<DualListSelectorControl
|
|
148
|
+
isDisabled={!availableOptions.some((option) => option.props.isSelected)}
|
|
149
|
+
onClick={() => moveSelected(true)}
|
|
150
|
+
aria-label="Add selected"
|
|
151
|
+
>
|
|
152
|
+
<AngleRightIcon />
|
|
153
|
+
</DualListSelectorControl>
|
|
154
|
+
<DualListSelectorControl
|
|
155
|
+
isDisabled={availableOptions.length === 0}
|
|
156
|
+
onClick={() => moveAll(true)}
|
|
157
|
+
aria-label="Add all"
|
|
158
|
+
>
|
|
159
|
+
<AngleDoubleRightIcon />
|
|
160
|
+
</DualListSelectorControl>
|
|
161
|
+
<DualListSelectorControl
|
|
162
|
+
isDisabled={chosenOptions.length === 0}
|
|
163
|
+
onClick={() => moveAll(false)}
|
|
164
|
+
aria-label="Remove all"
|
|
165
|
+
>
|
|
166
|
+
<AngleDoubleLeftIcon />
|
|
167
|
+
</DualListSelectorControl>
|
|
168
|
+
<DualListSelectorControl
|
|
169
|
+
onClick={() => moveSelected(false)}
|
|
170
|
+
isDisabled={!chosenOptions.some((option) => option.props.isSelected)}
|
|
171
|
+
aria-label="Remove selected"
|
|
172
|
+
>
|
|
173
|
+
<AngleLeftIcon />
|
|
174
|
+
</DualListSelectorControl>
|
|
175
|
+
</DualListSelectorControlsWrapper>
|
|
176
|
+
<DualListSelectorPane
|
|
177
|
+
title="Chosen"
|
|
178
|
+
status={`${chosenOptions.filter((x) => x.props.isSelected).length} of ${chosenOptions.length} options selected`}
|
|
179
|
+
isChosen
|
|
180
|
+
>
|
|
181
|
+
<NewDroppable
|
|
182
|
+
id="chosen"
|
|
183
|
+
items={allDraggableItems.chosen}
|
|
184
|
+
variant="DualListSelectorList"
|
|
185
|
+
wrapper={<DualListSelectorList />}
|
|
186
|
+
/>
|
|
187
|
+
</DualListSelectorPane>
|
|
188
|
+
</DualListSelector>
|
|
189
|
+
</DragDropContainer>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
@@ -14,7 +14,7 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
|
|
|
14
14
|
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
15
15
|
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
16
16
|
|
|
17
|
-
import { DragDropSort } from '@patternfly/react-drag-drop';
|
|
17
|
+
import { DragDropSort, DragDropContainer, Droppable as NewDroppable } from '@patternfly/react-drag-drop';
|
|
18
18
|
|
|
19
19
|
## Sorting demos
|
|
20
20
|
|
|
@@ -35,3 +35,27 @@ To enable reordering in a `<DualListSelector>` pane wrap the `<DualListSelectorL
|
|
|
35
35
|
```ts file="./DualListSelectorDraggable.tsx"
|
|
36
36
|
|
|
37
37
|
```
|
|
38
|
+
|
|
39
|
+
## Multiple drop zone demos
|
|
40
|
+
|
|
41
|
+
To enable multiple drop zones, wrap the component with `<DragDropContainer>`, place one or more `<Droppable>` components within the container, and define the `variant` property on all components. A collection of all draggable items should be passed to `<DragDropContainer>`, and each `<Droppable>` should be passed their respective draggable items.
|
|
42
|
+
|
|
43
|
+
`<Droppable>` will create the component's usual `children` internally based on the `items` property, so `children` should not be passed where the `<Droppable>` is defined.
|
|
44
|
+
|
|
45
|
+
To avoid a wrapping div inserted by `<Droppable>`, pass the desired container element to the `wrapper` property.
|
|
46
|
+
|
|
47
|
+
### Data list
|
|
48
|
+
|
|
49
|
+
To enable multiple drop zones with `<DataList>` components, place one or more `<Droppable>` within `<DragDropContainer>` and define the `variant` on all components as "DataList".
|
|
50
|
+
|
|
51
|
+
```ts file="./DragDropContainerDataList.tsx"
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Dual list selector
|
|
56
|
+
|
|
57
|
+
To enable multiple drop zones in a `<DualListSelector>`, wrap the `<DualListSelector>` component with `<DragDropContainer>`, and then include a `<Droppable>` component within each pane. Both `<DragDropContainer>` and `<Droppable>` should define the `variant` property as "DualListSelectorList".
|
|
58
|
+
|
|
59
|
+
```ts file="./DragDropContainerDualListSelector.tsx"
|
|
60
|
+
|
|
61
|
+
```
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DroppableContext.js","sourceRoot":"","sources":["../../../../../src/next/components/DragDrop/DroppableContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAC;IAClD,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,oBAAoB;CAClC,CAAC,CAAC"}
|
|
@@ -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,19 +0,0 @@
|
|
|
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
|
-
};
|