Components · Controls

Custom date range picker

A calendar for picking any start and end date, with no presets.

Open in playground

Preview

Date range

Usage

tsx
import { useState } from 'react';
import { ChartsProvider, DateRangePickerCustom } from 'em-kit';
import type { TimeRange } from 'em-kit';

export const Example = () => {
  const [range, setRange] = useState<TimeRange>();
  return (
    <ChartsProvider>
      <div style={{ width: 320 }}>
        <DateRangePickerCustom
          title="Date range"
          selectedValue={range}
          onChange={setRange}
        />
      </div>
    </ChartsProvider>
  );
};

Install with npm install em-kit. Needs <ChartsProvider> once, and your own state for its value: Quick start.

Examples

Two months

The calendar shows two months side by side, for ranges that cross a month.

tsxDiffers from Usage
Show full code (19 lines)
import { useState } from 'react';
import { ChartsProvider, DateRangePickerCustom } from 'em-kit';
import type { TimeRange } from 'em-kit';

export const Example = () => {
  const [range, setRange] = useState<TimeRange>();
  return (
    <ChartsProvider>
      <div style={{ width: 320 }}>
        <DateRangePickerCustom
          title="Date range"
          selectedValue={range}
          onChange={setRange}
          showTwoMonths
        />
      </div>
    </ChartsProvider>
  );
};
<DateRangePickerCustom
  title="Date range"
  selectedValue={range}
  onChange={setRange}
  showTwoMonths
/>

Props

Keyboard and screen readers: Accessibility.

PropTypeDefaultDescription
onChangerequired(newDateRange: TimeRange) => voidCalled with the range the reader picks, from the start of its first day to the end of its last in the provider’s time zone, or with undefined when the reader clears it.
placeholderstring"Select a date-range"Text shown while nothing is chosen. Translates like title.
selectedValueTimeRangeThe chosen range: { from: Date, to: Date }, with an optional relativeTimeString naming a preset.
clearablebooleantrueLet the reader clear the value.
showTwoMonthsbooleanfalseShow two months side by side in the calendar.
componentNamestringA name for this component, included in the interaction events it dispatches on the DOM, for your analytics.
trackingIdstringAn id included in the same events, to tell two instances apart.
titlestringThe title over the field. A "key|fallback" string is looked up in your translations.
descriptionstringSmaller text under the title. Translates like title.
tooltipstringText for an info icon beside the title.

A blank default means the prop is unset unless you pass it.

TypeDefinition
TimeRange{ from: Date | undefined; to: Date | undefined; relativeTimeString?: string; } | undefinedWhat a click’s TimeRange holds: Events.

Field options

DateRangePickerCustom reads only the common options in a field’s inputs.