'use client' import { useRef } from 'react' import { CalendarDays, X } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { cn } from '@/lib/utils' export type KriDateRange = { from: string to: string } export type KriDateRangePickerProps = { value: KriDateRange onChange: (value: KriDateRange) => void placeholder?: string className?: string triggerClassName?: string contentClassName?: string disabled?: boolean } export function KriDateRangePicker({ value, onChange, placeholder = '조회 기간 선택', className, triggerClassName, contentClassName, disabled = false, }: KriDateRangePickerProps) { const toInputRef = useRef(null) const displayText = value.from && value.to ? `${value.from} ~ ${value.to}` : value.from ? `${value.from} ~` : value.to ? `~ ${value.to}` : placeholder const hasValue = value.from.length > 0 || value.to.length > 0 const invalidRange = value.from.length > 0 && value.to.length > 0 && value.from > value.to const focusAndOpenToDate = () => { const input = toInputRef.current if (!input) return input.focus() const inputWithPicker = input as HTMLInputElement & { showPicker?: () => void } inputWithPicker.showPicker?.() if (!inputWithPicker.showPicker) { input.click() } } return (
{ const nextFrom = e.target.value onChange({ ...value, from: nextFrom }) if (nextFrom) { requestAnimationFrame(() => { focusAndOpenToDate() }) } }} /> ~ onChange({ ...value, to: e.target.value })} />
{invalidRange && (

조회 시작일은 종료일보다 이후일 수 없습니다.

)}
) } export default KriDateRangePicker