UNPKG

903 BTypeScriptView Raw
1import React from "react";
2
3import type { CalendarDay } from "../classes/index.js";
4import type { Modifiers } from "../types/index.js";
5
6/**
7 * Render the button for a day in the calendar.
8 *
9 * When not interactive, DayPicker will render a `DayContent` component instead
10 * of a `DayButton` component.
11 *
12 * @group Components
13 * @see https://daypicker.dev/guides/custom-components
14 */
15export function DayButton(
16 props: {
17 /** The day to render. */
18 day: CalendarDay;
19 /** The modifiers for the day. */
20 modifiers: Modifiers;
21 } & JSX.IntrinsicElements["button"]
22) {
23 const { day, modifiers, ...buttonProps } = props;
24
25 const ref = React.useRef<HTMLButtonElement>(null);
26 React.useEffect(() => {
27 if (modifiers.focused) ref.current?.focus();
28 }, [modifiers.focused]);
29 return <button ref={ref} {...buttonProps} />;
30}
31
32export type DayButtonProps = Parameters<typeof DayButton>[0];