# Date Range Picker

> A Date Range Field with a button that opens a range Calendar in a popover, so both days are picked in one calendar that looks the same in every browser.

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

## Install

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

## Usage

### React

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

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

export function MyDateRangePicker() {
  return (
    <slab-date-range-picker label="Stay" name="stay" start-label="Check-in" end-label="Check-out" required></slab-date-range-picker>
  );
}
```

### Lit

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

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

@customElement('my-date-range-picker')
export class MyDateRangePicker extends LitElement {
  render() {
    return html`
      <slab-date-range-picker label="Stay" name="stay" start-label="Check-in" end-label="Check-out" required></slab-date-range-picker>
    `;
  }
}
```

### Vue

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

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

<template>
  <slab-date-range-picker label="Stay" name="stay" start-label="Check-in" end-label="Check-out" required></slab-date-range-picker>
</template>
```

### Svelte

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

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

<slab-date-range-picker label="Stay" name="stay" start-label="Check-in" end-label="Check-out" required></slab-date-range-picker>
```

### Ember

`MyDateRangePicker.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-range-picker.js';

export const MyDateRangePicker = <template>
  <slab-date-range-picker label="Stay" name="stay" start-label="Check-in" end-label="Check-out" required></slab-date-range-picker>
</template>;
```

### HTML

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

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

<slab-date-range-picker label="Stay" name="stay" start-label="Check-in" end-label="Check-out" required></slab-date-range-picker>
```

## Example

Here's a styled version, `<slab-styled-date-range-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-range-picker label="Pour window" start-label="Earliest" end-label="Latest" min="2026-10-12" start-value="2026-10-16" end-value="2026-10-20">
  <span slot="description">The crew needs at least one dry day in the window.</span>
</slab-styled-date-range-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 Range Field](date-range-field.md), so the two inputs, their values, validity and the form all work the same, and the form still gets the start and then the end under `name`. The browser's own pickers are hidden where they can be, and the button after the inputs opens a [Calendar](calendar.md) with `range` in a non-modal dialog named by the label. Firefox keeps its own calendar icon in each input, which can't be hidden.

Opening it focuses the range's first day, or else today, kept between `min` and `max`. The first day picked starts the range and the second ends it, in either order. Picking the second sets both values, dispatches "input" and "change", closes the calendar and puts focus back on the button. A range left half picked is dropped when the calendar closes. `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(range-start)`, `::part(range-end)`, `::part(selected)`, `::part(preview)` and the rest.

## Keyboard

| Key                  | What it does                                                                                      |
| -------------------- | ------------------------------------------------------------------------------------------------- |
| Alt+Down             | In either input, opens the calendar.                                                              |
| Enter, Space         | On the button, opens or closes the calendar. On a day, starts the range, or ends it and closes.   |
| Escape               | After the first day, starts the range over. Otherwise closes the calendar and focuses the button. |
| Arrows, Page Up/Down | Moves between days and months, as on Calendar.                                                    |
| Enter (in an input)  | Submits the form.                                                                                 |

## Behavior

A date range picker with no visual styles: a Date Range Field, with a button beside its inputs that opens a Calendar with `range` in a popover, as Date Picker does for a single date.

It's Date Range Field, so everything a Date Range Field does it does too: the two native `<input type="date">`s to type into, linked so the end is never before the start, their values, `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 both days are picked in one calendar, the same in every browser, and it can be styled. Firefox keeps a calendar icon of its own in each 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 dates" unless `button-label` is set, and is `aria-expanded` while the calendar is open. Alt+ArrowDown in either input opens it too. Opening it focuses the range's first day, or else today, kept between `min` and `max`. The first day picked starts a range and the second ends it, in either order. Picking the second sets both values, dispatches "input" and "change" as typing does, closes the calendar, and puts focus back on the button. Escape after the first day starts over, and Escape otherwise, or a click outside, closes 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. 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 Range 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-range-picker>`

#### Attributes

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `button-label` | `string` |  | The button's text and so its accessible name. "Choose dates" 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 the group. Each input is named by it and its own label. |
| `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. |
| `end-label` | `string` |  | The end input's label, read after `label`. "End" in English when unset. |
| `end-value` | `string` | `''` | The last day of the range, as "yyyy-mm-dd". Like a native input's `value`, the attribute is the default and the property is the current value. |
| `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 for either, as "yyyy-mm-dd". |
| `min` | `string` |  | The earliest date allowed for either, as "yyyy-mm-dd". |
| `name` | `string` | `''` | Submitted twice, with the start value and then the end value. |
| `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` | Requires both dates. |
| `start-label` | `string` |  | The start input's label, read after `label`. "Start" in English when unset. |
| `start-value` | `string` | `''` | The first day of the range, as "yyyy-mm-dd". Like a native input's `value`, the attribute is the default and the property is the current value. |
| `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 |
| --- | --- | --- |
| `defaultEndValue` | `string` | The end value it starts with, and goes back to when its form resets. It's the `end-value` attribute, as a native input's `defaultValue` is its `value` attribute, so setting it sets the attribute, and `endValue` with it. |
| `defaultStartValue` | `string` | The start value it starts with, and goes back to when its form resets. It's the `start-value` attribute, as a native input's `defaultValue` is its `value` attribute, so setting it sets the attribute, and `startValue` 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. |

#### Methods

| Signature | Description |
| --- | --- |
| `checkValidity(): boolean` | Whether its value is valid. Dispatches "invalid" when it isn't, as a native control's 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 |
| `container` | The label, the inputs and the description |
| `control` | The inputs and the button |
| `description` | Text about the field, and its validity message when it has one |
| `end` | The fields for the end date |
| `end-field` | The end input and its label |
| `end-label` | The end input's label |
| `field` | The start input and its label |
| `fields` | Both inputs and their labels |
| `input` | The input |
| `input-label` | The start input's label |
| `label` | The label |
| `popover` | The popover the Calendar is in |
| `start` | The fields for the start date |
| `start-field` | The start input and its label |
| `start-label` | The start input's label |
| `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-range-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-range-picker.ts

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

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

/**
 * Date Range Picker, styled: Date Range Field's look, with Date Picker's
 * calendar button after the inputs, and the styled Calendar's range look in a
 * raised popover below.
 */
@customElement('slab-styled-date-range-picker')
export default class StyledDateRangePicker extends DateRangePicker {
  static override styles = [
    tokens,
    textInput,
    dateRangeField,
    datePicker,
    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;
    }
  }
`;
```

#### date-range-field.styles.ts

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

export default css`
  [part~='fields'] {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  }

  [part~='field'] {
    display: grid;
    gap: 0.25rem;
  }

  [part~='input-label'] {
    color: var(--ash);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
`;
```

#### date-range-picker.styles.ts

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

/*
  On top of Date Picker's styles. Each input has a small label above it, so
  the button isn't butted against an input the way Date Picker's is. It sits
  apart, at the inputs' height, level with them.
*/
export default css`
  [part~='control'] {
    align-items: end;
    column-gap: 0.75rem;
  }

  [part~='button'] {
    align-self: end;
    block-size: 3rem;
    box-sizing: border-box;
    margin-inline-start: 0;
  }

  /*
    As the styled Calendar draws a range: hatched while it's being picked, so
    the days don't read as chosen yet, then a band of chalk between its ends,
    which are ink like a single selected day.
  */
  [part~='calendar']::part(preview) {
    background-image: repeating-linear-gradient(
      -45deg,
      var(--chalk) 0 4px,
      transparent 4px 8px
    );
  }

  [part~='calendar']::part(selected),
  [part~='calendar']::part(selected):hover {
    background-color: var(--chalk);
    background-image: none;
    color: var(--ink);
    font-weight: 400;
  }

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

  [part~='calendar']::part(range-start),
  [part~='calendar']::part(range-end),
  [part~='calendar']::part(range-start):hover,
  [part~='calendar']::part(range-end):hover {
    background-color: var(--ink);
    color: var(--paper);
    font-weight: 600;
  }

  [part~='calendar']::part(range-start):focus-visible,
  [part~='calendar']::part(range-end):focus-visible {
    outline-color: currentcolor;
  }
`;
```

#### 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-range-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-range-picker.js` once, such as in your root layout, and use `<slab-date-range-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.

#### DateRangePicker.jsx

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

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

#### DateRangePicker.vue

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

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

#### date-range-picker.js

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

#### DateRangePicker.gjs

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

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

#### date-range-picker.css

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

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

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

slab-date-range-picker::part(input),
slab-date-range-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-range-picker::part(input)::placeholder,
slab-date-range-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-range-picker::part(input):focus-visible,
slab-date-range-picker::part(textarea):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
  translate: -2px -2px;
}

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

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

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

slab-date-range-picker:state(error)::part(input),
slab-date-range-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-range-picker::part(description) {
  color: var(--ash);
  display: grid;
  font-size: 0.875rem;
}

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

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

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

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

slab-date-range-picker::part(fields) {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

slab-date-range-picker::part(field) {
  display: grid;
  gap: 0.25rem;
}

slab-date-range-picker::part(input-label) {
  color: var(--ash);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

slab-date-range-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-range-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-range-picker::part(button)::before {
  block-size: 0.875rem;
  border: 2px solid currentcolor;
  border-block-start-width: 5px;
  content: '';
  inline-size: 1rem;
}

slab-date-range-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-range-picker::part(button):focus-visible {
  box-shadow: 4px 4px 0 var(--ember);
  outline: 2px solid transparent;
  translate: -2px -2px;
}

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

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

slab-date-range-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-range-picker::part(popover) {
  animation: slab-date-range-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-range-picker-drop {
  from {
    opacity: 0;
    translate: 0 -0.375rem;
  }
}

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

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

slab-date-range-picker::part(calendar)::part(previous),
slab-date-range-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-range-picker::part(calendar)::part(previous)::before,
slab-date-range-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-range-picker::part(calendar)::part(next)::before {
  rotate: -135deg;
  translate: -0.125rem 0;
}

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

slab-date-range-picker::part(calendar)::part(previous):focus-visible,
slab-date-range-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-range-picker::part(calendar)::part(grid) {
  border-collapse: separate;
  border-spacing: 0;
}

slab-date-range-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-range-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-range-picker::part(calendar)::part(day):hover {
  background-color: var(--chalk);
}

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

slab-date-range-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-range-picker::part(calendar)::part(selected) {
  background-color: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

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

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

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

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

slab-date-range-picker::part(control) {
  align-items: end;
  column-gap: 0.75rem;
}

slab-date-range-picker::part(button) {
  align-self: end;
  block-size: 3rem;
  box-sizing: border-box;
  margin-inline-start: 0;
}

/*
  As the styled Calendar draws a range: hatched while it's being picked, so
  the days don't read as chosen yet, then a band of chalk between its ends,
  which are ink like a single selected day.
*/
slab-date-range-picker::part(calendar)::part(preview) {
  background-image: repeating-linear-gradient(
    -45deg,
    var(--chalk) 0 4px,
    transparent 4px 8px
  );
}

slab-date-range-picker::part(calendar)::part(selected),
slab-date-range-picker::part(calendar)::part(selected):hover {
  background-color: var(--chalk);
  background-image: none;
  color: var(--ink);
  font-weight: 400;
}

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

slab-date-range-picker::part(calendar)::part(range-start),
slab-date-range-picker::part(calendar)::part(range-end),
slab-date-range-picker::part(calendar)::part(range-start):hover,
slab-date-range-picker::part(calendar)::part(range-end):hover {
  background-color: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

slab-date-range-picker::part(calendar)::part(range-start):focus-visible,
slab-date-range-picker::part(calendar)::part(range-end):focus-visible {
  outline-color: currentcolor;
}
```

#### 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;
  }
}
```
