-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathDragHandle.tsx
More file actions
48 lines (44 loc) · 1.53 KB
/
DragHandle.tsx
File metadata and controls
48 lines (44 loc) · 1.53 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
import DragIndicatorIcon from '@mui/icons-material/DragIndicator';
import { Box } from '@mui/material';
import { SxProps, Theme, useTheme } from '@mui/material/styles';
import { mergeSx } from '@mui/x-date-pickers/internals';
import { useContext } from 'react';
import { SortableItemContext } from '$components/drag-and-drop/SortableItem';
interface DragHandleProps {
disabled?: boolean;
iconSx?: SxProps<Theme>;
}
export function DragHandle({ disabled = false, iconSx }: DragHandleProps) {
const { attributes, listeners, ref } = useContext(SortableItemContext);
const theme = useTheme();
return (
<Box
{...attributes}
{...(disabled ? {} : listeners)}
ref={ref}
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: disabled ? 'auto' : 'pointer',
borderRadius: 1,
touchAction: 'none',
'&:hover': {
backgroundColor: disabled ? 'transparent' : 'rgba(0, 0, 0, 0.1)',
},
'&:focus-visible': {
boxShadow: disabled ? 'none' : '0 0 0 2px #4c9ffe',
},
}}
>
<DragIndicatorIcon
sx={mergeSx(
{
color: disabled ? 'gray' : theme.palette.mode === 'light' ? 'black' : 'white',
},
iconSx
)}
/>
</Box>
);
}