# Date picker preview

Interactive preview of the CyberSpec Date picker component. A date field with a calendar that opens beside it.

[View Date picker preview on CyberSpec](https://www.cyberspec.dev/preview/date-picker)

## About this preview

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.

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

## Example

```tsx
"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

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

## Resources

- [Date picker documentation](https://www.cyberspec.dev/components/sidebar/date-picker.md)
- [Component catalog](https://www.cyberspec.dev/components.md)
- [Date picker source code](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/ui/date-picker.tsx)
- [Shadcn registry item](https://www.cyberspec.dev/r/date-picker.json)
