Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 13ba8a4

Browse files
committed
initial commit for V2
1 parent 1bad340 commit 13ba8a4

38 files changed

+2711
-2008
lines changed

. eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/node_modules/*
22
/lib/*
3-
/dist/*
3+
/dist/*

.babelrc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
"react"
55
],
66
"plugins": [
7-
[
8-
"transform-object-rest-spread",
9-
"add-module-exports"
10-
]
7+
"date-fns",
8+
"transform-object-rest-spread",
9+
"transform-export-extensions"
1110
]
1211
}

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ module.exports = {
2424
"node": true,
2525
"browser": true,
2626
"jest": true,
27-
2827
},
2928
};

README.md

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,49 @@
55
[![npm](https://img.shields.io/npm/l/react-date-range.svg?style=flat-square)]()
66
[![npm](https://img.shields.io/npm/dm/localeval.svg?style=flat-square)](https://www.npmjs.com/package/react-date-range)
77

8+
⚠️ Warning: the current branch represents v2 pre-release version. See [v1 branch](https://github.com/Adphorus/react-date-range/tree/v1).
89

9-
A React component for choosing dates and date ranges. Uses [Moment.js](http://momentjs.com/) for date operations.
10+
A library agnostic React component for choosing dates and date ranges. Uses [date-fns](http://date-fns.org/) for date operations.
11+
Stateless date operations, highly configurable, multiple range selection support, based on js dates.
1012

1113
**Live Demo :** [http://adphorus.github.io/react-date-range](http://adphorus.github.io/react-date-range)
1214

13-
![](https://cdn.pbrd.co/images/1fjQlZzy.png)
15+
![](https://raw.githubusercontent.com/Adphorus/react-date-range/next/demo/assets/src/ss.png)
1416

15-
## React Range Picker v2 is coming!💥
16-
17-
** Want to help us testing the next version? Let's go
18-
[next branch](https://github.com/adphorus/react-date-range/tree/next)!**
1917

2018
## Getting Started
2119
### Installation
2220

2321
```
24-
$ npm install --save react-date-range
22+
yarn add react-date-range@next
23+
```
24+
25+
If you don't use yarn
26+
```
27+
$ npm install --save react-date-range@next
2528
```
2629

2730
## Usage
2831
### Date Picker
2932
```javascript
3033
import React, { Component } from 'react';
3134
import { Calendar } from 'react-date-range';
35+
// main style file
36+
import 'react-date-range/dist/styles.css';
37+
// theme css file
38+
import 'react-date-range/dist/theme/default.css';
39+
3240

3341
class MyComponent extends Component {
3442
handleSelect(date){
35-
console.log(date); // Momentjs object
43+
console.log(date); // native Date object
3644
}
3745

3846
render(){
3947
return (
4048
<div>
4149
<Calendar
42-
onInit={this.handleSelect}
50+
date={new Date()}
4351
onChange={this.handleSelect}
4452
/>
4553
</div>
@@ -49,17 +57,6 @@ class MyComponent extends Component {
4957

5058
```
5159

52-
###### Available Options (props)
53-
* **date:** *(String, Moment.js object, Function)* - default: today
54-
* **format:** *(String)* - default: DD/MM/YYY
55-
* **firstDayOfWeek** *(Number)* - default: [moment.localeData().firstDayOfWeek()](http://momentjs.com/docs/#/i18n/locale-data/)
56-
* **theme:** *(Object)* see [Demo's source](https://github.com/Adphorus/react-date-range/blob/master/demo/src/components/Main.js#L130)
57-
* **onInit:** *(Function)* default: none
58-
* **onChange:** *(Function)* default: none
59-
* **minDate:** *(String, Moment.js object, Function)* default: none
60-
* **maxDate:** *(String, Moment.js object, Function)* default: none
61-
* **lang:** *(String, 'cn' - Chinese, 'jp' - Japanese, 'fr' - French, 'it' - Italian, 'de' - German, 'es' - Spanish, 'ru' - Russian, 'tr' - Turkish, 'pt' - Portuguese, 'fi' - Finnish)* default: none
62-
6360
### Range Picker
6461
```javascript
6562
import React, { Component } from 'react';
@@ -85,3 +82,42 @@ class MyComponent extends Component {
8582
}
8683

8784
```
85+
### Options (DateRange, Calendar)
86+
Property | type | Default Value | Desctiption
87+
-------------------------------------|-----------|------------------|-----------------------------------------------------------------
88+
locale | object | enUS from locale | you can view full list from [here](https://github.com/Adphorus/react-date-range/tree/next/src/locale/index.js). Locales directly exported from [`date-fns/locales`](https://date-fns.org/v2.0.0-alpha.7/docs/I18n#supported-languages).
89+
className | String | | wrapper classname
90+
months | Number | 1 | rendered month count
91+
showSelectionPreview | Boolean | true | show preview on focused/hovered dates
92+
previewColor | String | | defines color for selection preview
93+
shownDate | Date | | initial focus date
94+
specialDays | Date[] | [] | defines special days
95+
onPreviewChange | Func | | callback for preview changes. fn()
96+
minDate | Date | | defines minimum date. Disabled earlier dates
97+
maxDate | Date | | defines maximum date. Disabled later dates
98+
showMonthArrow | Boolean | true |
99+
ranges(Calendar) | *Object[] | [] |
100+
onChange(Calendar) | Func | | callback function for date changes. fn(date: Date)
101+
color(Calendar) | String | `#3d91ff` | defines color for selected date in Calendar
102+
date(Calendar) | Date | | date value for Calendar
103+
onChange(DateRange) | Func | | callback function for range changes. fn(changes). changes contains `startDate` and `endDate` under an object key of changed range
104+
moveRangeOnFirstSelection(DateRange) | Boolean | false | move range on startDate selection. Otherwise endDate will replace with startDate.
105+
dateDisplayFormat(DateRange) | String | `MMM D,YYYY` | selected range preview formatter. checkout [format option](https://date-fns.org/v2.0.0-alpha.7/docs/format)
106+
> *shape of range:
107+
> ```js
108+
> {
109+
> startDate: PropTypes.object,
110+
> endDate: PropTypes.object,
111+
> color: PropTypes.string,
112+
> key: PropTypes.string,
113+
> autoFocus: PropTypes.bool,
114+
> disabled: PropTypes.bool,
115+
> }
116+
>```
117+
118+
TODOs
119+
120+
- make mobile friendly (integrate tap and swipe actions)
121+
- add complex booking customization example with exposed renderer props
122+
- drag and drop date selection
123+

demo/assets/ss.png

114 KB
Loading

0 commit comments

Comments
 (0)