import { useState } from "react"; import { Plus, Check } from "lucide-react"; import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { useBoardStore } from "@/stores/board-store"; import type { Label } from "@/types/board"; interface LabelPickerProps { cardId: string; cardLabelIds: string[]; boardLabels: Label[]; } const COLOR_SWATCHES = [ "#ef4444", // red "#f97316", // orange "#eab308", // yellow "#22c55e", // green "#06b6d4", // cyan "#3b82f6", // blue "#8b5cf6", // violet "#ec4899", // pink ]; export function LabelPicker({ cardId, cardLabelIds, boardLabels, }: LabelPickerProps) { const toggleCardLabel = useBoardStore((s) => s.toggleCardLabel); const addLabel = useBoardStore((s) => s.addLabel); const [newLabelName, setNewLabelName] = useState(""); const [newLabelColor, setNewLabelColor] = useState(COLOR_SWATCHES[0]); const [showCreate, setShowCreate] = useState(false); const currentLabels = boardLabels.filter((l) => cardLabelIds.includes(l.id)); function handleCreateLabel() { const trimmed = newLabelName.trim(); if (trimmed) { addLabel(trimmed, newLabelColor); setNewLabelName(""); setShowCreate(false); } } function handleCreateKeyDown(e: React.KeyboardEvent) { if (e.key === "Enter") { e.preventDefault(); handleCreateLabel(); } } return (
{/* Header */}

Labels

Toggle labels

{/* Existing labels */} {boardLabels.length > 0 && (
{boardLabels.map((label) => { const isSelected = cardLabelIds.includes(label.id); return ( ); })}
)} {/* Create new label */} {showCreate ? (
setNewLabelName(e.target.value)} onKeyDown={handleCreateKeyDown} placeholder="Label name..." className="h-7 rounded-md bg-pylon-column px-2 text-sm text-pylon-text outline-none placeholder:text-pylon-text-secondary/60 focus:ring-1 focus:ring-pylon-accent" />
{COLOR_SWATCHES.map((color) => (
) : ( )}
{/* Current labels display */} {currentLabels.length > 0 ? (
{currentLabels.map((label) => ( {label.name} ))}
) : (

No labels

)}
); }