This commit is contained in:
2026-02-01 19:22:54 +08:00
parent 85f742ad2b
commit e42fce5bd1
4 changed files with 62 additions and 81 deletions

View File

@@ -16,19 +16,14 @@ interface DatePickerProps {
}
export function DatePicker({ className, value, onChange }: DatePickerProps) {
const [date, setDate] = React.useState<Date | undefined>(
value ? new Date(typeof value === 'string' ? value : value.toISOString()) : undefined
)
const toDate = (val: string | Dayjs | undefined): Date | undefined => {
if (!val) return undefined
return new Date(typeof val === 'string' ? val : val.toISOString())
}
React.useEffect(() => {
if (value) {
const dateValue = typeof value === 'string' ? value : value.toISOString()
setDate(new Date(dateValue))
}
}, [value])
const date = toDate(value)
const handleSelect = (selectedDate: Date | undefined) => {
setDate(selectedDate)
if (selectedDate && onChange) {
onChange(dayjs(selectedDate))
}