import React, { type HTMLAttributes, type MouseEventHandler, useCallback, } from "react"; import { UI } from "../UI.js"; import { useDayPicker } from "../useDayPicker.js"; /** * Render the navigation toolbar with buttons to navigate between months. * * @group Components * @see https://daypicker.dev/guides/custom-components */ export function Nav( props: { /** Handler for the previous month button click. */ onPreviousClick?: MouseEventHandler; /** Handler for the next month button click. */ onNextClick?: MouseEventHandler; /** The date of the previous month, if available. */ previousMonth?: Date | undefined; /** The date of the next month, if available. */ nextMonth?: Date | undefined; } & HTMLAttributes, ) { const { onPreviousClick, onNextClick, previousMonth, nextMonth, ...navProps } = props; const { components, classNames, labels: { labelPrevious, labelNext }, } = useDayPicker(); const handleNextClick = useCallback( (e: React.MouseEvent) => { if (nextMonth) { onNextClick?.(e); } }, [nextMonth, onNextClick], ); const handlePreviousClick = useCallback( (e: React.MouseEvent) => { if (previousMonth) { onPreviousClick?.(e); } }, [previousMonth, onPreviousClick], ); return ( ); } export type NavProps = Parameters[0];