-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiDraggable] Add support for reparenting dragged items (#8048)
- Loading branch information
Showing
21 changed files
with
614 additions
and
131 deletions.
There are no files selected for viewing
Binary file added
BIN
+19.7 KB
...ui/.loki/reference/chrome_desktop_Display_EuiDragDropContext_Within_Flyouts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.4 KB
...eui/.loki/reference/chrome_desktop_Display_EuiDragDropContext_Within_Modals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32 KB
...eui/.loki/reference/chrome_mobile_Display_EuiDragDropContext_Within_Flyouts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.9 KB
.../eui/.loki/reference/chrome_mobile_Display_EuiDragDropContext_Within_Modals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- Updated `EuiDraggable` with a new `usePortal` prop. | ||
- This prop portals the dragged element to the body, allowing it to escape stacking contexts which prevents buggy drag positioning in e.g. popovers, modals, and flyouts. | ||
|
||
**Deprecations** | ||
|
||
- Deprecated `EuiPopover`'s `hasDragDrop` prop. Use `EuiDraggable`'s new `usePortal` prop instead. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
packages/eui/src-docs/src/views/drag_and_drop/drag_and_drop_portal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import React, { FunctionComponent, ReactElement, useState } from 'react'; | ||
import { | ||
EuiButton, | ||
EuiDragDropContext, | ||
EuiDraggable, | ||
EuiDroppable, | ||
EuiFlyout, | ||
EuiFlyoutBody, | ||
EuiFlyoutHeader, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalHeader, | ||
EuiPanel, | ||
EuiPopover, | ||
EuiSpacer, | ||
EuiTitle, | ||
euiDragDropReorder, | ||
} from '../../../../src/components'; | ||
import { htmlIdGenerator } from '../../../../src/services'; | ||
import { DroppableProps, OnDragEndResponder } from '@hello-pangea/dnd'; | ||
|
||
const makeId = htmlIdGenerator(); | ||
|
||
const makeList = (number: number, start = 1) => | ||
Array.from({ length: number }, (v, k) => k + start).map((el) => { | ||
return { | ||
content: `Item ${el}`, | ||
id: makeId(), | ||
}; | ||
}); | ||
|
||
const DragContainer: FunctionComponent<{ | ||
children: ReactElement | ReactElement[] | DroppableProps['children']; | ||
onDragEnd: OnDragEndResponder; | ||
}> = ({ children, onDragEnd }) => ( | ||
<EuiDragDropContext onDragEnd={onDragEnd}> | ||
<EuiDroppable droppableId="DROPPABLE_AREA" spacing="m"> | ||
{children} | ||
</EuiDroppable> | ||
</EuiDragDropContext> | ||
); | ||
|
||
export default () => { | ||
const [isFlyoutOpen, setFlyoutOpen] = useState(false); | ||
const [isModalOpen, setModalOpen] = useState(false); | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const [list, setList] = useState(makeList(3)); | ||
const onDragEnd: OnDragEndResponder = ({ source, destination }) => { | ||
if (source && destination) { | ||
const items = euiDragDropReorder(list, source.index, destination.index); | ||
|
||
setList(items); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<EuiButton onClick={() => setFlyoutOpen(!isFlyoutOpen)}> | ||
Toggle flyout | ||
</EuiButton> | ||
<EuiSpacer /> | ||
<EuiButton onClick={() => setModalOpen(!isModalOpen)}> | ||
Toggle modal | ||
</EuiButton> | ||
|
||
{isFlyoutOpen && ( | ||
<EuiFlyout onClose={() => setFlyoutOpen(false)}> | ||
<EuiFlyoutHeader> | ||
<EuiTitle size="s"> | ||
<h2> | ||
Portalled <strong>EuiDraggable</strong> items | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody> | ||
<DragContainer onDragEnd={onDragEnd}> | ||
{list.map(({ content, id }, idx) => ( | ||
<EuiDraggable | ||
spacing="m" | ||
key={id} | ||
index={idx} | ||
draggableId={id} | ||
usePortal | ||
> | ||
{(provided, state) => ( | ||
<EuiPanel hasShadow={state.isDragging}> | ||
{content} | ||
{state.isDragging && ' ✨'} | ||
</EuiPanel> | ||
)} | ||
</EuiDraggable> | ||
))} | ||
</DragContainer> | ||
</EuiFlyoutBody> | ||
</EuiFlyout> | ||
)} | ||
|
||
{isModalOpen && ( | ||
<EuiModal onClose={() => setModalOpen(false)}> | ||
<EuiModalHeader> | ||
<EuiTitle size="s"> | ||
<h2> | ||
Portalled <strong>EuiDraggable</strong> items | ||
</h2> | ||
</EuiTitle> | ||
</EuiModalHeader> | ||
<EuiModalBody> | ||
<DragContainer onDragEnd={onDragEnd}> | ||
{list.map(({ content, id }, idx) => ( | ||
<EuiDraggable | ||
spacing="m" | ||
key={id} | ||
index={idx} | ||
draggableId={id} | ||
usePortal | ||
> | ||
{(provided, state) => ( | ||
<EuiPanel hasShadow={state.isDragging}> | ||
{content} | ||
{state.isDragging && ' ✨'} | ||
</EuiPanel> | ||
)} | ||
</EuiDraggable> | ||
))} | ||
</DragContainer> | ||
</EuiModalBody> | ||
</EuiModal> | ||
)} | ||
|
||
<EuiSpacer /> | ||
|
||
<EuiPopover | ||
isOpen={isPopoverOpen} | ||
closePopover={() => setIsPopoverOpen(false)} | ||
button={ | ||
<EuiButton onClick={() => setIsPopoverOpen(!isPopoverOpen)}> | ||
Toggle popover | ||
</EuiButton> | ||
} | ||
panelPaddingSize="none" | ||
panelProps={{ css: { inlineSize: 200 } }} | ||
> | ||
<DragContainer | ||
onDragEnd={({ source, destination }) => { | ||
if (source && destination) { | ||
const items = euiDragDropReorder( | ||
list, | ||
source.index, | ||
destination.index | ||
); | ||
setList(items); | ||
} | ||
}} | ||
> | ||
{list.map(({ content, id }, idx) => ( | ||
<EuiDraggable | ||
spacing="m" | ||
key={id} | ||
index={idx} | ||
draggableId={id} | ||
usePortal | ||
> | ||
{(provided, state) => ( | ||
<EuiPanel hasShadow={state.isDragging}>{content}</EuiPanel> | ||
)} | ||
</EuiDraggable> | ||
))} | ||
</DragContainer> | ||
</EuiPopover> | ||
</> | ||
); | ||
}; |
63 changes: 0 additions & 63 deletions
63
packages/eui/src-docs/src/views/drag_and_drop/in_popover.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.