import type { FC } from "react"; import { getLocalTimeZone, today } from "@internationalized/date"; import { useControlledState } from "@react-stately/utils"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCalendar } from "@fortawesome/pro-duotone-svg-icons"; const CalendarIcon: FC<{ className?: string }> = ({ className }) => ; import { useDateFormatter } from "react-aria"; import type { DatePickerProps as AriaDatePickerProps, DateValue } from "react-aria-components"; import { DatePicker as AriaDatePicker, Dialog as AriaDialog, Group as AriaGroup, Popover as AriaPopover } from "react-aria-components"; import { Button } from "@/components/base/buttons/button"; import { cx } from "@/utils/cx"; import { Calendar } from "./calendar"; const highlightedDates = [today(getLocalTimeZone())]; interface DatePickerProps extends AriaDatePickerProps { /** The function to call when the apply button is clicked. */ onApply?: () => void; /** The function to call when the cancel button is clicked. */ onCancel?: () => void; } export const DatePicker = ({ value: valueProp, defaultValue, onChange, onApply, onCancel, ...props }: DatePickerProps) => { const formatter = useDateFormatter({ month: "short", day: "numeric", year: "numeric", }); const [value, setValue] = useControlledState(valueProp, defaultValue || null, onChange); const formattedDate = value ? formatter.format(value.toDate(getLocalTimeZone())) : "Select date"; return ( {formattedDate} cx( "origin-(--trigger-anchor-point) will-change-transform", isEntering && "duration-150 ease-out animate-in fade-in placement-right:slide-in-from-left-0.5 placement-top:slide-in-from-bottom-0.5 placement-bottom:slide-in-from-top-0.5", isExiting && "duration-100 ease-in animate-out fade-out placement-right:slide-out-to-left-0.5 placement-top:slide-out-to-bottom-0.5 placement-bottom:slide-out-to-top-0.5", ) } > {({ close }) => ( <> { onCancel?.(); close(); }} > Cancel { onApply?.(); close(); }} > Apply > )} ); };