"use client"; import { useState } from "react"; import { useDrag } from "react-dnd"; import { Type, Table, Image, Minus, PenLine, Stamp as StampIcon, Hash, CreditCard, Calculator, Barcode, CheckSquare, ChevronRight, LayoutGrid, FileText, Database, } from "lucide-react"; interface ComponentItem { type: string; label: string; icon: React.ReactNode; } interface ComponentCategory { id: string; label: string; icon: React.ReactNode; items: ComponentItem[]; } const CATEGORIES: ComponentCategory[] = [ { id: "basic", label: "기본 요소", icon: , items: [ { type: "text", label: "텍스트", icon: }, { type: "image", label: "이미지", icon: }, { type: "divider", label: "구분선", icon: }, ], }, { id: "data", label: "데이터 표시", icon: , items: [ { type: "table", label: "테이블", icon: }, { type: "card", label: "정보카드", icon: }, { type: "calculation", label: "계산", icon: }, ], }, { id: "form", label: "입력/인증", icon: , items: [ { type: "checkbox", label: "체크박스", icon: }, { type: "signature", label: "서명란", icon: }, { type: "stamp", label: "도장란", icon: }, { type: "barcode", label: "바코드/QR", icon: }, ], }, ]; function DraggableComponentItem({ type, label, icon }: ComponentItem) { const [{ isDragging }, drag] = useDrag(() => ({ type: "component", item: { componentType: type }, collect: (monitor) => ({ isDragging: monitor.isDragging(), }), })); return (
{icon}
{label}
); } export function ComponentPalette() { const [expandedCategories, setExpandedCategories] = useState>( new Set(CATEGORIES.map((c) => c.id)), ); const toggleCategory = (id: string) => { setExpandedCategories((prev) => { const next = new Set(prev); if (next.has(id)) { next.delete(id); } else { next.add(id); } return next; }); }; return (
{CATEGORIES.map((category) => { const isExpanded = expandedCategories.has(category.id); return (
{isExpanded && (
{category.items.map((item) => ( ))}
)}
); })}
); }