Date Picker

A date picker component with range and presets.

@@directive("'use client'")

@module("date-fns") external format: (Date.t, string) => string = "format"

Installation

The Date Picker is built using a composition of the <Popover /> and the <Calendar /> components.

See installation instructions for the Popover and the Calendar components.

Usage

let (date, setDate) = React.useState(() => None)
 
<Popover>
  <Popover.Trigger
    render={<Button
      variant=Outline
      dataEmpty=?{date->Option.isNone ? Some(true) : None}
      className="data-[empty=true]:text-muted-foreground justify-start text-left font-normal"
    />}
  >
    {switch date {
    | Some(d) => d->format("PPP")->React.string
    | None => <span> {"Pick a date"->React.string} </span>
    }}
  </Popover.Trigger>
  <Popover.Content className="w-auto p-0">
    <Calendar mode=Single selected={date} onSelect={value => setDate(_ => value)} />
  </Popover.Content>
</Popover>

Examples

Basic

A basic date picker component.

@@directive("'use client'")

@module("date-fns") external format: (Date.t, string) => string = "format"

Range Picker

A date picker component for selecting a range of dates.

@@directive("'use client'")

@module("date-fns") external format: (Date.t, string) => string = "format"

Date of Birth

A date picker component for selecting a date of birth. This component includes a dropdown caption layout for date and month selection.

@@directive("'use client'")

@react.component

Input

A date picker component with an input field for selecting a date.

@@directive("'use client'")

let formatDate = (date: option<Date.t>) =>

Time Picker

A date picker component with a time input field for selecting a time.

@@directive("'use client'")

@module("date-fns") external format: (Date.t, string) => string = "format"

Natural Language Picker

This component uses the chrono-node library to parse natural language dates.

@@directive("'use client'")

@module("chrono-node") external parseDate: string => Nullable.t<Date.t> = "parseDate"