DateRangePicker
A date range control in one of two layouts.
Pick both dates to see the length of the stay.
View code
let checkIn = "";
let checkOut = "";
// The fields own their values; the island only reads them back, so nothing it
// renders can overwrite a date the reader picked.
function readFields(event: Event) {
let field = event.target as HTMLInputElement;
if (field.name === "checkIn") checkIn = field.value;
else if (field.name === "checkOut") checkOut = field.value;
else return;
void handle.update();
}
<DateRangePicker mix={[on<HTMLDivElement, "change">("change", readFields)]}>
<Label htmlFor="checkIn">Dates of stay</Label>
<DateRangePicker.Group>
<Input id="checkIn" type="date" name="checkIn" aria-label="Check in" />
<Input id="checkOut" type="date" name="checkOut" aria-label="Check out" />
</DateRangePicker.Group>
<Description>
{stayLengthHint(parseDayValue(checkIn), parseDayValue(checkOut))}
</Description>
</DateRangePicker>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Or copy it into your project to edit it:
sdxc ui add date-range-pickerUsage
import { DateRangePicker } from "@sdxc/ui";Renders DateRangePicker's root in its layout, holding the parts the caller
writes in the order written.
Examples
Composed parts
View code
<DateRangePicker>
<Label htmlFor="trip-start">Trip dates</Label>
<DateRangePicker.Group>
<Input id="trip-start" type="date" name="tripStart" aria-label="Departure" />
<Input id="trip-end" type="date" name="tripEnd" aria-label="Return" />
</DateRangePicker.Group>
</DateRangePicker>Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
layout | "joined" | "split" | — | No | How the range lays out its children. Defaults to DEFAULT_LAYOUT. |
Also accepts everything in TagProps<"div">.
Types
| Name | Values | What it decides |
|---|---|---|
Layout | "joined" | "split" | "joined" stacks a caption, the DateRangePicker.Group row and any supporting copy in a column. |