import { useState } from "react"; import { Plus } from "lucide-react"; import { motion, useReducedMotion } from "framer-motion"; import { useDroppable } from "@dnd-kit/core"; import { SortableContext, verticalListSortingStrategy, useSortable, } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { Button } from "@/components/ui/button"; import { ScrollArea } from "@/components/ui/scroll-area"; import { ColumnHeader } from "@/components/board/ColumnHeader"; import { AddCardInput } from "@/components/board/AddCardInput"; import { CardThumbnail } from "@/components/board/CardThumbnail"; import { useBoardStore } from "@/stores/board-store"; import type { Column } from "@/types/board"; const WIDTH_MAP = { narrow: 180, standard: 280, wide: 360, } as const; interface KanbanColumnProps { column: Column; onCardClick?: (cardId: string) => void; } export function KanbanColumn({ column, onCardClick }: KanbanColumnProps) { const [showAddCard, setShowAddCard] = useState(false); const board = useBoardStore((s) => s.board); const prefersReducedMotion = useReducedMotion(); const width = WIDTH_MAP[column.width]; // Make the column itself sortable (for column reordering) const { attributes, listeners, setNodeRef: setSortableNodeRef, transform, transition, isDragging, } = useSortable({ id: column.id, data: { type: "column" }, }); // Make the column a droppable target so empty columns can receive cards const { setNodeRef: setDroppableNodeRef } = useDroppable({ id: `column-droppable-${column.id}`, data: { type: "column", columnId: column.id }, }); const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : undefined, width, }; const cardCount = column.cardIds.length; return ( {/* The column header is the drag handle for column reordering */}
{/* Card list - wrapped in SortableContext for within-column sorting */}
    {column.cardIds.map((cardId) => { const card = board?.cards[cardId]; if (!card) return null; return (
  • ); })} {column.cardIds.length === 0 && (
  • Drop or add a card
  • )}
{/* Add card section */} {showAddCard ? ( setShowAddCard(false)} /> ) : (
)}
); }