1.0.0-alpha0 • Published 8 years ago

react-date-range v1.0.0-alpha0

Weekly downloads
63,883
License
MIT
Repository
-
Last release
8 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
directionString'vertical'defines maximum date. Disabled later dates
scrollObject{ enabled: false }infinite scroll behaviour configuration. Checkout Infinite Scroll section
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,
	}

Infinite Scrolled Mode

To enable infinite scroll set `scroll={{enabled: true}}` basically. Infinite scroll feature is affected by `direction`(rendering direction for months) and `months`(for rendered months count) props directly.
If you prefer, you can overwrite calendar sizes with `calendarWidth`/`calendarHeight` or each month's height/withs with `monthWidth`/`monthHeight`/`longMonthHeight` at `scroll` prop.
	// shape of scroll prop
  scroll: {
    enabled: PropTypes.bool, 
    monthHeight: PropTypes.number,
    longMonthHeight: PropTypes.number, // some months has 1 more row than others
    monthWidth: PropTypes.number, // just used when direction="horizontal"
    calendarWidth: PropTypes.number, // defaults monthWidth * months
    calendarHeight: PropTypes.number, // defaults monthHeight * months
  }),

TODOs

  • make mobile friendly (integrate tap and swipe actions)
  • add complex booking customization example with exposed renderer props
agent-interface@srijan-alm/alm-search-01@srijan-alm/almosafer-search@srijan-alm/alm-searchalm-cra-searchalm-search-02alm-search-03alm-search-04alm-search-05alm-search-06alm-search-07almosafer-searchchancellorrrcbi-packageslash-common-components@rhinolabs/levantr-khaositem-editingreact-approveme-uipdxdeploy-v3.1.3facit-litechina-dashboard@clockbook-app/timetracker-module-browsertaskbox-cici@infinitebrahmanuniverse/nolb-react-daapplication-auction-packagesapplication-buyer-dealsapplication-dealsipm_fe_frameworkcomments-library-v2bhayangkara-ui2@everything-registry/sub-chunk-2549nineid-corecommon-navbar-reactweekly-progwakeflow-designweathertrack-ui-libweb-modules-corewpvibes-componentsxadmin-bootstrapsushiwebthis-oneux-thebackyardvmo-librarycreate-next-entity-form-crafter-newdigit-ui-react-componentsjrx-react-feeling-uikalachakra_componentsjumbouiibbiz-react-componenticp-componentsimbric-themehooly-ui-kithound-uihplx-react-elementshplx-react-elements-devhalo-ui-elements-librarylevantr-khaoslondonmanager-legosmayao-ui-newmctm-plmctm-ui@travelpassero/khaos@upyog/digit-ui-module-dss@upyog/digit-ui-react-components@vksci123/hasura-modules@yan_coquoz/react_input@zalastax/nolb-react-daalm-search-01@zimyo/componentsabsence-yol-calendarabsdfafafaffsabsdsanswers-ui-libby-publicargousars-febackpack-uifully-frameworkfrst-componentsgeneral-input-libgale-dash-core-componentsefc-packageefc-yashdompetku-ui-libec_commdsgsdfgenidesignsystem-reactentity-form-crafter-frontendenergy_machines_jupyter_reportselectraeoempower-containerempower-custom-containereye-designfluna-ui-libraryfit-datepickerfareye-transport-uicf-neo-uicalendar-reactjs-frontendci_dashboardcommon-searchmodal-reactchaincodedev-form-builder
2.0.1

2 years ago

2.0.0-alpha.3

2 years ago

2.0.0-alpha.4

2 years ago

2.0.0-alpha.2

2 years ago

1.4.0

4 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.4

5 years ago

1.1.4-alpha.2

5 years ago

1.1.4-alpha.1

5 years ago

1.1.4-alpha.3

5 years ago

1.1.3

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-beta2

7 years ago

1.0.0-beta

8 years ago

1.0.0-alpha6

8 years ago

1.0.0-alpha5

8 years ago

1.0.0-alpha4

8 years ago

1.0.0-alpha3

8 years ago

1.0.0-alpha2

8 years ago

1.0.0-alpha1

8 years ago

1.0.0-alpha0

8 years ago

0.9.4

9 years ago

0.9.3

9 years ago

0.9.2

9 years ago

0.9.0

9 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.0

10 years ago