import Button from "./Button"; import Input, { InputProps } from "./Input"; import Popover from "./Popover"; import React, { useEffect, useState } from "react"; import Stack from "./Stack"; import Typography from "./Typography"; import moment from "moment"; import { ArrowSmLeftIcon, ArrowSmRightIcon } from "@heroicons/react/outline"; import { getDaysInMonth, MONTHS, WEEKDAYS } from "./lib/dates"; export interface CustomDatePickerProps { onChangeDate: (date: Date) => void; showTodayButton?: boolean; date?: Date; } export interface DatePickerProps extends Omit, CustomDatePickerProps {} const today = new Date(); export default function DatePicker({ showTodayButton = true, onChangeDate, date, ...rest }: DatePickerProps) { const [currentYear, setCurrentYear] = useState( date?.getFullYear() ?? today.getFullYear() ); const [currentMonth, setCurrentMonth] = useState( date?.getMonth() ?? today.getMonth() ); const firstDaysOfMonth = Array.from( Array(new Date(currentYear, currentMonth, 1).getDay()).keys() ); const days = Array.from( Array(getDaysInMonth(currentMonth + 1, currentYear)).keys() ); useEffect(() => { if (date) { setCurrentYear(date.getFullYear()); setCurrentMonth(date.getMonth()); } }, [date]); function goToToday() { setCurrentYear(today.getFullYear()); setCurrentMonth(today.getMonth()); onChangeDate(today); } return ( { return (
)}
); }} >
); } interface DayProps { day?: number; onClick?: () => void; isActive?: boolean; } function Day({ day, onClick, isActive }: DayProps) { return ( ); }