Date picker

A date field with a calendar that opens beside it.

Component

Date picker belongs to the Pickers group in the CyberSpec catalog. It uses @ui-sdk/react/date-picker, @ui-sdk/react/field.

Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

bunx --bun shadcn@latest add https://www.cyberspec.dev/r/date-picker.json

Example

"use client"

import { DatePicker } from "@/components/ui/date-picker"

// An ISO date some days from today, so the example never opens on the past.
function fromToday(days: number) {
  const date = new Date()
  date.setDate(date.getDate() + days)
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`
}

export default function DatePickerDemo() {
  return (
    <>
      <DatePicker
        label="Extraction date"
        defaultValue={fromToday(4)}
        min={fromToday(2)}
        hint="Solace Mutual needs two days' notice."
      />
      <DatePicker
        label="Return date"
        defaultValue={fromToday(2)}
        invalid
        error="Return is set before extraction."
      />
    </>
  )
}

Install this example

bunx --bun shadcn@latest add https://www.cyberspec.dev/r/date-picker-demo.json

Resources

View as Markdown