import cx from "clsx"; import { Text } from "@mantine/core"; import { useListState } from "@mantine/hooks"; import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd"; import classes from "./DndList.module.css"; const data = [ { position: 6, mass: 12.011, symbol: "C", name: "Carbon" }, { position: 7, mass: 14.007, symbol: "N", name: "Nitrogen" }, { position: 39, mass: 88.906, symbol: "Y", name: "Yttrium" }, { position: 56, mass: 137.33, symbol: "Ba", name: "Barium" }, { position: 58, mass: 140.12, symbol: "Ce", name: "Cerium" }, ]; export function DndList() { const [state, handlers] = useListState(data); const items = (listIndex: number) => state.map((item, index) => ( {(provided, snapshot) => (
{item.symbol}
{item.name} Position: {item.position} • Mass: {item.mass}
)}
)); return ( handlers.reorder({ from: source.index, to: destination?.index || 0, }) }> {provided => (
{items(1)} {provided.placeholder}
)}
{provided => (
{items(2)} {provided.placeholder}
)}
); }