DatePicker

A date field that opens a calendar, plus DateRangePicker with presets like “Last 7 days”.

Status: beta. Category: Forms.

import { DatePicker, DateRangePicker } from '@glyphui/ui'

Exports: DatePicker, DateRangePicker, datePickerStyles.

Notes

  • Values are Date objects (or { from, to } for ranges), never strings. Pass name to submit ISO dates with a native form.
  • Format the trigger with any date-fns pattern through the format prop.

DatePicker props

PropTypeDefaultDescription
aria-describedbystring
aria-invalidboolean
aria-labelstring
classNamestring
clearablebooleanShow a button that clears the value.
contentClassNamestring
defaultValueDate
disabledboolean
disabledDatesMatcher | Matcher[]Extra disabled dates, in react-day-picker matcher form.
formatstringdate-fns format string for the trigger. Default "MMM d, yyyy".
idstring
maxDateDateLatest selectable date.
minDateDateEarliest selectable date.
namestringSubmits the ISO date (yyyy-MM-dd) with a native form.
onValueChange((date: Date) => void)
placeholderReactNode
requiredboolean
size"sm" | "md" | "lg"
valueDate

Example: Date

In a Field, with a minimum date and a clear button.

import { DatePicker, Field } from '@glyphui/ui'
import { useState } from 'react'

export default function Example() {
  const [date, setDate] = useState<Date | undefined>()
  return (
    <Field label="Launch date" description="Weekdays from today onward." className="w-72">
      <DatePicker
        value={date}
        onValueChange={setDate}
        minDate={new Date()}
        disabledDates={{ dayOfWeek: [0, 6] }}
        clearable
      />
    </Field>
  )
}

Example: Date range with presets

import { type DateRange, DateRangePicker, Field } from '@glyphui/ui'
import { useState } from 'react'

const daysAgo = (n: number) => new Date(Date.now() - n * 86_400_000)
const startOfMonth = () => new Date(new Date().getFullYear(), new Date().getMonth(), 1)

export default function Example() {
  const [range, setRange] = useState<DateRange | undefined>({ from: daysAgo(6), to: new Date() })
  return (
    <Field label="Report period" className="w-80">
      <DateRangePicker
        value={range}
        onValueChange={setRange}
        maxDate={new Date()}
        presets={[
          { label: 'Today', range: () => ({ from: new Date(), to: new Date() }) },
          { label: 'Last 7 days', range: () => ({ from: daysAgo(6), to: new Date() }) },
          { label: 'Last 30 days', range: () => ({ from: daysAgo(29), to: new Date() }) },
          { label: 'Month to date', range: () => ({ from: startOfMonth(), to: new Date() }) },
        ]}
      />
    </Field>
  )
}

Example: In a form

Value and onValueChange map straight to FormField.

import { DatePicker } from '@glyphui/ui'
import { Form, FormField, FormSubmit, useForm } from '@glyphui/ui/form'
import { z } from 'zod'

const schema = z.object({
  dueDate: z.date('Choose a due date'),
})

export default function Example() {
  const form = useForm({ schema })
  return (
    <Form form={form} onSubmit={() => {}} className="grid w-72 gap-4">
      <FormField control={form.control} name="dueDate" label="Due date" required>
        {(field) => <DatePicker value={field.value} onValueChange={field.onChange} />}
      </FormField>
      <FormSubmit className="justify-self-start">Save</FormSubmit>
    </Form>
  )
}

Live page: https://glyphui.xyz/components/date-picker