# Date Picker

> A Date Field with a button that opens a Calendar in a popover, so the picker is the same in every browser and yours to style.

`<slab-date-picker>` · Form · built on `<input type=date>`

## Install

```sh
pnpm add slab-elements lit
```

## Usage

### React

`MyDatePicker.jsx`. React 19 or later, which sets props on custom elements as properties.

```jsx
import 'slab-elements/date-picker.js';

export function MyDatePicker() {
  return (
    <slab-date-picker label="Start date" name="start" min="2026-01-01" required></slab-date-picker>
  );
}
```

### Lit

`my-date-picker.ts`. Slab is built on Lit, so its elements are at home in Lit's templates.

```ts
import 'slab-elements/date-picker.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';

@customElement('my-date-picker')
export class MyDatePicker extends LitElement {
  render() {
    return html`
      <slab-date-picker label="Start date" name="start" min="2026-01-01" required></slab-date-picker>
    `;
  }
}
```

### Vue

`MyDatePicker.vue`. Let Vue's compiler know slab- tags are custom elements with isCustomElement.

```vue
<script setup>
import 'slab-elements/date-picker.js';
</script>

<template>
  <slab-date-picker label="Start date" name="start" min="2026-01-01" required></slab-date-picker>
</template>
```

### Svelte

`MyDatePicker.svelte`. Svelte binds properties and events to custom elements like any other element.

```svelte
<script>
  import 'slab-elements/date-picker.js';
</script>

<slab-date-picker label="Start date" name="start" min="2026-01-01" required></slab-date-picker>
```

### Ember

`MyDatePicker.gjs`. Ember sets attributes, and a dynamic value like {{this.max}} sets the property when the element has one. {{on}} listens for any event by its name.

```gjs
import 'slab-elements/date-picker.js';

export const MyDatePicker = <template>
  <slab-date-picker label="Start date" name="start" min="2026-01-01" required></slab-date-picker>
</template>;
```

### HTML

`index.html`. Any bundler (or an import map) takes care of the imports.

```html
<script type="module">
  import 'slab-elements/date-picker.js';
</script>

<slab-date-picker label="Start date" name="start" min="2026-01-01" required></slab-date-picker>
```

## Example

Here's a styled version, `<slab-styled-date-picker>`. It's not in the package — it's an example of what you can build with the headless element. Copy it and make it yours at the bottom of this page.

```html
<slab-styled-date-picker label="Pour date" min="2026-10-12" value="2026-10-16">
  <span slot="description">The plant needs two days' notice.</span>
</slab-styled-date-picker>
```

Swap `slab-styled-` for `slab-` in that markup and you've got the same example as it ships: the headless elements with no CSS at all. That's your starting point.

It's [Date Field](date-field.md), so the input, the value, validity and the form all work the same. The browser's own picker is hidden where it can be, and the button beside the input opens a [Calendar](calendar.md) in a non-modal dialog named by the label. Firefox keeps its own calendar icon in the input, which can't be hidden.

Opening it focuses the selected day, or else today, kept between `min` and `max`. Picking a day sets the value, dispatches "input" and "change", closes the calendar and puts focus back on the button. `open` reflects whether it's open, and `showPicker()` and `hidePicker()` open and close it. Like a native input's, `showPicker()` only works from a user gesture, such as a click, and throws while it's disabled or read-only. The Calendar's parts are exported with the same names, so style its days with `::part(day)`, `::part(selected)` and the rest. `step` isn't passed to the Calendar, so a day it offers can still be a `stepMismatch`.

## Keyboard

| Key                  | What it does                                                                |
| -------------------- | --------------------------------------------------------------------------- |
| Alt+Down             | In the input, opens the calendar.                                           |
| Enter, Space         | On the button, opens or closes the calendar. On a day, picks it and closes. |
| Escape               | Closes the calendar without picking, and focuses the button.                |
| Arrows, Page Up/Down | Moves between days and months, as on Calendar.                              |
| Enter (in the input) | Submits the form.                                                           |

## Behavior

A date picker with no visual styles: a Date Field, with a button beside its input that opens a Calendar in a popover, as in the APG's date picker dialog.

It's Date Field, so everything a Date Field does it does too: the native `<input type="date">` to type into, its value, `min`, `max`, `required`, validity, and taking part in a form. Only the picker is different. The browser's own is hidden where it can be, and Calendar is used instead, so the picker is the same in every browser and can be styled. Firefox keeps a calendar icon of its own in the input, which can't be hidden.

The button opens and closes a non-modal `role="dialog"`, named by the field's label, with a Calendar in it. The button says "Choose date" unless `button-label` is set, and is `aria-expanded` while the calendar is open. Alt+ArrowDown in the input opens it too. Opening it focuses the selected day, or else today, kept between `min` and `max`. Picking a day sets the value, dispatches "input" and "change" as typing does, closes the calendar, and puts focus back on the button. Escape and a click outside close it without picking anything, the way a native popover closes.

`week-start` is passed to the Calendar, and so are `min` and `max`, so days outside them can't be picked. `step` isn't: a day the Calendar offers can still be a `stepMismatch`. The Calendar's language is the field's nearest `lang`.

`open` reflects whether the calendar is open, and setting it opens or closes the calendar, as `showPicker()` and `hidePicker()` do.

Style the field through Date Field's parts and states, the button through `::part(button)` and `:host([open])`, the popover through `::part(popover)`, and the Calendar through its own parts, which are exported with the same names.

## API

### `<slab-date-picker>`

#### Attributes

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `button-label` | `string` |  | The button's text and so its accessible name. "Choose date" in English when unset. |
| `open` | `boolean` | `false` | Whether the calendar is open, however it got there or went away. Setting it opens or closes the calendar. |
| `week-start` | `number` | `0` | The day the Calendar's weeks start on, from 0 for Sunday to 6 for Saturday. |
| `label` (required) | `string` |  | Names it. It's the accessible name, and the visible label where there is one. |
| `autocomplete` | `HTMLInputElement['autocomplete']` |  | What the browser may fill it with, as a native input's `autocomplete` says. |
| `disabled` | `boolean` | `false` | Disables it, as `disabled` does a native control: the user can't focus or use it, and a form control's value isn't submitted. |
| `hide-label` | `boolean` | `false` | Hides the label visually and leaves it as the accessible name, for a design that shows the label some other way. |
| `max` | `string` |  | The latest date allowed, as "yyyy-mm-dd". |
| `min` | `string` |  | The earliest date allowed, as "yyyy-mm-dd". Also where `step` counts from. |
| `name` | `string` | `''` | The name its value is submitted under, as a native control's `name`. |
| `readonly` | `boolean` | `false` | Lets the user select the value but not change it, as `readonly` does a native input. The value is still submitted. |
| `required` | `boolean` | `false` | Makes it invalid while it has no value, as `required` does a native control. |
| `step` | `string` |  | In days, or "any". Counted from `min` when there is one. |
| `value` | `string` | `''` | An ISO "yyyy-mm-dd" string. Like a native input, the attribute is the default value and the property is the current one, so the attribute doesn't change as the field is edited. |
| `custom-validity` | `string` |  | Makes it invalid with this message, as `setCustomValidity()` does, and shows the message at once rather than once validity is reported, for an error the page already knows about, such as one from a server. Removing it, or setting it to an empty string, makes it valid again, unless something else makes it invalid. |

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| `defaultValue` | `string` | The value it starts with, and goes back to when its form resets. It's the `value` attribute, as a native input's `defaultValue` is, so setting it sets the attribute, and `value` with it. |
| `form` (read-only) | `HTMLFormElement \| null` | The form it belongs to, or `null`. |
| `labels` (read-only) | `NodeList` | The `<label>` elements associated with it, as a native control's `labels`: each `<label for>` that names its `id`, and a `<label>` around it. |
| `validationMessage` (read-only) | `string` | What's wrong, as the validity message says it: the message given to `setCustomValidity()` or `setValidity()`, or else the browser's own. Empty while it's valid. |
| `validity` (read-only) | `ValidityState` | Its `ValidityState`, as a native control's. |
| `willValidate` (read-only) | `boolean` | Whether its validity is checked when its form submits. It isn't while it's disabled or read-only. |
| `valueAsDate` | `Date \| null` | `value` as a `Date` at midnight UTC, or `null` when empty, as on a native input. |

#### Methods

| Signature | Description |
| --- | --- |
| `checkValidity(): boolean` | Whether its value is valid. Dispatches "invalid" when it isn't, as a native control's does. |
| `click(): void` | Clicks it, as a native element's `click()` does. |
| `focus(options?: FocusOptions): void` | Focuses it, or the part of it that takes focus. |
| `hidePicker(): void` | Closes the calendar. |
| `reportValidity(): boolean` | Whether its value is valid. When it isn't, dispatches "invalid" and shows the validity message, as a native control's does. |
| `resetValidityFeedback(): void` | Clears the validity feedback without changing `validity`. |
| `setCustomValidity(message: string): void` | Makes it invalid with a message of your own, or valid again with an empty one, as a native control's does. |
| `setValidity(flags?: ValidityStateFlags, message?: string): void` | Sets its validity and message, as `ElementInternals.setValidity()` does, for checks of your own beyond `setCustomValidity()`. |
| `showPicker(): void` | Opens the calendar and focuses its tabbable day. As a native input's, it throws without a user gesture, or while it's disabled or read-only. |

#### Events

| Name | Type | Description |
| --- | --- | --- |
| `input` | `Event` | As the user changes its value, as a native control's does. Setting it from code doesn't dispatch it. |
| `change` | `Event` | When the user changes its value, as a native control's does. Setting it from code doesn't dispatch it. |
| `beforetoggle` | `ToggleEvent` | Before it opens or closes, as a `ToggleEvent` that doesn't bubble. Cancel it while it's opening to keep it closed. |
| `toggle` | `ToggleEvent` | When it opens or closes, as a `ToggleEvent` with `oldState` and `newState` that doesn't bubble, as a popover's does. |
| `invalid` | `Event` | When a check finds its value invalid, as a native control's does. Cancel it to leave the validity message unshown, after a blur, a submit or `reportValidity()`, and focus where it is. |

#### Slots

| Name | Type | Description |
| --- | --- | --- |
| `description` | `Element \| string` | Text that describes it, such as a hint or what the validity message means. It's its accessible description. |
| `validity-message` | `Element \| string` | Shown in place of the validity message's text while it's invalid and the message shows, for wording of your own, a translation, or a link. It's part of its accessible description, and `validationMessage` stays the browser's or `setCustomValidity()`'s. |

#### CSS parts

| Name | Description |
| --- | --- |
| `button` | Opens and closes the calendar |
| `calendar` | The Calendar in the popover |
| `control` | The input and the button |
| `description` | Text about the field, and its validity message when it has one |
| `input` | The input |
| `label` | The label |
| `popover` | The popover the Calendar is in |
| `validity-message` | The validity message, which says why the value is invalid |

#### CSS states

| Name | Description |
| --- | --- |
| `:state(disabled)` | While it's disabled. |
| `:state(error)` | While it's invalid and its validity message shows, which is once its validity is reported, as when its form is submitted. |
| `:state(open)` | While it's open. |
| `:state(readonly)` | While it's read-only. |
| `:state(required)` | While it's required, for styles such as an asterisk. |

## Copy and own it

`<slab-styled-date-picker>` isn't in the package. It's an example — copy it into your project and change whatever you want. Keyboard, focus, ARIA, forms, and events all come from the headless element, and the styles only reach in through `::part()` and `:state()`, same as yours would.

### Lit

Under the hood, it's just the headless element, subclassed, with `styles` set. That's it. To use it, copy these files, swap the tag in `@customElement()` for one of your own, and import it. `tokens.styles.ts` holds the colors and fonts every styled example shares, so you only need it once.

#### TypeScript

These files are TypeScript, and `@customElement()` is one of Lit's decorators (TypeScript's experimental flavor). You'll need two options in your tsconfig, per [Lit's docs](https://lit.dev/docs/components/decorators/#decorators-typescript): `experimentalDecorators` to compile them, and `useDefineForClassFields` turned off so class fields don't stomp on the accessors Lit sets up.

```json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "useDefineForClassFields": false
  }
}
```

Using plain JavaScript? Drop the types and register the class with `customElements.define()` instead of the decorator.

#### date-picker.ts

```ts
import { customElement } from 'lit/decorators.js';
import DatePicker from 'slab-elements/date-picker.js';
import styles from './date-picker.styles.js';
import textInput from './text-input.styles.js';
import tokens from './tokens.styles.js';

declare global {
  interface HTMLElementTagNameMap {
    'slab-styled-date-picker': StyledDatePicker;
  }
}

/**
 * Date Picker, styled: Date Field's look, with a calendar button butted
 * against the input, and the styled Calendar's look in a raised popover below.
 */
@customElement('slab-styled-date-picker')
export default class StyledDatePicker extends DatePicker {
  static override styles = [tokens, textInput, styles];
}
```

#### date-picker.styles.ts

```ts
import { css } from 'lit';

/*
  The Calendar is in this shadow root rather than slotted, so its days are
  styled through the parts it exports, the way the styled Calendar styles
  them from inside its own.
*/
export default css`
  [part~='control'] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  /*
    Butted against the input, sharing its border. It has no height of its own
    and is stretched to the input's, so the two match in every browser, even
    one that sizes a date input its own way. Its text is its accessible name,
    so it stays, at no size, and a calendar is drawn in its place.
  */
  [part~='button'] {
    align-items: center;
    align-self: stretch;
    background-color: var(--paper);
    border: var(--border);
    border-radius: 0;
    color: inherit;
    cursor: pointer;
    display: flex;
    font-size: 0;
    inline-size: 3rem;
    justify-content: center;
    margin-inline-start: -2px;
    padding: 0;
    transition:
      background-color 100ms,
      box-shadow 100ms,
      color 100ms,
      translate 100ms;

    &::before {
      block-size: 0.875rem;
      border: 2px solid currentcolor;
      border-block-start-width: 5px;
      content: '';
      inline-size: 1rem;
    }

    &:hover {
      background-color: var(--chalk);
    }

    /*
      The outline is transparent rather than gone, so it still shows in forced
      colors, where box shadows don't.
    */
    &:focus-visible {
      box-shadow: 4px 4px 0 var(--ember);
      outline: 2px solid transparent;
      translate: -2px -2px;
    }

    &:disabled {
      background-color: var(--chalk);
      border-style: dashed;
      color: var(--ash);
      cursor: not-allowed;
    }
  }

  :host([open]) [part~='button'] {
    background-color: var(--ink);
    color: var(--paper);
  }

  :host(:state(error)) [part~='button'] {
    border-color: var(--ember-deep);
  }

  /* A closed popover isn't displayed, so the entrance runs each time it opens. */
  [part~='popover'] {
    animation: drop 150ms ease-out;
    background-color: var(--paper);
    border: var(--border);
    box-shadow: var(--shadow);
    color: var(--ink);
    font-family: var(--font-body);
    margin-block: 0.5rem;
    padding: 1rem;
  }

  @keyframes drop {
    from {
      opacity: 0;
      translate: 0 -0.375rem;
    }
  }

  [part~='calendar']::part(header) {
    align-items: center;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    margin-block-end: 0.75rem;
  }

  [part~='calendar']::part(heading) {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 600;
  }

  [part~='calendar']::part(previous),
  [part~='calendar']::part(next) {
    align-items: center;
    background-color: var(--paper);
    block-size: 2.25rem;
    border: var(--border);
    color: var(--ink);
    cursor: pointer;
    display: flex;
    font-size: 0;
    inline-size: 2.25rem;
    justify-content: center;
    padding: 0;
    transition: background-color 100ms;
  }

  [part~='calendar']::part(previous)::before,
  [part~='calendar']::part(next)::before {
    block-size: 0.5rem;
    border-block-end: 2px solid currentcolor;
    border-inline-start: 2px solid currentcolor;
    content: '';
    inline-size: 0.5rem;
    rotate: 45deg;
    translate: 0.125rem 0;
  }

  [part~='calendar']::part(next)::before {
    rotate: -135deg;
    translate: -0.125rem 0;
  }

  [part~='calendar']::part(previous):hover,
  [part~='calendar']::part(next):hover {
    background-color: var(--chalk);
  }

  [part~='calendar']::part(previous):focus-visible,
  [part~='calendar']::part(next):focus-visible {
    outline: 3px solid var(--ember);
    outline-offset: 2px;
  }

  /*
    Separate rather than collapsed, so each day draws its own border whole.
    Collapsed, a day's border merges with its neighbors' and today's ring
    breaks up.
  */
  [part~='calendar']::part(grid) {
    border-collapse: separate;
    border-spacing: 0;
  }

  [part~='calendar']::part(weekday) {
    color: var(--ash);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    padding-block-end: 0.375rem;
    text-transform: uppercase;
  }

  [part~='calendar']::part(day) {
    block-size: 2.5rem;
    border: 2px solid transparent;
    box-sizing: border-box;
    cursor: pointer;
    inline-size: 2.5rem;
    text-align: center;
    transition:
      background-color 100ms,
      color 100ms;
  }

  [part~='calendar']::part(day):hover {
    background-color: var(--chalk);
  }

  [part~='calendar']::part(day):focus-visible {
    outline: 3px solid var(--ember);
    outline-offset: -3px;
  }

  [part~='calendar']::part(today) {
    border-color: var(--ember);
  }

  /*
    The ring is inside the day, so on the selected one it's on ink, where
    ember falls short of 3:1 in the dark. The text's color always has the
    contrast.
  */
  [part~='calendar']::part(selected) {
    background-color: var(--ink);
    color: var(--paper);
    font-weight: 600;
  }

  [part~='calendar']::part(selected):focus-visible {
    outline-color: currentcolor;
  }

  [part~='calendar']::part(disabled) {
    color: var(--ash);
    cursor: not-allowed;
    text-decoration: line-through;
  }

  [part~='calendar']::part(disabled):hover {
    background-color: transparent;
  }

  @media (prefers-reduced-motion: reduce) {
    [part~='button'],
    [part~='popover'],
    [part~='calendar']::part(previous),
    [part~='calendar']::part(next),
    [part~='calendar']::part(day) {
      animation: none;
      transition: none;
    }
  }
`;
```

#### text-input.styles.ts

```ts
import { css } from 'lit';

/*
  The look shared by everything typed into: Text Field, Password Field,
  Search Field, Textarea, Number, Date Field, Time Field, Combobox and Tags
  Input, whose fields are "::part(input)", or "::part(textarea)" for Textarea.
  File Drop starts from it too, for its label and description.
*/
export default css`
  :host {
    color: var(--ink);
    display: grid;
    font-family: var(--font-body);
  }

  [part~='label'] {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: 600;
    margin-block-end: 0.375rem;
  }

  :host(:state(required)) [part~='label']::after {
    color: var(--ember-deep);
    content: ' *' / '';
  }

  [part~='input'],
  [part~='textarea'] {
    background-color: var(--paper);
    block-size: 3rem;
    border: var(--border);
    border-radius: 0;
    box-sizing: border-box;
    color: inherit;
    font: inherit;

    /* A fixed height, shared with Select, so fields line up in a row. */
    padding: 0 0.75rem;
    transition:
      background-color 100ms,
      border-color 100ms,
      box-shadow 100ms,
      translate 100ms;

    &::placeholder {
      color: var(--ash);
    }

    /*
      The outline is transparent rather than gone, so it still shows in forced
      colors, where box shadows don't.
    */
    &:focus-visible {
      box-shadow: 4px 4px 0 var(--ember);
      outline: 2px solid transparent;
      translate: -2px -2px;
    }

    &:disabled {
      background-color: var(--chalk);
      border-style: dashed;
      color: var(--ash);
      cursor: not-allowed;
    }
  }

  [part~='textarea'] {
    block-size: auto;
    min-block-size: 7rem;
    padding: 0.625rem 0.75rem;
    resize: vertical;
  }

  :host(:state(readonly)) [part~='input'],
  :host(:state(readonly)) [part~='textarea'] {
    background-color: var(--chalk);
  }

  :host(:state(error)) [part~='input'],
  :host(:state(error)) [part~='textarea'] {
    border-color: var(--ember-deep);
  }

  /*
    Spaced by what's in it rather than by a gap, so a description with
    nothing in it takes no room, and a control beside the field lines up
    with its bottom edge.
  */
  [part~='description'] {
    color: var(--ash);
    display: grid;
    font-size: 0.875rem;
  }

  ::slotted([slot='description']) {
    margin-block-start: 0.375rem;
  }

  [part~='validity-message'] {
    color: var(--ember-deep);
    font-weight: 600;
    margin-block-start: 0.375rem;

    &::before {
      content: '■ ' / '';
    }
  }

  @media (prefers-reduced-motion: reduce) {
    [part~='input'],
    [part~='textarea'] {
      transition: none;
    }
  }
`;
```

#### tokens.styles.ts

```ts
import { css } from 'lit';

/*
  The styled components' palette and type, taken from the logo: ink for the
  courses, ember for the base, paper behind them.

  Each is a short alias for a "--slab-styled-*" property, with the default as
  its fallback. Retheming is "--slab-styled-ember" and the rest on ":root",
  which every shadow root inherits. Were the defaults declared under those
  names here instead, each host's own declaration would shadow the page's.

  Each default is "light-dark()", so the components follow the page's
  "color-scheme": "dark" for dark, "light" for light, and "light dark" to
  follow the operating system. Ink and paper trade places in the dark, so
  ink is always the text and paper always what's behind it. Contrast is given
  as light, then dark.
*/
export default css`
  :host {
    /* Secondary text. 6.8:1 and 6.9:1 on paper. */
    --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
    --border: 2px solid var(--ink);

    /* Behind disabled and read-only controls, and hovered rows. */
    --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

    /*
      The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
      enough for borders, fills and large text, but not always for small text,
      which takes "--ember-deep".
    */
    --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

    /*
      Orange for small text on paper, and for paper text on it. 5.7:1 and
      7.4:1.
    */
    --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
    --font-body: var(
      --slab-styled-font-body,
      'IBM Plex Sans',
      system-ui,
      sans-serif
    );
    --font-display: var(
      --slab-styled-font-display,
      'Zilla Slab',
      rockwell,
      'Roboto Slab',
      serif
    );
    --font-mono: var(
      --slab-styled-font-mono,
      'IBM Plex Mono',
      ui-monospace,
      monospace
    );
    --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
    --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

    /* The hard, offset shadow a raised surface casts. */
    --shadow: 4px 4px 0 var(--ink);
  }

  /*
    Forced colors, such as Windows' contrast themes, replace every color that
    isn't a system color, so ember fills and paper marks all become the same
    background, and a checked Checkbox looks like an unchecked one. The palette
    becomes the user's system colors instead, which are kept. Ember is the
    highlight, the color of what's selected, and ember-deep, being for text and
    for paper text on it, is the text color.
  */
  @media (forced-colors: active) {
    :host {
      --ash: GrayText;
      --chalk: Canvas;
      --ember: Highlight;
      --ember-deep: CanvasText;
      --ink: CanvasText;
      --paper: Canvas;
    }
  }
`;
```

### React, Vue, Svelte and Ember

The same styles, written from outside the element, so there's nothing to subclass. The CSS styles every `<slab-date-picker>` on the page. Import `tokens.css`, the colors and fonts every styled example shares, once, wherever your global styles go.

In React and Vue, each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.

In Svelte, import `date-picker.js` once, such as in your root layout, and use `<slab-date-picker>` as is. A Svelte component around it would take `slot="…"` content as its own slot and drop it.

In Ember, each component registers its headless element and imports its CSS. Use it like the element: its attributes and its content go to the element.

#### DatePicker.jsx

```jsx
import 'slab-elements/date-picker.js';
import './date-picker.css';

export function DatePicker(props) {
  return <slab-date-picker {...props} />;
}
```

#### DatePicker.vue

```vue
<script setup>
import 'slab-elements/date-picker.js';
import './date-picker.css';
</script>

<template>
  <slab-date-picker><slot /></slab-date-picker>
</template>
```

#### date-picker.js

```js
import 'slab-elements/date-picker.js';
import './date-picker.css';
```

#### DatePicker.gjs

```gjs
import 'slab-elements/date-picker.js';
import './date-picker.css';

export const DatePicker = <template>
  <slab-date-picker ...attributes>{{yield}}</slab-date-picker>
</template>;
```

#### date-picker.css

```css
slab-date-picker {
  color: var(--ink);
  display: grid;
  font-family: var(--font-body);
}

slab-date-picker::part(label) {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  margin-block-end: 0.375rem;
}

slab-date-picker:state(required)::part(label)::after {
  color: var(--ember-deep);
  content: ' *' / '';
}

slab-date-picker::part(input),
slab-date-picker::part(textarea) {
  background-color: var(--paper);
  block-size: 3rem;
  border: var(--border);
  border-radius: 0;
  box-sizing: border-box;
  color: inherit;
  font: inherit;
  /* A fixed height, shared with Select, so fields line up in a row. */
  padding: 0 0.75rem;
  transition:
    background-color 100ms,
    border-color 100ms,
    box-shadow 100ms,
    translate 100ms;
}

slab-date-picker::part(input)::placeholder,
slab-date-picker::part(textarea)::placeholder {
  color: var(--ash);
}

/*
  The outline is transparent rather than gone, so it still shows in forced
  colors, where box shadows don't.
*/
slab-date-picker::part(input):focus-visible,
slab-date-picker::part(textarea):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
  translate: -2px -2px;
}

slab-date-picker::part(input):disabled,
slab-date-picker::part(textarea):disabled {
  background-color: var(--chalk);
  border-style: dashed;
  color: var(--ash);
  cursor: not-allowed;
}

slab-date-picker::part(textarea) {
  block-size: auto;
  min-block-size: 7rem;
  padding: 0.625rem 0.75rem;
  resize: vertical;
}

slab-date-picker:state(readonly)::part(input),
slab-date-picker:state(readonly)::part(textarea) {
  background-color: var(--chalk);
}

slab-date-picker:state(error)::part(input),
slab-date-picker:state(error)::part(textarea) {
  border-color: var(--ember-deep);
}

/*
  Spaced by what's in it rather than by a gap, so a description with
  nothing in it takes no room, and a control beside the field lines up
  with its bottom edge.
*/
slab-date-picker::part(description) {
  color: var(--ash);
  display: grid;
  font-size: 0.875rem;
}

slab-date-picker > [slot='description'] {
  margin-block-start: 0.375rem;
}

slab-date-picker::part(validity-message) {
  color: var(--ember-deep);
  font-weight: 600;
  margin-block-start: 0.375rem;
}

slab-date-picker::part(validity-message)::before {
  content: '■ ' / '';
}

@media (prefers-reduced-motion: reduce) {
  slab-date-picker::part(input),
  slab-date-picker::part(textarea) {
    transition: none;
  }
}

slab-date-picker::part(control) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

/*
  Butted against the input, sharing its border. It has no height of its own
  and is stretched to the input's, so the two match in every browser, even
  one that sizes a date input its own way. Its text is its accessible name,
  so it stays, at no size, and a calendar is drawn in its place.
*/
slab-date-picker::part(button) {
  align-items: center;
  align-self: stretch;
  background-color: var(--paper);
  border: var(--border);
  border-radius: 0;
  color: inherit;
  cursor: pointer;
  display: flex;
  font-size: 0;
  inline-size: 3rem;
  justify-content: center;
  margin-inline-start: -2px;
  padding: 0;
  transition:
    background-color 100ms,
    box-shadow 100ms,
    color 100ms,
    translate 100ms;
}

slab-date-picker::part(button)::before {
  block-size: 0.875rem;
  border: 2px solid currentcolor;
  border-block-start-width: 5px;
  content: '';
  inline-size: 1rem;
}

slab-date-picker::part(button):hover {
  background-color: var(--chalk);
}

/*
  The outline is transparent rather than gone, so it still shows in forced
  colors, where box shadows don't.
*/
slab-date-picker::part(button):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
  translate: -2px -2px;
}

slab-date-picker::part(button):disabled {
  background-color: var(--chalk);
  border-style: dashed;
  color: var(--ash);
  cursor: not-allowed;
}

slab-date-picker[open]::part(button) {
  background-color: var(--ink);
  color: var(--paper);
}

slab-date-picker:state(error)::part(button) {
  border-color: var(--ember-deep);
}

/* A closed popover isn't displayed, so the entrance runs each time it opens. */
slab-date-picker::part(popover) {
  animation: slab-date-picker-drop 150ms ease-out;
  background-color: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-family: var(--font-body);
  margin-block: 0.5rem;
  padding: 1rem;
}

@keyframes slab-date-picker-drop {
  from {
    opacity: 0;
    translate: 0 -0.375rem;
  }
}

slab-date-picker::part(calendar)::part(header) {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-block-end: 0.75rem;
}

slab-date-picker::part(calendar)::part(heading) {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
}

slab-date-picker::part(calendar)::part(previous),
slab-date-picker::part(calendar)::part(next) {
  align-items: center;
  background-color: var(--paper);
  block-size: 2.25rem;
  border: var(--border);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-size: 0;
  inline-size: 2.25rem;
  justify-content: center;
  padding: 0;
  transition: background-color 100ms;
}

slab-date-picker::part(calendar)::part(previous)::before,
slab-date-picker::part(calendar)::part(next)::before {
  block-size: 0.5rem;
  border-block-end: 2px solid currentcolor;
  border-inline-start: 2px solid currentcolor;
  content: '';
  inline-size: 0.5rem;
  rotate: 45deg;
  translate: 0.125rem 0;
}

slab-date-picker::part(calendar)::part(next)::before {
  rotate: -135deg;
  translate: -0.125rem 0;
}

slab-date-picker::part(calendar)::part(previous):hover,
slab-date-picker::part(calendar)::part(next):hover {
  background-color: var(--chalk);
}

slab-date-picker::part(calendar)::part(previous):focus-visible,
slab-date-picker::part(calendar)::part(next):focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 2px;
}

/*
  Separate rather than collapsed, so each day draws its own border whole.
  Collapsed, a day's border merges with its neighbors' and today's ring
  breaks up.
*/
slab-date-picker::part(calendar)::part(grid) {
  border-collapse: separate;
  border-spacing: 0;
}

slab-date-picker::part(calendar)::part(weekday) {
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 400;
  padding-block-end: 0.375rem;
  text-transform: uppercase;
}

slab-date-picker::part(calendar)::part(day) {
  block-size: 2.5rem;
  border: 2px solid transparent;
  box-sizing: border-box;
  cursor: pointer;
  inline-size: 2.5rem;
  text-align: center;
  transition:
    background-color 100ms,
    color 100ms;
}

slab-date-picker::part(calendar)::part(day):hover {
  background-color: var(--chalk);
}

slab-date-picker::part(calendar)::part(day):focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: -3px;
}

slab-date-picker::part(calendar)::part(today) {
  border-color: var(--ember);
}

/*
  The ring is inside the day, so on the selected one it's on ink, where
  ember falls short of 3:1 in the dark. The text's color always has the
  contrast.
*/
slab-date-picker::part(calendar)::part(selected) {
  background-color: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

slab-date-picker::part(calendar)::part(selected):focus-visible {
  outline-color: currentcolor;
}

slab-date-picker::part(calendar)::part(disabled) {
  color: var(--ash);
  cursor: not-allowed;
  text-decoration: line-through;
}

slab-date-picker::part(calendar)::part(disabled):hover {
  background-color: transparent;
}

@media (prefers-reduced-motion: reduce) {
  slab-date-picker::part(button),
  slab-date-picker::part(popover),
  slab-date-picker::part(calendar)::part(previous),
  slab-date-picker::part(calendar)::part(next),
  slab-date-picker::part(calendar)::part(day) {
    animation: none;
    transition: none;
  }
}
```

#### tokens.css

```css
:root {
  /* Secondary text. 6.8:1 and 6.9:1 on paper. */
  --ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
  --border: 2px solid var(--ink);

  /* Behind disabled and read-only controls, and hovered rows. */
  --chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));

  /*
    The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
    enough for borders, fills and large text, but not always for small text,
    which takes "--ember-deep".
  */
  --ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));

  /*
    Orange for small text on paper, and for paper text on it. 5.7:1 and
    7.4:1.
  */
  --ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
  --font-body: var(
    --slab-styled-font-body,
    'IBM Plex Sans',
    system-ui,
    sans-serif
  );
  --font-display: var(
    --slab-styled-font-display,
    'Zilla Slab',
    rockwell,
    'Roboto Slab',
    serif
  );
  --font-mono: var(
    --slab-styled-font-mono,
    'IBM Plex Mono',
    ui-monospace,
    monospace
  );
  --ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
  --paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));

  /* The hard, offset shadow a raised surface casts. */
  --shadow: 4px 4px 0 var(--ink);
}

/*
  Forced colors, such as Windows' contrast themes, replace every color that
  isn't a system color, so ember fills and paper marks all become the same
  background, and a checked Checkbox looks like an unchecked one. The palette
  becomes the user's system colors instead, which are kept. Ember is the
  highlight, the color of what's selected, and ember-deep, being for text and
  for paper text on it, is the text color.
*/
@media (forced-colors: active) {
  :host {
    --ash: GrayText;
    --chalk: Canvas;
    --ember: Highlight;
    --ember-deep: CanvasText;
    --ink: CanvasText;
    --paper: Canvas;
  }
}
```
