-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.tsx
More file actions
87 lines (85 loc) · 3.5 KB
/
Copy pathindex.tsx
File metadata and controls
87 lines (85 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Draggable, Droppable, DraggableProvided, DroppableProvided } from '@hello-pangea/dnd';
import { Box } from '@mui/material';
import React from 'react';
interface DroppableBoxProps {
children: React.ReactNode;
droppableId: string;
type?: string;
[prop: string]: unknown;
}
/**
* A wrapper around the Droppable component from @hello-pangea/dnd.
* It provides a consistent interface for creating droppable areas in drag-and-drop interfaces.
* @param {DroppableBoxProps} props - The properties for the droppable area.
* @param {string} props.droppableId - The unique identifier for the droppable area.
* @param {string} [props.type] - The type of the droppable area, used for grouping draggable items.
* @param {React.ReactNode} props.children - The content to be rendered inside the droppable area.
* @param {object} [props.rest] - Additional properties to be passed to the Box component.
* @returns {JSX.Element} A Box component that serves as a droppable area.
* @example
* <DroppableBox droppableId="droppable-1" type="TYPE_1">
* <DraggableBox draggableId="draggable-1" index={0}>
* <div>Draggable Item 1</div>
* </DraggableBox>
* <DraggableBox draggableId="draggable-2" index={1}>
* <div>Draggable Item 2</div>
* </DraggableBox>
* </DroppableBox>
*/
export const DroppableBox = ({ droppableId, type, children, ...rest }: DroppableBoxProps) => {
return (
<Droppable droppableId={droppableId} type={type}>
{(provided: DroppableProvided) => (
<Box {...provided.droppableProps} ref={provided.innerRef} {...rest}>
{children}
{provided.placeholder}
</Box>
)}
</Droppable>
);
};
interface DraggableBoxProps {
index: number;
children: React.ReactNode;
draggableId: string;
sx?: object;
}
/**
* A wrapper around the Draggable component from @hello-pangea/dnd.
* It provides a consistent interface for creating draggable items in drag-and-drop interfaces.
* @param {DraggableBoxProps} props - The properties for the draggable item.
* @param {number} props.index - The index of the draggable item within its droppable area.
* @param {React.ReactNode} props.children - The content to be rendered as the draggable item.
* @param {string} props.draggableId - The unique identifier for the draggable item.
* @param {object} [props.sx] - Additional styles to be applied to the draggable item.
* @returns {JSX.Element} A Box component that serves as a draggable item.
* @example
* <DroppableBox droppableId="droppable-1">
* <DraggableBox draggableId="draggable-1" index={0}>
* <div>Draggable Item 1</div>
* </DraggableBox>
* <DraggableBox draggableId="draggable-2" index={1}>
* <div>Draggable Item 2</div>
* </DraggableBox>
* </DroppableBox>
*/
export const DraggableBox = ({ children, draggableId, index, sx }: DraggableBoxProps) => {
return (
<Draggable key={draggableId} draggableId={draggableId} index={index}>
{(provided: DraggableProvided) => (
<Box
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
sx={{
marginBottom: '1em',
...provided.draggableProps.style,
...sx,
}}
>
{children}
</Box>
)}
</Draggable>
);
};