import type { FC, HTMLAttributes, PropsWithChildren } from "react"; import { Fragment, useContext, useState } from "react"; import { faChevronLeft, faChevronRight } from "@fortawesome/pro-duotone-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { type CalendarDate, getLocalTimeZone, today } from "@internationalized/date"; import type { CalendarProps as AriaCalendarProps, DateValue } from "react-aria-components"; import { Calendar as AriaCalendar, CalendarContext as AriaCalendarContext, CalendarGrid as AriaCalendarGrid, CalendarGridBody as AriaCalendarGridBody, CalendarGridHeader as AriaCalendarGridHeader, CalendarHeaderCell as AriaCalendarHeaderCell, CalendarStateContext as AriaCalendarStateContext, Heading as AriaHeading, useSlottedContext, } from "react-aria-components"; import { Button } from "@/components/base/buttons/button"; import { cx } from "@/utils/cx"; import { CalendarCell } from "./cell"; import { DateInput } from "./date-input"; const ChevronLeft: FC<{ className?: string }> = ({ className }) => ; const ChevronRight: FC<{ className?: string }> = ({ className }) => ; export const CalendarContextProvider = ({ children }: PropsWithChildren) => { const [value, onChange] = useState(null); const [focusedValue, onFocusChange] = useState(); return {children}; }; const PresetButton = ({ value, children, ...props }: HTMLAttributes & { value: CalendarDate }) => { const context = useContext(AriaCalendarStateContext); if (!context) { throw new Error("Preset must be used within a Calendar component"); } const handleClick = () => { context.setValue(value); context.setFocusedDate(value); }; return ( ); }; interface CalendarProps extends AriaCalendarProps { /** The dates to highlight. */ highlightedDates?: DateValue[]; } export const Calendar = ({ highlightedDates, className, ...props }: CalendarProps) => { const context = useSlottedContext(AriaCalendarContext)!; const ContextWrapper = context ? Fragment : CalendarContextProvider; return ( cx("flex flex-col gap-3", typeof className === "function" ? className(state) : className)}>
Today
{(day) => (
{day.slice(0, 2)}
)}
{(date) => ( date.compare(highlightedDate) === 0)} /> )}
); };