### Install React DayPicker Source: https://react-day-picker.js.org/ Install the react-day-picker and date-fns packages using npm, pnpm, or yarn. ```bash npm install react-day-picker date-fns # using npm pnpm install react-day-picker date-fns # using pnpm yarn add react-day-picker date-fns # using yarn ``` -------------------------------- ### Basic DayPicker Example with Date Formatting Source: https://react-day-picker.js.org/start A single-date selection example using DayPicker with date-fns for formatting the selected date in the footer. Ensure DayPicker and date-fns are installed and imported. ```javascript import React from 'react'; import { format } from 'date-fns'; import { DayPicker } from 'react-day-picker'; export default function Example() { const [selected, setSelected] = React.useState(); let footer =

Please pick a day.

; if (selected) { footer =

You picked {format(selected, 'PP')}.

; } return ( ); } ``` -------------------------------- ### Install React Day Picker and Date-Fns Source: https://react-day-picker.js.org/start Install the necessary packages using npm, pnpm, or yarn. ```bash npm install react-day-picker date-fns # with npm pnpm install react-day-picker date-fns # with pnpm yarn add react-day-picker date-fns # with yarn ``` -------------------------------- ### Basic DayPicker Example Source: https://react-day-picker.js.org/ A basic example demonstrating how to use the DayPicker component to select a single date. It includes a custom footer that updates based on the selected date. ```jsx import { useState } from 'react'; import { format } from 'date-fns'; import { DayPicker } from 'react-day-picker'; import 'react-day-picker/dist/style.css'; export default function Example() { const [selected, setSelected] = useState(); let footer =

Please pick a day.

; if (selected) { footer =

You picked {format(selected, 'PP')}.

; } return ( ); } ``` -------------------------------- ### Clone Monorepo and Install Dependencies Source: https://react-day-picker.js.org/development/source Clone the react-day-picker monorepo and install its dependencies using pnpm. ```bash $ git clone git@github.com:gpbl/react-day-picker.git $ cd react-day-picker $ pnpm ``` -------------------------------- ### Development Scripts for Website Source: https://react-day-picker.js.org/development/source Scripts to start the documentation website in watch mode or run type checking for the website. ```bash $ pnpm -F website start # start the website in watch mode ``` ```bash $ pnpm -F website typecheck-watch # start the typecheck in watch mode for website ``` -------------------------------- ### Date Picker Dialog Example Source: https://react-day-picker.js.org/guides/input-fields This example demonstrates how to create a date picker dialog that integrates with an input field. It uses `react-popper` for positioning the dialog and `focus-trap-react` to manage focus within the dialog. The input field allows direct date entry, and selecting a date from the picker updates the input and closes the dialog. ```javascript import React, { ChangeEventHandler, useRef, useState } from 'react'; import { format, isValid, parse } from 'date-fns'; import FocusTrap from 'focus-trap-react'; import { DayPicker, SelectSingleEventHandler } from 'react-day-picker'; import { usePopper } from 'react-popper'; export default function DatePickerDialog() { const [selected, setSelected] = useState(); const [inputValue, setInputValue] = useState(''); const [isPopperOpen, setIsPopperOpen] = useState(false); const popperRef = useRef(null); const buttonRef = useRef(null); const [popperElement, setPopperElement] = useState( null ); const popper = usePopper(popperRef.current, popperElement, { placement: 'bottom-start' }); const closePopper = () => { setIsPopperOpen(false); buttonRef?.current?.focus(); }; const handleInputChange: ChangeEventHandler = (e) => { setInputValue(e.currentTarget.value); const date = parse(e.currentTarget.value, 'y-MM-dd', new Date()); if (isValid(date)) { setSelected(date); } else { setSelected(undefined); } }; const handleButtonClick = () => { setIsPopperOpen(true); }; const handleDaySelect: SelectSingleEventHandler = (date) => { setSelected(date); if (date) { setInputValue(format(date, 'y-MM-dd')); closePopper(); } else { setInputValue(''); } }; return (
{isPopperOpen && (
)}
); } ``` -------------------------------- ### Configure First Week of the Year and Week Number Formatting Source: https://react-day-picker.js.org/basics/localization Use `firstWeekContainsDate` to change the week number calculation and `formatters` to customize the display of week numbers. This example sets the first week of the year to start on day 4 and prefixes week numbers with 'W'. ```jsx import React from 'react'; import { DayPicker } from 'react-day-picker'; export default function App() { return ( `W${weekNumber}` }} /> ); } ``` -------------------------------- ### onDayTouchStart Source: https://react-day-picker.js.org/api/interfaces/DayPickerDefaultProps Optional event callback when a day touch event starts. Inherited from DayPickerBase. ```APIDOC ## onDayTouchStart ### Description Event callback when a day touch event starts. ### Type `DayTouchEventHandler` ### Optional true ### Inherited from DayPickerBase.onDayTouchStart ``` -------------------------------- ### Basic Modifier Examples Source: https://react-day-picker.js.org/basics/modifiers Demonstrates adding 'selected', 'disabled', and 'hidden' modifiers to days using their respective props. ```jsx