feat: boards dnd editor for mobile
This commit is contained in:
@ -10,7 +10,7 @@ import React, {
|
||||
import { Active, DndContext, DragEndEvent } from "@dnd-kit/core";
|
||||
import { SortableContext } from "@dnd-kit/sortable";
|
||||
import { LexoRank } from "lexorank";
|
||||
import { Box, Group } from "@mantine/core";
|
||||
import { Box, Flex } from "@mantine/core";
|
||||
import useDndSensors from "@/app/deals/hooks/useSensors";
|
||||
import { SortableOverlay } from "@/components/dnd/SortableDnd/SortableOverlay";
|
||||
import SortableItem from "@/components/dnd/SortableItem";
|
||||
@ -25,9 +25,10 @@ type Props<T extends BaseItem> = {
|
||||
initialItems: T[];
|
||||
renderItem: (item: T) => ReactNode;
|
||||
onDragEnd: (itemId: number, newLexorank: string) => void;
|
||||
onItemClick: (item: T) => void;
|
||||
rowStyle?: CSSProperties;
|
||||
onItemClick?: (item: T) => void;
|
||||
containerStyle?: CSSProperties;
|
||||
itemStyle?: CSSProperties;
|
||||
vertical?: boolean;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
@ -36,8 +37,9 @@ const SortableDnd = <T extends BaseItem>({
|
||||
renderItem,
|
||||
onDragEnd,
|
||||
onItemClick,
|
||||
rowStyle,
|
||||
containerStyle,
|
||||
itemStyle,
|
||||
vertical,
|
||||
disabled = false,
|
||||
}: Props<T>) => {
|
||||
const [active, setActive] = useState<Active | null>(null);
|
||||
@ -100,14 +102,19 @@ const SortableDnd = <T extends BaseItem>({
|
||||
<SortableContext
|
||||
items={items}
|
||||
disabled={disabled}>
|
||||
<Group
|
||||
<Flex
|
||||
gap={0}
|
||||
style={rowStyle}
|
||||
style={{
|
||||
flexWrap: "nowrap",
|
||||
flexDirection: vertical ? "column" : "row",
|
||||
...containerStyle,
|
||||
}}
|
||||
role="application">
|
||||
{items.map((item, index) => (
|
||||
<Box
|
||||
key={index}
|
||||
onClick={e => {
|
||||
if (!onItemClick) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onItemClick(item);
|
||||
@ -121,7 +128,7 @@ const SortableDnd = <T extends BaseItem>({
|
||||
</SortableItem>
|
||||
</Box>
|
||||
))}
|
||||
</Group>
|
||||
</Flex>
|
||||
</SortableContext>
|
||||
<SortableOverlay>
|
||||
{activeItem ? renderItem(activeItem) : null}
|
||||
|
||||
Reference in New Issue
Block a user