"use client"; import {CalendarIcon, X} from "lucide-react"; import {Button} from "@/components/ui/button"; import {Calendar} from "@/components/ui/calendar"; import {Popover, PopoverContent, PopoverTrigger} from "@/components/ui/popover"; import {cn} from "@/lib/utils"; const parseDate = (value: string) => { if (!value) return undefined const [year, month, day] = value.split('-').map(Number) if (!year || !month || !day) return undefined const date = new Date(year, month - 1, day) if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) { return undefined } return date } const formatDate = (date: Date | undefined) => { if (!date) return '' const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') return `${year}-${month}-${day}` } export function KriDatePicker({ value, onChange, placeholder = "날짜 선택", className, }: { value: string; onChange: (value: string) => void; placeholder?: string; className?: string; }) { const selected = parseDate(value); return (
onChange(date ? formatDate(date) : "")} /> {value && ( )}
); }