1. Components
  2. Date Range Picker

Components

Date Range Picker

A simple yet powerful Date Picker with ranges.

   

Import DateRangePicker

Tremor exports one component for DateRangePicker. The type of its value, DateRangePickerValue is exported as well.

import { DateRangePicker, DateRangePickerValue } from "@tremor/react";

Usage example

The example below shows a date range picker without the relative dates menu.

import { DateRangePicker } from "@tremor/react";

export default () => (
  <DateRangePicker className="max-w-sm mx-auto" enableDropdown={false} />
);

Controlled state example with alternative language locale

The example below shows a date range picker with a controlled state and the Spanish locale, e.g. { en }. Note that for all locales other than English { enUS } you have to import the locale from date-fns.

import { useState } from "react";
import { DateRangePicker, DateRangePickerValue } from "@tremor/react";
import { es } from "date-fns/locale";

export function DateRangePickerSpanish() {
  const [value, setValue] = useState<DateRangePickerValue>([
    new Date(2022, 1, 1),
    new Date(),
  ]);

  return (
    <DateRangePicker
      className="max-w-md mx-auto"
      value={value}
      onValueChange={setValue}
      locale={es}
      dropdownPlaceholder="Seleccionar"
    />
  );
}

API Reference: DateRangePicker

client component

valueoptional
Description
Sets the date range and optionally a dropdown option value. Per default, availble ranges are 'tdy' (Today), 'w' (Last 7 days), 't' (Last 30 days), 'm' (Month to date), 'y' (Year to date)
Type
DateRangePickerValue = [Date | null | undefined, Date | null | undefined, (string | null)?]
Default
Values
e.g. [new Date(2022, 1, 1), new Date()], [undefined, undefined, 'tdy']
onValueChangeoptional
Description
Event handler called when the state of the datepicker changes.
Type
(value: DateRangePickerValue) => void
Default
Values
defaultValueoptional
Description
Sets the date range and optionally a dropdown option value. Per default, availble ranges are 'tdy' (Today), 'w' (Last 7 days), 't' (Last 30 days), 'm' (Month to date), 'y' (Year to date)
Type
DateRangePickerValue = [Date | null | undefined, Date | null | undefined, (string | null)?]
Default
Values
e.g. [new Date(2022, 1, 1), new Date()], [undefined, undefined, 'tdy']
enableClearoptional
Description
Enables the ability to clear a date range selection.
Type
boolean
Default
true
Values
true, false
optionsoptional
Description
Overwrite the default dropdown options. It is recommended to use the date-fns utility library for calculating the startDate and endDate (optional, Today() is the default value)
Type
Array
Default
null
Values
e.g. [{ value: 'tdy', text: 'Today', startDate: new Date() }, { value: 'f', text: 'Last 5 Years', startDate: sub(new Date(), { years: 5 }) }, { value: 't', text: 'ChristmasHoliday', startDate: new Date(2022, 12, 23), endDate: new Date(2022, 12, 26)}]
enableDropdownoptional
Description
Enables the dropdown menu.
Type
boolean
Default
true
Values
true, false
placeholderoptional
Description
Sets the placeholder text of the DateRangePicker
Type
string
Default
Select
Values
dropdownPlaceholderoptional
Description
Sets the placeholder text of the optional Date Range Dropdown
Type
string
Default
Select
Values
disabledoptional
Description
Set the state of the element to disabled.
Type
boolean
Default
false
Values
true, false
localeoptional
Description
Sets the placeholder text of the optional Date Range Dropdown. Note that for all locales other than English {enUS} you have to import the locale from `date-fns`. E.g. {frCH} for French locale (Switzerland)
Type
locale
Default
enUS
Values
enableYearPaginationoptional
Description
Adds additional buttons to jump through years.
Type
boolean
Default
false
Values
true, false
minDateoptional
Description
Controls the mininmum available date.
Type
Date | null
Default
Values
e.g. new Date(2022, 12, 31)
maxDateoptional
Description
Controls the maximum available date.
Type
Date | null
Default
Values
e.g. new Date(2022, 12, 31)