"use client"; /** * V2TextDisplay 설정 패널 * 토스식 단계별 UX: 텍스트 내용 -> 폰트 설정(카드선택) -> 정렬(카드선택) -> 고급 설정(접힘) */ import React, { useState } from "react"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; import { Settings, ChevronDown, AlignLeft, AlignCenter, AlignRight, } from "lucide-react"; import { cn } from "@/lib/utils"; import { TextDisplayConfig } from "@/lib/registry/components/v2-text-display/types"; const FONT_SIZE_CARDS = [ { value: "12px", label: "작게", preview: "Aa" }, { value: "14px", label: "보통", preview: "Aa" }, { value: "18px", label: "크게", preview: "Aa" }, { value: "24px", label: "제목", preview: "Aa" }, ] as const; const FONT_WEIGHT_CARDS = [ { value: "lighter", label: "얇게" }, { value: "normal", label: "보통" }, { value: "bold", label: "굵게" }, ] as const; const ALIGN_CARDS = [ { value: "left", label: "왼쪽", icon: AlignLeft }, { value: "center", label: "가운데", icon: AlignCenter }, { value: "right", label: "오른쪽", icon: AlignRight }, ] as const; interface V2TextDisplayConfigPanelProps { config: TextDisplayConfig; onChange: (config: Partial) => void; } export const V2TextDisplayConfigPanel: React.FC = ({ config, onChange, }) => { const [advancedOpen, setAdvancedOpen] = useState(false); const updateConfig = (field: keyof TextDisplayConfig, value: any) => { const newConfig = { ...config, [field]: value }; onChange({ [field]: value }); if (typeof window !== "undefined") { window.dispatchEvent( new CustomEvent("componentConfigChanged", { detail: { config: newConfig }, }) ); } }; return (
{/* ─── 1단계: 표시 텍스트 ─── */}

표시 텍스트

updateConfig("text", e.target.value)} placeholder="표시할 텍스트를 입력하세요" className="h-8 text-sm" />

화면에 보여질 텍스트를 입력해요

{/* ─── 2단계: 폰트 크기 카드 선택 ─── */}

폰트 크기

{FONT_SIZE_CARDS.map((card) => { const isSelected = (config.fontSize || "14px") === card.value; return ( ); })}
직접 입력 updateConfig("fontSize", e.target.value)} placeholder="14px" className="h-7 w-[100px] text-xs" />
{/* ─── 3단계: 폰트 굵기 카드 선택 ─── */}

폰트 굵기

{FONT_WEIGHT_CARDS.map((card) => { const isSelected = (config.fontWeight || "normal") === card.value; return ( ); })}
{/* ─── 4단계: 텍스트 정렬 카드 선택 ─── */}

텍스트 정렬

{ALIGN_CARDS.map((card) => { const Icon = card.icon; const isSelected = (config.textAlign || "left") === card.value; return ( ); })}
{/* ─── 5단계: 텍스트 색상 ─── */}

텍스트 색상

{config.color || "#212121"}
updateConfig("color", e.target.value)} className="h-7 w-[60px] cursor-pointer p-0.5" />
{/* ─── 6단계: 고급 설정 (기본 접혀있음) ─── */}
{/* 배경색 */}
배경색
updateConfig("backgroundColor", e.target.value)} className="h-7 w-[60px] cursor-pointer p-0.5" />
{/* 패딩 */}
패딩 updateConfig("padding", e.target.value)} placeholder="8px" className="h-7 w-[100px] text-xs" />
{/* 모서리 둥글기 */}
모서리 둥글기 updateConfig("borderRadius", e.target.value)} placeholder="4px" className="h-7 w-[100px] text-xs" />
{/* 테두리 */}
테두리 updateConfig("border", e.target.value)} placeholder="1px solid #d1d5db" className="h-7 w-[140px] text-xs" />
{/* 비활성화 */}

비활성화

컴포넌트를 비활성화 상태로 만들어요

updateConfig("disabled", checked)} />
); }; V2TextDisplayConfigPanel.displayName = "V2TextDisplayConfigPanel"; export default V2TextDisplayConfigPanel;