# Date picker

Boxes for choosing a date, a range, or several dates in a form.

```tsx
import { DatePickerField, DateRangePickerField } from '@halo-ds/react';
```

## When to use it
Date field opens a Calendar to pick one date, and people can type it too. Date range field picks a start and an end across two months, with presets like Last 7 days. Multiple date field picks several separate days, shown as tags in the box. The Calendar inside each one, and the full Event calendar, are on the Calendar page.

## Do
- Always let people type the date as well as pick it.
- Show the date format, like DD / MM / YYYY, in the placeholder.
- Start the calendar on the chosen date, or on today.
- Strike through dates that cannot be picked, and say why nearby.

## Don't
- Make people page back years for a birthday; let them type.
- Hide dates that cannot be picked; it breaks the grid.
- Use colour alone for today or the range.
- Squeeze two months onto a phone; show one, with presets above.

## Which picker?
Pick by how far away the date is and whether people need one date or a range.
- **Type it**: Dates far away that people know, like a birthday. Typing is faster than paging back years.
- **Single**: One date nearby, like a due date or a booking.
- **Range**: A start and an end, like a report period. Opens the range calendar with presets.

## Props
### DatePickerField props
| Prop | Type | What it does |
| --- | --- | --- |
| `defaultValue` | `Date \| null \| undefined` |  |
| `className` | `string \| undefined` |  |
| `id` | `string \| undefined` |  |
| `aria-label` | `string \| undefined` |  |
| `name` | `string \| undefined` | Form field name. A hidden input carries the date as YYYY-MM-DD. |
| `max` | `Date \| undefined` |  |
| `min` | `Date \| undefined` |  |
| `format` | `((date: Date) => string) \| undefined` | How the chosen date shows in the box. |
| `classNames` | `Partial<Record<DatePickerPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<DatePickerPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
| `size` | `"sm" \| "md" \| "lg" \| undefined` |  |
| `disabled` | `boolean \| undefined` |  |
| `placeholder` | `string \| undefined` |  |
| `required` | `boolean \| undefined` |  |
| `value` | `Date \| null \| undefined` |  |
| `invalid` | `boolean \| undefined` |  |
| `onValueChange` | `((date: Date \| null) => void) \| undefined` |  |
| `calendarHeader` | `"picker" \| "arrows" \| undefined` | Picker (the default) makes the calendar's title a button that jumps to any month and year, for dates far away like a date of birth. Arrows leaves only the arrows. Figma: Header. |
| `yearRange` | `[number, number] \| undefined` | Years people can jump to with the picker. |
| `isDateDisabled` | `((date: Date) => boolean) \| undefined` |  |
| `weekStartsOn` | `0 \| 1 \| undefined` |  |
| `locale` | `string \| undefined` |  |
| `label` | `ReactNode` |  |
| `error` | `ReactNode` | An error message. Replaces the hint, turns red and marks the control invalid. The control shows the warning icon, so the message has none. Figma: State=Error. |
| `hint` | `ReactNode` | Help text under the control. Figma: Hint. |
| `optional` | `boolean \| undefined` |  |
| `info` | `ReactNode` |  |
| `fieldClassName` | `string \| undefined` | Class for the outer field, not the control. |
| `fieldClassNames` | `Partial<Record<FieldPart, string>> \| undefined` | Classes for the field's parts: root, label, hintRow, hint, count. |
| `fieldStyles` | `Partial<Record<FieldPart, CSSProperties>> \| undefined` | Styles for the field's parts: root, label, hintRow, hint, count. |
It also takes the usual HTML attributes for its element.

### DateRangePickerField props
| Prop | Type | What it does |
| --- | --- | --- |
| `defaultValue` | `DateRange \| null \| undefined` |  |
| `className` | `string \| undefined` |  |
| `id` | `string \| undefined` |  |
| `aria-label` | `string \| undefined` |  |
| `name` | `string \| undefined` | Form field name. A hidden input carries the date as YYYY-MM-DD. |
| `max` | `Date \| undefined` |  |
| `min` | `Date \| undefined` |  |
| `format` | `((date: Date) => string) \| undefined` | How the chosen date shows in the box. |
| `classNames` | `Partial<Record<DatePickerPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<DatePickerPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
| `size` | `"sm" \| "md" \| "lg" \| undefined` |  |
| `disabled` | `boolean \| undefined` |  |
| `required` | `boolean \| undefined` |  |
| `value` | `DateRange \| null \| undefined` |  |
| `invalid` | `boolean \| undefined` |  |
| `onValueChange` | `((range: DateRange \| null) => void) \| undefined` |  |
| `presets` | `CalendarPreset[] \| undefined` | Quick picks, like "Last 7 days". Figma: Presets. |
| `isDateDisabled` | `((date: Date) => boolean) \| undefined` |  |
| `weekStartsOn` | `0 \| 1 \| undefined` |  |
| `locale` | `string \| undefined` |  |
| `startPlaceholder` | `string \| undefined` | Shown in the first slot before a range is picked. Figma: Start text. |
| `endPlaceholder` | `string \| undefined` | Shown in the second slot before a range is picked. Figma: End text. |
| `label` | `ReactNode` |  |
| `error` | `ReactNode` | An error message. Replaces the hint, turns red and marks the control invalid. The control shows the warning icon, so the message has none. Figma: State=Error. |
| `hint` | `ReactNode` | Help text under the control. Figma: Hint. |
| `optional` | `boolean \| undefined` |  |
| `info` | `ReactNode` |  |
| `fieldClassName` | `string \| undefined` | Class for the outer field, not the control. |
| `fieldClassNames` | `Partial<Record<FieldPart, string>> \| undefined` | Classes for the field's parts: root, label, hintRow, hint, count. |
| `fieldStyles` | `Partial<Record<FieldPart, CSSProperties>> \| undefined` | Styles for the field's parts: root, label, hintRow, hint, count. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { DatePickerField, DateRangePickerField } from '@halo-ds/react';

export default function Example() {
  return (
    <div style={{ display: 'grid', gap: 20, width: 320 }}>
      <DatePickerField label="Due date" />
      <DateRangePickerField label="Trip" />
    </div>
  );
}
```

### Only some days
Weekdays from today on. Other days can not be picked.
```tsx
import { DatePickerField } from '@halo-ds/react';

const today = new Date();

export default function Demo() {
  return (
    <div style={{ width: 300 }}>
      <DatePickerField label="Delivery day" hint="Weekdays only" min={today} isDateDisabled={(d) => d.getDay() === 0 || d.getDay() === 6} />
    </div>
  );
}
```

### Several dates
Separate days shown as tags. Each click adds or removes a day.
```tsx
import { useState } from 'react';
import { MultiDatePickerField } from '@halo-ds/react';

const today = new Date();

export default function Demo() {
  const [dates, setDates] = useState<Date[]>([]);
  return (
    <div style={{ width: 320 }}>
      <MultiDatePickerField label="Days off" hint="Pick up to 5 days." maxCount={5} min={today} value={dates} onValueChange={setDates} />
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/date-picker
