Refactor draggable list (#1874)

This commit is contained in:
Charles Bochet
2023-10-04 17:29:18 +02:00
committed by GitHub
parent f59dc75627
commit 13c8ee29f7
7 changed files with 78 additions and 40 deletions

View File

@ -0,0 +1,36 @@
import styled from '@emotion/styled';
import {
DragDropContext,
Droppable,
OnDragEndResponder,
} from '@hello-pangea/dnd';
import { v4 } from 'uuid';
type DraggableListProps = {
draggableItems: React.ReactNode;
onDragEnd: OnDragEndResponder;
};
const StyledDragDropItemsWrapper = styled.div`
width: 100%;
`;
export const DraggableList = ({
draggableItems,
onDragEnd,
}: DraggableListProps) => {
return (
<DragDropContext onDragEnd={onDragEnd}>
<StyledDragDropItemsWrapper>
<Droppable droppableId={v4()}>
{(provided) => (
<div ref={provided.innerRef} {...provided.droppableProps}>
{draggableItems}
{provided.placeholder}
</div>
)}
</Droppable>
</StyledDragDropItemsWrapper>
</DragDropContext>
);
};