Back to Supabase

Date Picker

apps/design-system/content/docs/components/date-picker.mdx

1.26.081.9 KB
Original Source
<ComponentPreview name="date-picker-demo" peekCode wide />

Installation

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

See installation instructions for the Popover and the Calendar components.

Usage

tsx
'use client'

import { format } from 'date-fns'
import * as React from 'react'
import { Button, Calendar } from 'ui'
import {
  DatePicker,
  DatePickerButton,
  DatePickerContent,
  DatePickerTrigger,
} from 'ui-patterns/DatePicker'

export function DatePickerDemo() {
  const [date, setDate] = React.useState<Date>()

  return (
    <DatePicker>
      <DatePickerTrigger asChild>
        <DatePickerButton variant="outline" className="w-[280px]">
          {date ? format(date, 'PPP') : <span>Pick a date</span>}
        </DatePickerButton>
      </DatePickerTrigger>
      <DatePickerContent>
        <Calendar mode="single" selected={date} onSelect={setDate} initialFocus />
      </DatePickerContent>
    </DatePicker>
  )
}

See the React DayPicker documentation for more information.

API Reference

Examples

Date Picker

<ComponentPreview name="date-picker-demo" peekCode wide />

Date Range Picker

<ComponentPreview name="date-picker-with-range" />

With Presets

<ComponentPreview name="date-picker-with-presets" />

Form

<ComponentPreview name="date-picker-form" />