Date picker

Pick one date. It drops open like fabric.

Due date

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/date-picker.json

This copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/date-picker.tsx
"use client";

import * as React from "react";
import { Calendar, type CalendarPreset } from "./calendar";

export type DatePickerProps = {
  /** The date (controlled); null for none yet. */
  value?: Date | null;
  /** The starting date when uncontrolled (none, if left out). */
  defaultValue?: Date | null;
  /** Called with the picked date. */
  onValueChange?: (value: Date) => void;
  /** What the trigger says while no date is picked. */
  placeholder?: string;
  /** Quick picks above the month. */
  presets?: CalendarPreset[];

Usage

Usage
"use client";

import * as React from "react";
import { DatePicker } from "@/components/fabricui/date-picker";

export function DueDate() {
  const [due, setDue] = React.useState<Date | null>(null);
  return (
    <div className="flex flex-col gap-2">
      <span id="due">Due date</span>
      <DatePicker value={due} onValueChange={setDue} aria-labelledby="due" />
    </div>
  );
}

Props

PropTypeDefault
value

The date, if you control it; null for none yet.

Date | null—
defaultValue

The starting date when you don't (none, if left out).

Date | null—
onValueChange

Called with the picked date.

(value: Date) => void—
placeholder

What the trigger says while no date is picked.

string"Pick a date"
presets

Quick picks above the month, in days from today.

{ label: string; days: number }[]Today, Tomorrow, Next week
panelLabel

The panel's accessible name.

string"Choose a date"
aria-labelledby

Ids of the field's label; the trigger reads as the label followed by the date. (Name it this way rather than wrapping it in a <label>: a click anywhere in a <label> presses the trigger, which would close the panel.)

string—
className

Added to the root.

string—