Home

Awesome

reactjs-datetime-range-picker

ReactJS datetime range picker with daily, weekly, monthly, quarterly & yearly levels

npm version

This plugin uses bootstrap and moment.js. This plugin can render the components from any UI library you are using in your app as long as the UI library exports Input, Select and Button components.

Demo

Storybook demo

Angular Version

ngx-datetime-range-picker

Installation

Install the plugin:

# npm
npm install reactjs-datetime-range-picker --save-dev

# yarn
yarn add reactjs-datetime-range-picker --dev

Using the basic HTML components

import React from "react";
import {
  ReactJSDatetimeRangePicker,
  DateRangeModel,
  Options,
  Settings,
} from "reactjs-datetime-range-picker";

const SomeComponent: React.FC<Props> = ({}) => {
  const dateRangeModel: DateRangeModel = {...};
  const options: Options = {...};
  const settings: Settings = {...};

  const onDateSelect = (options: Options) => {
    console.log(options);
    /**
     * {
     *   startDate: "2018-10-13",
     *   endDate: "2018-10-19",
     * },
     */
  };

  return <>
    ...
    <ReactJSDatetimeRangePicker
      canBeEmpty={false}
      dateRangeModel={dateRangeModel}
      options={options}
      settings={settings}
      onDateSelect={onDateSelect}
      onDateRangeModelChange={(options: Options | DateRangeModel) => console.log(options)}
      onDateRangeChange={(options: Options) => console.log(options)}
      onInputBlur={(options: Record<string, unknown>) => console.log(options)}
    />
  </>
}

Using the components from the library you are using. Example: NextUI

Assumpition is that you have already installed the UI library you will be using.

import React from "react";
import {
  ReactJSDatetimeRangePicker,
  DateRangeModel,
  Options,
  Settings,
  SELECT_AS
} from "reactjs-datetime-range-picker";
import { Input } from "@nextui-org/input";
import { Button } from "@nextui-org/button";
import { Select, SelectItem } from "@nextui-org/select";

const SomeComponent: React.FC<Props> = ({}) => {
  const dateRangeModel: DateRangeModel = {...};
  const options: Options = {...};
  const settings: Settings = {...};
  const selectAs: SELECT_AS = {
    tag: Select,
    optionTag: SelectItem,
    selectedAttributeName: "defaultSelectedKeys", // specify the propery that your library uses for default value selection
    selectedAttributeValueType: "array", // specify if the above property accepts default value in array or string
  };
  
  const onSelectedDate = (options: Options) => {
    console.log(options);
    /**
     * {
     *   startDate: "2018-10-13",
     *   endDate: "2018-10-19",
     * },
     */
  };

  return <>
    ...
    <ReactJSDatetimeRangePicker
      canBeEmpty={false}
      onDateSelect={{
        daily: {
          endDate: '2024-03-23',
          startDate: '2024-03-23'
        },
        weekly: {
          endDate: '2024-03-23',
          startDate: '2024-03-17'
        }
      }}
      
      displayEndDate={true}
      inputDateFormat="YYYY-MM-DD"
      label="Date"
      placeholder="Date"
      showRowNumber
      singleDatePicker
      type="daily"
      viewDateFormat="MMM D, YYYY"
      inputAs={Input}
      selectAs={selectAs}
      buttonAs={Button}
      onDateSelect={onDateSelect}
      onDateRangeModelChange={(options: Options | DateRangeModel) => console.log(options)}
      onDateRangeChange={(options: Options) => console.log(options)}
      onInputBlur={(options: Record<string, unknown>) => console.log(options)}
    />
  </>
}

Properties

PropertyTypeDefaultDescription
typestring'daily'type (daily
timePickerbooleanfalseenable/disable timepicker
inputDateFormatstring"YYYY-MM-DD"input date format
viewDateFormatstring"YYYY-MM-DD"date format to view the date in
outputDateFormatstring"YYYY-MM-DD"date format in which change event will return the date in
singleDatePickerbooleanfalseenable/disable single date picker
componentDisabledstringfalseenable/disable component
placeholderstring"Select Date"placeholder/title of the component
showRowNumberbooleantruehide/show week numers for daily
availableRangesObject{"Last 7 Days": {startDate: inputDateFormat, endDate: inputDateFormat}, "Last 30 days": {...}, "Last 90 days": {...}}ranges to show
showRangesbooleantruehide/show ranges
disableWeekendsbooleanfalseenable/disable weekends
disableWeekdaysbooleanfalseenable/disable weekdays
displayBeginDatebooleanfalseshow begin date in input
displayEndDatebooleanfalseshow end date in input
dateArrayArray[]Only the dates in the array will be enabled
startDatestringToday's dateStart date
endDatestringToday's dateEnd date
minDatestringCurrent Year - 2Min date
maxDatestringToday's dateMax date
startTimestring"00:00"Start time (only for timepicker)
endTimestring"23:59"End time (only for timepicker)
minTimestringMin time (only for timepicker)
maxTimestringMax time (only for timepicker)
onDateRangeModelChangefunctionfunction(options: Options | DateRangeModel) {}Emits the date range model when the calendar is closed
onDateSelectfunctionfunction(options: Options) {}Emits date when date is selected
onDateRangeChangefunctionfunction(options: Options) {}Emits the selected date and time when the calendar is closed
onInputBlurfunctionfunction(options: Record<string, unknown>) {}Emitted when the date input is blurred

License

MIT