"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 { Switch } from "@/components/ui/switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Button } from "@/components/ui/button"; import { Calendar } from "lucide-react"; import { WebTypeConfigPanelProps } from "@/lib/registry/types"; import { WidgetComponent, DateTypeConfig } from "@/types/screen"; export const DateConfigPanel: React.FC = ({ component, onUpdateComponent, onUpdateProperty, }) => { const widget = component as WidgetComponent; const config = (widget.webTypeConfig as DateTypeConfig) || {}; // 로컬 상태 const [localConfig, setLocalConfig] = useState({ format: config.format || "YYYY-MM-DD", showTime: config.showTime || false, minDate: config.minDate || "", maxDate: config.maxDate || "", defaultValue: config.defaultValue || "", placeholder: config.placeholder || "", required: config.required || false, readonly: config.readonly || false, }); // 컴포넌트 변경 시 로컬 상태 동기화 useEffect(() => { const currentConfig = (widget.webTypeConfig as DateTypeConfig) || {}; setLocalConfig({ format: currentConfig.format || "YYYY-MM-DD", showTime: currentConfig.showTime || false, minDate: currentConfig.minDate || "", maxDate: currentConfig.maxDate || "", defaultValue: currentConfig.defaultValue || "", placeholder: currentConfig.placeholder || "", required: currentConfig.required || false, readonly: currentConfig.readonly || false, }); }, [widget.webTypeConfig]); // 설정 업데이트 핸들러 const updateConfig = (field: keyof DateTypeConfig, value: any) => { const newConfig = { ...localConfig, [field]: value }; setLocalConfig(newConfig); onUpdateProperty("webTypeConfig", newConfig); }; // 현재 날짜 설정 const setCurrentDate = (field: "minDate" | "maxDate" | "defaultValue") => { const now = new Date(); const dateString = localConfig.showTime ? now.toISOString().slice(0, 16) // YYYY-MM-DDTHH:mm : now.toISOString().slice(0, 10); // YYYY-MM-DD updateConfig(field, dateString); }; // 날짜 형식 옵션 const formatOptions = [ { value: "YYYY-MM-DD", label: "2024-12-25", description: "ISO 표준 형식" }, { value: "YYYY-MM-DD HH:mm", label: "2024-12-25 14:30", description: "날짜 + 시간" }, { value: "YYYY-MM-DD HH:mm:ss", label: "2024-12-25 14:30:45", description: "날짜 + 시간 + 초" }, { value: "DD/MM/YYYY", label: "25/12/2024", description: "유럽 형식" }, { value: "MM/DD/YYYY", label: "12/25/2024", description: "미국 형식" }, { value: "YYYY년 MM월 DD일", label: "2024년 12월 25일", description: "한국 형식" }, ]; return ( 날짜 설정 날짜/시간 입력 필드의 세부 설정을 관리합니다. {/* 기본 설정 */}

기본 설정

updateConfig("placeholder", e.target.value)} placeholder="날짜를 선택하세요" className="text-xs" />

날짜와 함께 시간도 입력받습니다.

updateConfig("showTime", checked)} />
{/* 날짜 범위 설정 */}

날짜 범위

updateConfig("minDate", e.target.value)} className="flex-1 text-xs" />
updateConfig("maxDate", e.target.value)} className="flex-1 text-xs" />
{/* 기본값 설정 */}

기본값

updateConfig("defaultValue", e.target.value)} className="flex-1 text-xs" />

입력 필드의 초기값으로 사용됩니다.

{/* 상태 설정 */}

상태 설정

날짜가 선택되어야 합니다.

updateConfig("required", checked)} />

날짜를 수정할 수 없습니다.

updateConfig("readonly", checked)} />
{/* 미리보기 */}

미리보기

형식: {localConfig.format} {localConfig.showTime && " (시간 포함)"}
); }; DateConfigPanel.displayName = "DateConfigPanel";