React DayPicker

repository·main·Indexed 27 days ago

https://github.com/gpbl/react-day-picker

A highly customizable and accessible calendar component for React 16.8+ written in TypeScript and relying on date-fns. It supports various selection modes, localization, and multiple calendar systems including ISO 8601 and specialized add-ons for Buddhist, Ethiopic, Hebrew, Hijri, and Persian calendars via @daypicker/* packages.

Tokens
62K
Snippets
145
Records
427
Agent score
89%

What's inside react-day-picker

  1. Overview of shadcn-app-workspace

    main
    The shadcn-app-workspace is a standalone Vite application designed to demonstrate the integration of the react-day-picker package within a shadcn-style environment. It is specifically configured to maintain the structure of the generated shadcn components/ui/calendar.tsx component as closely as possible to the official documentation, allowing developers to compare its rendering directly against the released application.
  2. Overview of shadcn-app-v9

    main
    The shadcn-app-v9 is a standalone Vite application designed to demonstrate a shadcn-style implementation of the calendar component. It is specifically pinned to react-day-picker@9.14.0. This app is intended for comparison purposes, allowing developers to compare the rendering of the generated shadcn components/ui/calendar.tsx against the workspace-backed implementation.
  3. Understand DayPicker UI elements and modifiers

    main

    DayPicker is composed of several functional UI elements. When styling or interacting with the calendar, you can identify days using specific modifiers:

    • selected: The day is selected.
    • disabled: The day is disabled.
    • hidden: The day is hidden.
    • focused: The day has focus.
    • today: The day is today.
    • outside: The day is outside the current month.
    • range_start: The day is the start of a selected range.
    • range_middle: The day is inside a selected range.
    • range_end: The day is the end of a selected range.

    All stylable UI elements are mapped to CSS classes. For a complete list of these classes, refer to the UI enum in the API documentation.

  4. React DayPicker features and capabilities

    main

    React DayPicker is a highly customizable calendar component with the following features:

    • Selection Modes: Supports single days, multiple days, ranges of days, or custom selections.
    • Customization: Extensive props for calendar customization and support for custom components.
    • Styling: Minimal design that can be styled with CSS or any CSS framework.
    • Localization & Time Zones: Supports localization into any language and various time zones.
    • Calendar Systems: Supports ISO 8601 and broadcast calendars. Specialized calendars (Persian, Hijri, Buddhist (Thai), Ethiopic, and Hebrew) are available via @daypicker/* add-on packages.
    • Accessibility: Complies with WCAG 2.1 AA requirements.
    • Integration: Easy integration with input fields.

    Technical Details:

    • Written in TypeScript.
    • Compiled to CommonJS and ESM.
    • Relies on date-fns for date manipulation and formatting.
    • Compatible with React 16.8 and later.
  5. Key features of DayPicker

    main

    DayPicker provides several advanced capabilities for building date interfaces:

    • Customization: Extensive props for calendar appearance and customizable components to extend rendered elements.
    • Styling: Minimal design that can be styled with CSS or any CSS framework.
    • Selection Modes: Supports single days, multiple days, ranges of days, or custom selections.
    • Localization: Supports various languages, time zones, and multiple calendar systems including ISO 8601, Persian, Hijri, Buddhist (Thai), Ethiopic, and Hebrew.
    • Accessibility: Complies with WCAG 2.1 AA requirements.
    • Integration: Easy integration with standard HTML input fields.
  6. Identify the correct DayPicker package for your project

    main

    DayPicker is split into a core React package and several calendar-specific packages.

    • Use @daypicker/react for the core React component, props, hooks, utilities, and shared types.
    • Use a specific calendar package if you need a non-Gregorian calendar, including its specific DayPicker component, locale constants, and date-library helpers:
      • @daypicker/buddhist: Buddhist/Thai calendar.
      • @daypicker/ethiopic: Ethiopic calendar.
      • @daypicker/hebrew: Hebrew calendar.
      • @daypicker/hijri: Hijri (Umm al-Qura) calendar.
      • @daypicker/persian: Persian (Jalali) calendar.
  7. DayPicker features and capabilities

    main

    DayPicker provides a highly customizable and accessible calendar component with the following features:

    • Customization: Extensive props for calendar customization and customizable components to extend rendered elements.
    • Styling: Minimal design easily styled with CSS or any CSS framework.
    • Selection Modes: Supports single days, multiple days, ranges of days, or custom selections.
    • Localization & Time Zones: Supports localization into any language and various time zones.
    • Calendar Systems: Supports ISO 8601 and broadcast calendars. Specialized calendars (Persian, Hijri, Buddhist (Thai), Ethiopic, and Hebrew) are available via @daypicker/* add-on packages.
    • Accessibility: Complies with WCAG 2.1 AA requirements.
    • Integration: Easy integration with input fields.
  8. Implement custom selection behavior

    main

    If built-in selection modes do not meet your requirements, you can implement custom logic using the onDayClick and modifiers props.

    To implement custom selection:

    1. Disable built-in logic: Omit the mode prop (or set it to undefined).
    2. Manage state: Maintain your own selection state in your component.
    3. Sync styling/ARIA: Derive a selected modifier (and any range_* modifiers) from your state and pass them to the modifiers prop so the UI and accessibility features remain aligned.
    4. Handle accessibility:
      • Ignore clicks/interactions on modifiers.disabled or modifiers.hidden.
      • For keyboard support, implement the same logic in onDayKeyDown (handling Space and Enter keys) as you do in onDayClick.