0.10.5 • Published 6 years ago

react-date-range-next v0.10.5

Weekly downloads
23
License
MIT
Repository
github
Last release
6 years ago

react-date-range

npm npm.io

npm npm

⚠️ Warning: the current branch represents v2 pre-release version. See v1 branch.

A library agnostic React component for choosing dates and date ranges. Uses date-fns for date operations.

Why should you use react-date-range?

  • Stateless date operations
  • Highly configurable
  • Multiple range selection
  • Based on native js dates
  • Drag n Drop selection
  • Keyboard friendly

Live Demo : http://adphorus.github.io/react-date-range

npm.io

Getting Started

Installation

yarn add react-date-range@next

If you don't use yarn

$ npm install --save react-date-range@next

Usage

Date Picker

import React, { Component } from 'react';
import { Calendar } from 'react-date-range';
// main style file
import 'react-date-range/dist/styles.css';
// theme css file
import 'react-date-range/dist/theme/default.css';


class MyComponent extends Component {
	handleSelect(date){
		console.log(date); // native Date object
	}

	render(){
		return (
			<div>
				<Calendar
					date={new Date()}
					onChange={this.handleSelect}
				/>
			</div>
		)
	}
}

Range Picker

import React, { Component } from 'react';
import { DateRange } from 'react-date-range';

class MyComponent extends Component {
	handleSelect(range){
		console.log(range);
		// An object with two keys,
		// 'startDate' and 'endDate' which are Momentjs objects.
	}

	render(){
		return (
			<div>
				<DateRange
					onInit={this.handleSelect}
					onChange={this.handleSelect}
				/>
			</div>
		)
	}
}

Options (DateRange, Calendar)

PropertytypeDefault ValueDesctiption
localeObjectenUS from localeyou can view full list from here. Locales directly exported from date-fns/locales.
classNameStringwrapper classname
monthsNumber1rendered month count
showSelectionPreviewBooleantrueshow preview on focused/hovered dates
previewColorStringdefines color for selection preview
shownDateDateinitial focus date
specialDaysDate[][]defines special days
onPreviewChangeFunccallback for preview changes. fn()
minDateDatedefines minimum date. Disabled earlier dates
maxDateDatedefines maximum date. Disabled later dates
showMonthArrowBooleantrueshow/hide month arrow button
onChange(Calendar)Funccallback function for date changes. fn(date: Date)
color(Calendar)String#3d91ffdefines color for selected date in Calendar
date(Calendar)Datedate value for Calendar
onChange(DateRange)Funccallback function for range changes. fn(changes). changes contains startDate and endDate under an object key of changed range
moveRangeOnFirstSelection(DateRange)Booleanfalsemove range on startDate selection. Otherwise endDate will replace with startDate.
ranges(Calendar)*Object[][]Defines ranges. array of range object
showDateDisplay(DateRange)Booleantrueshow/hide selection display row. Uses dateDisplayFormat for formatter
dateDisplayFormat(DateRange)StringMMM D,YYYYselected range preview formatter. checkout date-fns's format option

*shape of range:

	{
		startDate: PropTypes.object,
		endDate: PropTypes.object,
		color: PropTypes.string,
		key: PropTypes.string,
		autoFocus: PropTypes.bool,
		disabled: PropTypes.bool,
		show: PropTypes.bool,
		showDateDisplay: PropTypes.bool,
	}

TODOs

  • make mobile friendly (integrate tap and swipe actions)
  • add complex booking customization example with exposed renderer props