Custom date range picker
A calendar for picking any start and end date, with no presets.
Preview
Date range
Usage
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.
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.
| Prop | Type | Default | Description |
|---|---|---|---|
onChangerequired | ( | Called 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. | |
placeholder | string | "Select a date-range" | Text shown while nothing is chosen. Translates like title. |
selectedValue | TimeRange | The chosen range: { from: Date, to: Date }, with an optional relativeTimeString naming a preset. | |
clearable | boolean | true | Let the reader clear the value. |
showTwoMonths | boolean | false | Show two months side by side in the calendar. |
componentName | string | A name for this component, included in the interaction events it dispatches on the DOM, for your analytics. | |
trackingId | string | An id included in the same events, to tell two instances apart. | |
title | string | The title over the field. A "key|fallback" string is looked up in your translations. | |
description | string | Smaller text under the title. Translates like title. | |
tooltip | string | Text for an info icon beside the title. |
A blank default means the prop is unset unless you pass it.
| Type | Definition |
|---|---|
TimeRange | { from: Date |What a click’s TimeRange holds: Events. |
Field options
DateRangePickerCustom reads only the common options in a field’s inputs.