@patternfly/react-drag-drop 5.4.0-prerelease.22 → 5.4.0-prerelease.24
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 +10 -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 +3 -8
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.js +12 -62
- package/dist/esm/next/components/DragDrop/DragDropSort.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/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 +3 -8
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
- package/dist/js/next/components/DragDrop/DragDropSort.js +12 -62
- package/dist/js/next/components/DragDrop/DragDropSort.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 +3 -3
- package/src/next/components/DragDrop/DragDropContainer.tsx +305 -0
- package/src/next/components/DragDrop/DragDropSort.tsx +21 -147
- package/src/next/components/DragDrop/Droppable.tsx +69 -15
- package/src/next/components/DragDrop/examples/DataListDraggable.tsx +1 -0
- package/src/next/components/DragDrop/examples/DragDrop.md +7 -1
- 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
|
@@ -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"}
|