-
Notifications
You must be signed in to change notification settings - Fork 854
[EuiDraggable] Add support for reparenting dragged items #8048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mgadewoll
merged 9 commits into
elastic:main
from
mgadewoll:draggable/8027-add-draggable-reparenting
Oct 1, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
902e41e
feat: add usePortal on EuiDraggable
mgadewoll b69b3cf
test(VRT): add VRT only stories for stacking context usages
mgadewoll e89fc1e
docs: add docs entries
mgadewoll 23ee7dd
chore: add changelog
mgadewoll 9536800
docs: update based on PR feedback
mgadewoll 5cd8461
test(VRT): clean up and DRY out VRT stories
mgadewoll 5fa1195
refactor: deprecate hasDragDrop on EuiPopover
mgadewoll 4828d33
chore: update changelog
mgadewoll f2261ea
docs: update copy and examples
mgadewoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.