"use client"; import React, { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; // import { Switch } from "@/components/ui/switch"; // import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { WebTypeConfigPanelProps } from "@/lib/registry/types"; import { WidgetComponent, TextTypeConfig } from "@/types/screen"; export const TextConfigPanel: React.FC = ({ component, onUpdateComponent, onUpdateProperty, }) => { const widget = component as WidgetComponent; const config = (widget.webTypeConfig as TextTypeConfig) || {}; // 로컬 상태 const [localConfig, setLocalConfig] = useState({ minLength: config.minLength || undefined, maxLength: config.maxLength || undefined, pattern: config.pattern || "", placeholder: config.placeholder || "", autoComplete: config.autoComplete || "off", format: config.format || "none", required: config.required || false, readonly: config.readonly || false, }); // 컴포넌트 변경 시 로컬 상태 동기화 useEffect(() => { const currentConfig = (widget.webTypeConfig as TextTypeConfig) || {}; setLocalConfig({ minLength: currentConfig.minLength || undefined, maxLength: currentConfig.maxLength || undefined, pattern: currentConfig.pattern || "", placeholder: currentConfig.placeholder || "", autoComplete: currentConfig.autoComplete || "off", format: currentConfig.format || "none", required: currentConfig.required || false, readonly: currentConfig.readonly || false, }); }, [widget.webTypeConfig]); // 설정 업데이트 핸들러 const updateConfig = (field: keyof TextTypeConfig, value: any) => { const newConfig = { ...localConfig, [field]: value }; setLocalConfig(newConfig); onUpdateProperty("webTypeConfig", newConfig); }; return ( 텍스트 설정 텍스트 입력 필드의 세부 설정을 관리합니다. {/* 기본 설정 */}

기본 설정

updateConfig("placeholder", e.target.value)} placeholder="입력 안내 텍스트" className="text-xs" />
updateConfig("minLength", e.target.value ? parseInt(e.target.value) : undefined)} placeholder="0" min="0" className="text-xs" />
updateConfig("maxLength", e.target.value ? parseInt(e.target.value) : undefined)} placeholder="100" min="1" className="text-xs" />
{/* 형식 설정 */}

형식 설정

updateConfig("pattern", e.target.value)} placeholder="예: [A-Za-z0-9]+" className="font-mono text-xs" />

JavaScript 정규식 패턴을 입력하세요.

{/* 상태 설정 */}

상태 설정

값이 입력되어야 합니다.

updateConfig("required", e.target.checked)} className="border-input bg-background text-primary focus:ring-ring h-4 w-4 rounded border focus:ring-2 focus:ring-offset-2" />

값을 수정할 수 없습니다.

updateConfig("readonly", e.target.checked)} className="border-input bg-background text-primary focus:ring-ring h-4 w-4 rounded border focus:ring-2 focus:ring-offset-2" />
{/* 미리보기 */}

미리보기

); }; TextConfigPanel.displayName = "TextConfigPanel";