import React, { useState } from 'react' import { X, ChevronLeft, ChevronRight, Calendar as CalendarIcon } from 'lucide-react' import './JumpToDateDialog.scss' interface JumpToDateDialogProps { isOpen: boolean onClose: () => void onSelect: (date: Date) => void currentDate?: Date } const JumpToDateDialog: React.FC = ({ isOpen, onClose, onSelect, currentDate = new Date() }) => { const [calendarDate, setCalendarDate] = useState(new Date(currentDate)) const [selectedDate, setSelectedDate] = useState(new Date(currentDate)) if (!isOpen) return null const getDaysInMonth = (date: Date) => { const year = date.getFullYear() const month = date.getMonth() return new Date(year, month + 1, 0).getDate() } const getFirstDayOfMonth = (date: Date) => { const year = date.getFullYear() const month = date.getMonth() return new Date(year, month, 1).getDay() } const generateCalendar = () => { const daysInMonth = getDaysInMonth(calendarDate) const firstDay = getFirstDayOfMonth(calendarDate) const days: (number | null)[] = [] for (let i = 0; i < firstDay; i++) { days.push(null) } for (let i = 1; i <= daysInMonth; i++) { days.push(i) } return days } const handleDateClick = (day: number) => { const newDate = new Date(calendarDate.getFullYear(), calendarDate.getMonth(), day) setSelectedDate(newDate) } const handleConfirm = () => { onSelect(selectedDate) onClose() } const isToday = (day: number) => { const today = new Date() return day === today.getDate() && calendarDate.getMonth() === today.getMonth() && calendarDate.getFullYear() === today.getFullYear() } const isSelected = (day: number) => { return day === selectedDate.getDate() && calendarDate.getMonth() === selectedDate.getMonth() && calendarDate.getFullYear() === selectedDate.getFullYear() } const weekdays = ['日', '一', '二', '三', '四', '五', '六'] const days = generateCalendar() return (
e.stopPropagation()}>

跳转到日期

{calendarDate.getFullYear()}年{calendarDate.getMonth() + 1}月
{weekdays.map(d =>
{d}
)}
{days.map((day, i) => (
day !== null && handleDateClick(day)} > {day}
))}
) } export default JumpToDateDialog