feat: raw boards dnd
This commit is contained in:
47
src/components/SortableDnd/SortableItem.tsx
Normal file
47
src/components/SortableDnd/SortableItem.tsx
Normal file
@ -0,0 +1,47 @@
|
||||
import React, { CSSProperties, PropsWithChildren, useMemo } from "react";
|
||||
import { useSortable } from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import DragHandle from "@/components/SortableDnd/DragHandle";
|
||||
import SortableItemContext from "./SortableItemContext";
|
||||
|
||||
type Props = {
|
||||
id: number;
|
||||
itemStyle?: CSSProperties;
|
||||
};
|
||||
|
||||
export const SortableItem = ({ children, id }: PropsWithChildren<Props>) => {
|
||||
const {
|
||||
attributes,
|
||||
isDragging,
|
||||
listeners,
|
||||
setNodeRef,
|
||||
setActivatorNodeRef,
|
||||
transform,
|
||||
transition,
|
||||
} = useSortable({ id });
|
||||
|
||||
const context = useMemo(
|
||||
() => ({
|
||||
attributes,
|
||||
listeners,
|
||||
ref: setActivatorNodeRef,
|
||||
}),
|
||||
[attributes, listeners, setActivatorNodeRef]
|
||||
);
|
||||
|
||||
const style: CSSProperties = {
|
||||
opacity: isDragging ? 0.4 : undefined,
|
||||
transform: CSS.Translate.toString(transform),
|
||||
transition,
|
||||
};
|
||||
|
||||
return (
|
||||
<SortableItemContext.Provider value={context}>
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
style={style}>
|
||||
<DragHandle>{children}</DragHandle>
|
||||
</div>
|
||||
</SortableItemContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user