import React, { memo, useMemo } from "react"; import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { BoardSortableList } from "./BoardSortableList"; import { BoardColumnTitle } from "./BoardColumnTitle"; import { BoardItem, BoardItemViewProps } from "./board_types"; import { IconButton } from "../../components"; import { cls } from "../../util"; import { iconSize, PlusIcon } from "../../icons"; export interface BoardColumnProps { id: string; title: string; items: BoardItem[]; index: number; ItemComponent: React.ComponentType>; isDragging: boolean; isDragOverColumn: boolean; allowReorder?: boolean; loading?: boolean; hasMore?: boolean; error?: Error; onLoadMore?: () => void; onAddItem?: () => void; totalCount?: number; color?: any; style?: React.CSSProperties; } export const BoardColumn = memo(function BoardColumn({ id, title, items, ItemComponent, isDragging, isDragOverColumn, allowReorder = false, loading = false, hasMore = false, error, onLoadMore, onAddItem, totalCount, color, style }: BoardColumnProps) { const { setNodeRef, attributes, listeners, isDragging: isColumnBeingDragged, transform, transition } = useSortable({ id, data: { type: "COLUMN" }, disabled: !allowReorder }); const combinedStyle = useMemo(() => ({ ...style, transform: CSS.Translate.toString(transform), transition, zIndex: isColumnBeingDragged ? 2 : 1 }), [style, transform, transition, isColumnBeingDragged]); const dragListeners = allowReorder ? listeners : {}; const columnClassName = useMemo(() => cls( "border h-full w-80 min-w-80 mx-2 flex flex-col rounded-md border-surface-200 dark:border-surface-800", isColumnBeingDragged ? "ring-2 ring-primary" : "" ), [isColumnBeingDragged]); const headerClassName = useMemo(() => cls( "flex items-center justify-between px-2 rounded-t-md transition-colors duration-200 ease-in-out", isColumnBeingDragged ? "bg-surface-100 dark:bg-surface-700" : "bg-surface-50 hover:bg-surface-100 dark:bg-surface-800 dark:hover:bg-surface-700", allowReorder ? "cursor-grab" : "" ), [isColumnBeingDragged, allowReorder]); const itemIds = useMemo(() => items.map(i => i.id), [items]); return (
{title} {totalCount !== undefined && ( {totalCount} )}
{onAddItem && ( { e.stopPropagation(); onAddItem(); }} className="opacity-60 hover:opacity-100" > )}
); }) as (props: BoardColumnProps) => React.ReactElement;