@patternfly/react-drag-drop 6.0.0-alpha.6 → 6.0.0-alpha.61
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 +474 -0
- package/dist/cjs.tsbuildinfo +1 -1
- package/dist/esm/components/DragDrop/DragButton.d.ts +11 -0
- package/dist/esm/components/DragDrop/DragButton.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DragButton.js +14 -0
- package/dist/esm/components/DragDrop/DragButton.js.map +1 -0
- package/dist/esm/components/DragDrop/DragDropSort.d.ts +35 -0
- package/dist/esm/components/DragDrop/DragDropSort.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DragDropSort.js +70 -0
- package/dist/esm/components/DragDrop/DragDropSort.js.map +1 -0
- package/dist/esm/components/DragDrop/Draggable.d.ts +13 -0
- package/dist/esm/components/DragDrop/Draggable.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/Draggable.js +22 -0
- package/dist/esm/components/DragDrop/Draggable.js.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts +15 -0
- package/dist/esm/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDataListItem.js +26 -0
- package/dist/esm/components/DragDrop/DraggableDataListItem.js.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts +23 -0
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js +37 -0
- package/dist/esm/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
- package/dist/esm/components/DragDrop/Droppable.d.ts +16 -0
- package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/Droppable.js +11 -0
- package/dist/esm/components/DragDrop/Droppable.js.map +1 -0
- package/dist/esm/components/DragDrop/DroppableContext.d.ts +6 -0
- package/dist/esm/components/DragDrop/DroppableContext.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/DroppableContext.js +6 -0
- package/dist/esm/components/DragDrop/DroppableContext.js.map +1 -0
- package/dist/esm/components/DragDrop/index.d.ts +2 -0
- package/dist/esm/components/DragDrop/index.d.ts.map +1 -0
- package/dist/esm/components/DragDrop/index.js +2 -0
- package/dist/esm/components/DragDrop/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.d.ts.map +1 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts +2 -2
- package/dist/esm/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.js +4 -1
- package/dist/esm/next/components/DragDrop/DragDropSort.js.map +1 -1
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js +1 -1
- package/dist/esm/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
- package/dist/esm.tsbuildinfo +1 -1
- package/dist/js/components/DragDrop/DragButton.d.ts +11 -0
- package/dist/js/components/DragDrop/DragButton.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DragButton.js +18 -0
- package/dist/js/components/DragDrop/DragButton.js.map +1 -0
- package/dist/js/components/DragDrop/DragDropSort.d.ts +35 -0
- package/dist/js/components/DragDrop/DragDropSort.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DragDropSort.js +74 -0
- package/dist/js/components/DragDrop/DragDropSort.js.map +1 -0
- package/dist/js/components/DragDrop/Draggable.d.ts +13 -0
- package/dist/js/components/DragDrop/Draggable.d.ts.map +1 -0
- package/dist/js/components/DragDrop/Draggable.js +26 -0
- package/dist/js/components/DragDrop/Draggable.js.map +1 -0
- package/dist/js/components/DragDrop/DraggableDataListItem.d.ts +15 -0
- package/dist/js/components/DragDrop/DraggableDataListItem.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DraggableDataListItem.js +30 -0
- package/dist/js/components/DragDrop/DraggableDataListItem.js.map +1 -0
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts +23 -0
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js +41 -0
- package/dist/js/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -0
- package/dist/js/components/DragDrop/Droppable.d.ts +16 -0
- package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -0
- package/dist/js/components/DragDrop/Droppable.js +15 -0
- package/dist/js/components/DragDrop/Droppable.js.map +1 -0
- package/dist/js/components/DragDrop/DroppableContext.d.ts +6 -0
- package/dist/js/components/DragDrop/DroppableContext.d.ts.map +1 -0
- package/dist/js/components/DragDrop/DroppableContext.js +10 -0
- package/dist/js/components/DragDrop/DroppableContext.js.map +1 -0
- package/dist/js/components/DragDrop/index.d.ts +2 -0
- package/dist/js/components/DragDrop/index.d.ts.map +1 -0
- package/dist/js/components/DragDrop/index.js +5 -0
- package/dist/js/components/DragDrop/index.js.map +1 -0
- package/dist/js/components/index.d.ts +2 -0
- package/dist/js/components/index.d.ts.map +1 -0
- package/dist/js/components/index.js +5 -0
- package/dist/js/components/index.js.map +1 -0
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.d.ts.map +1 -1
- package/dist/js/index.js +1 -1
- package/dist/js/index.js.map +1 -1
- package/dist/js/next/components/DragDrop/DragButton.js.map +1 -1
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts +2 -2
- package/dist/js/next/components/DragDrop/DragDropSort.d.ts.map +1 -1
- package/dist/js/next/components/DragDrop/DragDropSort.js +4 -1
- package/dist/js/next/components/DragDrop/DragDropSort.js.map +1 -1
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js +1 -1
- package/dist/js/next/components/DragDrop/DraggableDualListSelectorListItem.js.map +1 -1
- package/package.json +5 -10
- package/src/components/DragDrop/DragButton.tsx +27 -0
- package/src/components/DragDrop/DragDropSort.tsx +182 -0
- package/src/components/DragDrop/Draggable.tsx +58 -0
- package/src/components/DragDrop/DraggableDataListItem.tsx +61 -0
- package/src/components/DragDrop/DraggableDualListSelectorListItem.tsx +93 -0
- package/src/components/DragDrop/Droppable.tsx +27 -0
- package/src/components/DragDrop/DroppableContext.ts +6 -0
- package/src/components/DragDrop/__tests__/DragDrop.test.tsx +19 -0
- package/src/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +125 -0
- package/src/components/DragDrop/examples/BasicSortingWithDragButton.tsx +19 -0
- package/src/components/DragDrop/examples/DataListDraggable.tsx +38 -0
- package/src/components/DragDrop/examples/DragDrop.md +26 -0
- package/src/components/DragDrop/examples/DragDropDemos.md +37 -0
- package/src/components/DragDrop/examples/DualListSelectorDraggable.tsx +150 -0
- package/src/components/DragDrop/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/next/components/DragDrop/DragDropSort.tsx +5 -1
- package/src/next/components/DragDrop/DraggableDualListSelectorListItem.tsx +1 -1
- package/src/next/components/DragDrop/__tests__/DragDrop.test.tsx +5 -0
- package/src/next/components/DragDrop/examples/DualListSelectorDraggable.tsx +8 -12
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataList, DataListCell, DataListCheck, DataListControl, DataListItemCells } from '@patternfly/react-core';
|
|
3
|
+
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
4
|
+
|
|
5
|
+
const getItems = (count: number): DraggableObject[] =>
|
|
6
|
+
Array.from({ length: count }, (_, idx) => idx).map((idx) => ({
|
|
7
|
+
id: `data-list-item-${idx}`,
|
|
8
|
+
content: (
|
|
9
|
+
<>
|
|
10
|
+
<DataListControl>
|
|
11
|
+
<DataListCheck aria-labelledby={`item-${idx}`} name={`item-${idx}`} otherControls />
|
|
12
|
+
</DataListControl>
|
|
13
|
+
<DataListItemCells
|
|
14
|
+
dataListCells={[
|
|
15
|
+
<DataListCell key={`item-${idx}`}>
|
|
16
|
+
<span id={`item-${idx}`}>{`item-${idx}`}</span>
|
|
17
|
+
</DataListCell>
|
|
18
|
+
]}
|
|
19
|
+
/>
|
|
20
|
+
</>
|
|
21
|
+
)
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
export const DataListDraggable: React.FunctionComponent = (props) => {
|
|
25
|
+
const [items, setItems] = React.useState<DraggableObject[]>(getItems(10));
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<DragDropSort
|
|
29
|
+
items={items}
|
|
30
|
+
onDrop={(_, newItems) => {
|
|
31
|
+
setItems(newItems);
|
|
32
|
+
}}
|
|
33
|
+
variant="DataList"
|
|
34
|
+
>
|
|
35
|
+
<DataList aria-label="draggable data list example" isCompact {...props} />
|
|
36
|
+
</DragDropSort>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Drag and drop
|
|
3
|
+
section: components
|
|
4
|
+
cssPrefix: pf-c-drag-drop
|
|
5
|
+
propComponents: ['DragDropSort', 'DraggableObject']
|
|
6
|
+
hideNavItem: true
|
|
7
|
+
beta: true
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Note: This drag and drop implementation lives in its own package at [@patternfly/react-drag-drop](https://www.npmjs.com/package/@patternfly/react-drag-drop)!
|
|
11
|
+
|
|
12
|
+
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
13
|
+
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
14
|
+
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
15
|
+
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
16
|
+
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
17
|
+
|
|
18
|
+
import { DragDropSort } from '@patternfly/react-drag-drop';
|
|
19
|
+
|
|
20
|
+
## Sorting examples
|
|
21
|
+
|
|
22
|
+
### Basic drag and drop sorting
|
|
23
|
+
|
|
24
|
+
```ts file="./BasicSortingWithDragButton.tsx"
|
|
25
|
+
|
|
26
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Drag and drop
|
|
3
|
+
section: components
|
|
4
|
+
source: react-demos
|
|
5
|
+
propComponents: ['DragDropSort', 'DraggableObject']
|
|
6
|
+
beta: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
Note: This drag and drop implementation lives in its own package at [@patternfly/react-drag-drop](https://www.npmjs.com/package/@patternfly/react-drag-drop)!
|
|
10
|
+
|
|
11
|
+
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
12
|
+
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
13
|
+
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
14
|
+
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
15
|
+
import PficonSortCommonAscIcon from '@patternfly/react-icons/dist/esm/icons/pficon-sort-common-asc-icon';
|
|
16
|
+
|
|
17
|
+
import { DragDropSort } from '@patternfly/react-drag-drop';
|
|
18
|
+
|
|
19
|
+
## Sorting demos
|
|
20
|
+
|
|
21
|
+
To enable drag and drop for compatible components, wrap the component with `<DragDropSort>`, define the `variant` property, and pass both the sortable `items` and `onDrop` callback to `<DragDropSort>`. `<DragDropSort>` will create the component's usual `children` internally based on the `items` property, so `children` should not be passed to the wrapped component.
|
|
22
|
+
|
|
23
|
+
### Drag and drop sortable data list
|
|
24
|
+
|
|
25
|
+
To enable reordering in a `<DataList>`, wrap the `<DataList>` component with `<DragDropSort>` and define the `variant` as "DataList".
|
|
26
|
+
|
|
27
|
+
```ts file="./DataListDraggable.tsx"
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Drag and drop sortable dual list selector
|
|
32
|
+
|
|
33
|
+
To enable reordering in a `<DualListSelector>` pane wrap the `<DualListSelectorList>` component with `<DragDropSort>` and define the `variant` as "DualListSelectorList".
|
|
34
|
+
|
|
35
|
+
```ts file="./DualListSelectorDraggable.tsx"
|
|
36
|
+
|
|
37
|
+
```
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
DualListSelector,
|
|
4
|
+
DualListSelectorPane,
|
|
5
|
+
DualListSelectorList,
|
|
6
|
+
DualListSelectorListItem,
|
|
7
|
+
DualListSelectorControlsWrapper,
|
|
8
|
+
DualListSelectorControl
|
|
9
|
+
} from '@patternfly/react-core';
|
|
10
|
+
import { DragDropSort, DraggableObject } from '@patternfly/react-drag-drop';
|
|
11
|
+
|
|
12
|
+
import AngleDoubleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-left-icon';
|
|
13
|
+
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
14
|
+
import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon';
|
|
15
|
+
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
16
|
+
|
|
17
|
+
export const ComposableDualListSelector: React.FunctionComponent = () => {
|
|
18
|
+
const [ignoreNextOptionSelect, setIgnoreNextOptionSelect] = React.useState(false);
|
|
19
|
+
const [availableOptions, setAvailableOptions] = React.useState<DraggableObject[]>([
|
|
20
|
+
{ id: 'Apple', content: 'Apple', props: { key: 'Apple', isSelected: false } },
|
|
21
|
+
{ id: 'Banana', content: 'Banana', props: { key: 'Banana', isSelected: false } },
|
|
22
|
+
{ id: 'Pineapple', content: 'Pineapple', props: { key: 'Pineapple', isSelected: false } }
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const [chosenOptions, setChosenOptions] = React.useState<DraggableObject[]>([
|
|
26
|
+
{ id: 'Orange', content: 'Orange', props: { key: 'Orange', isSelected: false } },
|
|
27
|
+
{ id: 'Grape', content: 'Grape', props: { key: 'Grape', isSelected: false } },
|
|
28
|
+
{ id: 'Peach', content: 'Peach', props: { key: 'Peach', isSelected: false } },
|
|
29
|
+
{ id: 'Strawberry', content: 'Strawberry', props: { key: 'Strawberry', isSelected: false } }
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const moveSelected = (fromAvailable) => {
|
|
33
|
+
const sourceOptions = fromAvailable ? availableOptions : chosenOptions;
|
|
34
|
+
const destinationOptions = fromAvailable ? chosenOptions : availableOptions;
|
|
35
|
+
for (let i = 0; i < sourceOptions.length; i++) {
|
|
36
|
+
const option = sourceOptions[i];
|
|
37
|
+
if (option.props.isSelected) {
|
|
38
|
+
sourceOptions.splice(i, 1);
|
|
39
|
+
destinationOptions.push(option);
|
|
40
|
+
option.props.isSelected = false;
|
|
41
|
+
i--;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (fromAvailable) {
|
|
45
|
+
setAvailableOptions([...sourceOptions]);
|
|
46
|
+
setChosenOptions([...destinationOptions]);
|
|
47
|
+
} else {
|
|
48
|
+
setChosenOptions([...sourceOptions]);
|
|
49
|
+
setAvailableOptions([...destinationOptions]);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const moveAll = (fromAvailable) => {
|
|
54
|
+
if (fromAvailable) {
|
|
55
|
+
setChosenOptions([...availableOptions, ...chosenOptions]);
|
|
56
|
+
setAvailableOptions([]);
|
|
57
|
+
} else {
|
|
58
|
+
setAvailableOptions([...chosenOptions, ...availableOptions]);
|
|
59
|
+
setChosenOptions([]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const onOptionSelect = (event, index, isChosen) => {
|
|
64
|
+
if (ignoreNextOptionSelect) {
|
|
65
|
+
setIgnoreNextOptionSelect(false);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (isChosen) {
|
|
69
|
+
const newChosen = [...chosenOptions];
|
|
70
|
+
newChosen[index].props.isSelected = !chosenOptions[index].props.isSelected;
|
|
71
|
+
setChosenOptions(newChosen);
|
|
72
|
+
} else {
|
|
73
|
+
const newAvailable = [...availableOptions];
|
|
74
|
+
newAvailable[index].props.isSelected = !availableOptions[index].props.isSelected;
|
|
75
|
+
setAvailableOptions(newAvailable);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<DualListSelector>
|
|
81
|
+
<DualListSelectorPane
|
|
82
|
+
title="Available"
|
|
83
|
+
status={`${availableOptions.filter((x) => x.props.isSelected).length} of ${
|
|
84
|
+
availableOptions.length
|
|
85
|
+
} options selected`}
|
|
86
|
+
>
|
|
87
|
+
<DualListSelectorList>
|
|
88
|
+
{availableOptions.map((option, index) => (
|
|
89
|
+
<DualListSelectorListItem
|
|
90
|
+
key={index}
|
|
91
|
+
isSelected={option.props.isSelected}
|
|
92
|
+
id={`composable-available-option-${option.content}`}
|
|
93
|
+
onOptionSelect={(e) => onOptionSelect(e, index, false)}
|
|
94
|
+
>
|
|
95
|
+
{option.content}
|
|
96
|
+
</DualListSelectorListItem>
|
|
97
|
+
))}
|
|
98
|
+
</DualListSelectorList>
|
|
99
|
+
</DualListSelectorPane>
|
|
100
|
+
<DualListSelectorControlsWrapper aria-label="Selector controls">
|
|
101
|
+
<DualListSelectorControl
|
|
102
|
+
isDisabled={!availableOptions.some((option) => option.props.isSelected)}
|
|
103
|
+
onClick={() => moveSelected(true)}
|
|
104
|
+
aria-label="Add selected"
|
|
105
|
+
icon={<AngleRightIcon />}
|
|
106
|
+
/>
|
|
107
|
+
<DualListSelectorControl
|
|
108
|
+
isDisabled={availableOptions.length === 0}
|
|
109
|
+
onClick={() => moveAll(true)}
|
|
110
|
+
aria-label="Add all"
|
|
111
|
+
icon={<AngleDoubleRightIcon />}
|
|
112
|
+
/>
|
|
113
|
+
<DualListSelectorControl
|
|
114
|
+
isDisabled={chosenOptions.length === 0}
|
|
115
|
+
onClick={() => moveAll(false)}
|
|
116
|
+
aria-label="Remove all"
|
|
117
|
+
icon={<AngleDoubleLeftIcon />}
|
|
118
|
+
/>
|
|
119
|
+
<DualListSelectorControl
|
|
120
|
+
onClick={() => moveSelected(false)}
|
|
121
|
+
isDisabled={!chosenOptions.some((option) => option.props.isSelected)}
|
|
122
|
+
aria-label="Remove selected"
|
|
123
|
+
icon={<AngleLeftIcon />}
|
|
124
|
+
/>
|
|
125
|
+
</DualListSelectorControlsWrapper>
|
|
126
|
+
<DualListSelectorPane
|
|
127
|
+
title="Chosen"
|
|
128
|
+
status={`${chosenOptions.filter((x) => x.props.isSelected).length} of ${chosenOptions.length} options selected`}
|
|
129
|
+
isChosen
|
|
130
|
+
>
|
|
131
|
+
<DragDropSort
|
|
132
|
+
items={chosenOptions.map((option, index) => ({
|
|
133
|
+
...option,
|
|
134
|
+
props: {
|
|
135
|
+
key: option.props.key,
|
|
136
|
+
isSelected: option.props.isSelected,
|
|
137
|
+
onOptionSelect: (e) => onOptionSelect(e, index, true)
|
|
138
|
+
}
|
|
139
|
+
}))}
|
|
140
|
+
onDrop={(_, newItems) => {
|
|
141
|
+
setChosenOptions(newItems);
|
|
142
|
+
}}
|
|
143
|
+
variant="DualListSelectorList"
|
|
144
|
+
>
|
|
145
|
+
<DualListSelectorList />
|
|
146
|
+
</DragDropSort>
|
|
147
|
+
</DualListSelectorPane>
|
|
148
|
+
</DualListSelector>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DragDropSort';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DragDrop';
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './components';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import * as ReactDOM from 'react-dom';
|
|
2
3
|
import { css } from '@patternfly/react-styles';
|
|
3
4
|
import {
|
|
4
5
|
DndContext,
|
|
@@ -22,6 +23,7 @@ import { Draggable } from './Draggable';
|
|
|
22
23
|
import { DraggableDataListItem } from './DraggableDataListItem';
|
|
23
24
|
import { DraggableDualListSelectorListItem } from './DraggableDualListSelectorListItem';
|
|
24
25
|
import styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
26
|
+
import { canUseDOM } from '@patternfly/react-core';
|
|
25
27
|
|
|
26
28
|
export type DragDropSortDragEndEvent = DragEndEvent;
|
|
27
29
|
export type DragDropSortDragStartEvent = DragStartEvent;
|
|
@@ -135,6 +137,8 @@ export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
|
|
|
135
137
|
);
|
|
136
138
|
};
|
|
137
139
|
|
|
140
|
+
const dragOverlay = <DragOverlay>{activeId && getDragOverlay()}</DragOverlay>;
|
|
141
|
+
|
|
138
142
|
const renderedChildren = (
|
|
139
143
|
<SortableContext items={itemIds} strategy={verticalListSortingStrategy} id="droppable">
|
|
140
144
|
{items.map((item: DraggableObject) => {
|
|
@@ -159,7 +163,7 @@ export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
|
|
|
159
163
|
);
|
|
160
164
|
}
|
|
161
165
|
})}
|
|
162
|
-
|
|
166
|
+
{canUseDOM ? ReactDOM.createPortal(dragOverlay, document.getElementById('root')) : dragOverlay}
|
|
163
167
|
</SortableContext>
|
|
164
168
|
);
|
|
165
169
|
|
|
@@ -5,7 +5,7 @@ import { css } from '@patternfly/react-styles';
|
|
|
5
5
|
import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
|
|
6
6
|
import dragStyles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
|
|
7
7
|
import { DragButton } from './DragButton';
|
|
8
|
-
import { DualListSelectorListContext } from '@patternfly/react-core/dist/esm/components/DualListSelector';
|
|
8
|
+
import { DualListSelectorListContext } from '@patternfly/react-core/dist/esm/deprecated/components/DualListSelector';
|
|
9
9
|
|
|
10
10
|
export interface DraggableDualListSelectorListItemProps extends React.HTMLProps<HTMLLIElement> {
|
|
11
11
|
/** Content rendered inside DragDrop */
|
|
@@ -2,6 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { DragDropSort } from '../';
|
|
4
4
|
|
|
5
|
+
jest.mock('react-dom', () => ({
|
|
6
|
+
...jest.requireActual('react-dom'),
|
|
7
|
+
createPortal: jest.fn((node) => node)
|
|
8
|
+
}));
|
|
9
|
+
|
|
5
10
|
test('renders some divs', () => {
|
|
6
11
|
const { asFragment } = render(
|
|
7
12
|
<div className="pf-c-droppable pf-m-dragging">
|
|
@@ -102,30 +102,26 @@ export const ComposableDualListSelector: React.FunctionComponent = () => {
|
|
|
102
102
|
isDisabled={!availableOptions.some((option) => option.props.isSelected)}
|
|
103
103
|
onClick={() => moveSelected(true)}
|
|
104
104
|
aria-label="Add selected"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
</DualListSelectorControl>
|
|
105
|
+
icon={<AngleRightIcon />}
|
|
106
|
+
/>
|
|
108
107
|
<DualListSelectorControl
|
|
109
108
|
isDisabled={availableOptions.length === 0}
|
|
110
109
|
onClick={() => moveAll(true)}
|
|
111
110
|
aria-label="Add all"
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
</DualListSelectorControl>
|
|
111
|
+
icon={<AngleDoubleRightIcon />}
|
|
112
|
+
/>
|
|
115
113
|
<DualListSelectorControl
|
|
116
114
|
isDisabled={chosenOptions.length === 0}
|
|
117
115
|
onClick={() => moveAll(false)}
|
|
118
116
|
aria-label="Remove all"
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
</DualListSelectorControl>
|
|
117
|
+
icon={<AngleDoubleLeftIcon />}
|
|
118
|
+
/>
|
|
122
119
|
<DualListSelectorControl
|
|
123
120
|
onClick={() => moveSelected(false)}
|
|
124
121
|
isDisabled={!chosenOptions.some((option) => option.props.isSelected)}
|
|
125
122
|
aria-label="Remove selected"
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
</DualListSelectorControl>
|
|
123
|
+
icon={<AngleLeftIcon />}
|
|
124
|
+
/>
|
|
129
125
|
</DualListSelectorControlsWrapper>
|
|
130
126
|
<DualListSelectorPane
|
|
131
127
|
title="Chosen"
|