SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

DateRangePicker

A date range control in one of two layouts.

Pick both dates to see the length of the stay.

View code
tsx
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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add date-range-picker

Usage

typescript
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
tsx
<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.

PropTypeDefaultRequiredDescription
layout"joined" | "split"—NoHow the range lays out its children. Defaults to DEFAULT_LAYOUT.

Also accepts everything in TagProps<"div">.

Types

NameValuesWhat it decides
Layout"joined" | "split""joined" stacks a caption, the DateRangePicker.Group row and any supporting copy in a column.
@sdxc/ui

Can’t find it? Contact us