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

Commit 017f3d9

Browse files
committed
- add infinite scroll
- expose mont&tyear renderer - add visual improvements
1 parent 8ee6358 commit 017f3d9

File tree

14 files changed

+592
-184
lines changed

14 files changed

+592
-184
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,14 @@ Momentjs: `moment(dateString).toDate()`
113113
- `init` prop removed.
114114

115115
### Added
116+
- `DefinedRanges` component: It's a set of date presets. Receives `inputRanges`, `staticRanges` for setting date ranges.
117+
- `DateRangePicker` component. It's combined version of `DateRange` with `DefinedRanges` component.
118+
- Date range selection by drag.
119+
- Infinite scroll feature. Sample usage:
120+
```js
121+
const horizontalScroll={enabled: true, monthHeight: 300, monthWidth: 300 };
122+
const verticalScroll={enabled: true, monthHeight: 220, longMonthHeight: 240 };
123+
<DateRangePicker scroll={horizontalScroll} />
124+
<DateRangePicker scroll={verticalScroll} months={2} />
125+
```
116126

117-
- Date range selection by drag n drop.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ specialDays | Date[] | [] | defines sp
103103
onPreviewChange | Func | | callback for preview changes. fn()
104104
minDate | Date | | defines minimum date. Disabled earlier dates
105105
maxDate | Date | | defines maximum date. Disabled later dates
106+
direction | String | 'vertical' | defines maximum date. Disabled later dates
107+
scroll | Object | { enabled: false }| infinite scroll behaviour configuration. Checkout [Infinite Scroll](#infinite-scrolled-mode) section
106108
showMonthArrow | Boolean | true | show/hide month arrow button
107109
onChange(Calendar) | Func | | callback function for date changes. fn(date: Date)
108110
color(Calendar) | String | `#3d91ff` | defines color for selected date in Calendar
@@ -112,6 +114,8 @@ moveRangeOnFirstSelection(DateRange) | Boolean | false | move range
112114
ranges(Calendar) | *Object[] | [] | Defines ranges. array of range object
113115
showDateDisplay(DateRange) | Boolean | true | show/hide selection display row. Uses `dateDisplayFormat` for formatter
114116
dateDisplayFormat(DateRange) | String | `MMM D,YYYY` | selected range preview formatter. checkout [date-fns's format option](https://date-fns.org/v2.0.0-alpha.7/docs/format)
117+
118+
115119
> *shape of range:
116120
> ```js
117121
> {
@@ -126,6 +130,24 @@ dateDisplayFormat(DateRange) | String | `MMM D,YYYY` | selected r
126130
> }
127131
>```
128132
133+
#### Infinite Scrolled Mode
134+
135+
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.
136+
If you prefer, you can overwrite calendar sizes with `calendarWidth`/`calendarHeight` or each month's height/withs with `monthWidth`/`monthHeight`/`longMonthHeight` at `scroll` prop.
137+
138+
```js
139+
// shape of scroll prop
140+
scroll: {
141+
enabled: PropTypes.bool,
142+
monthHeight: PropTypes.number,
143+
longMonthHeight: PropTypes.number, // some months has 1 more row than others
144+
monthWidth: PropTypes.number, // just used when direction="horizontal"
145+
calendarWidth: PropTypes.number, // defaults monthWidth * months
146+
calendarHeight: PropTypes.number, // defaults monthHeight * months
147+
}),
148+
```
149+
150+
129151
TODOs
130152

131153
- make mobile friendly (integrate tap and swipe actions)

demo/src/components/Main.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ export default class Main extends Component {
6767
this.state = {
6868
dateRange: {
6969
selection: {
70-
startDate: addDays(new Date(), 1115),
70+
startDate: new Date(),
71+
endDate: null,
72+
},
73+
},
74+
dateRangePickerI: {
75+
selection: {
76+
startDate: new Date(),
7177
endDate: null,
7278
},
7379
},
@@ -81,7 +87,7 @@ export default class Main extends Component {
8187
endDate: addDays(new Date(), 8),
8288
},
8389
},
84-
datePickerInternational: addDays(new Date(), 1167),
90+
datePickerInternational: new Date(),
8591
locale: 'ja',
8692
dateRangePicker: {
8793
selection: {
@@ -129,7 +135,6 @@ export default class Main extends Component {
129135
<div>
130136
<DateRangePicker
131137
onChange={this.handleRangeChange.bind(this, 'dateRangePicker')}
132-
showMonthArrow={false}
133138
showSelectionPreview={true}
134139
moveRangeOnFirstSelection={false}
135140
className={'PreviewArea'}
@@ -141,6 +146,40 @@ export default class Main extends Component {
141146
key: 'selection',
142147
},
143148
]}
149+
direction="horizontal"
150+
/>
151+
</div>
152+
</Section>
153+
154+
<Section title="Date Range Picker - Vertical Infinite">
155+
<div>
156+
<input
157+
type="text"
158+
readOnly
159+
value={formatDateDisplay(this.state.dateRangePickerI.selection.startDate)}
160+
/>
161+
<input
162+
type="text"
163+
readOnly
164+
value={formatDateDisplay(this.state.dateRangePickerI.selection.endDate)}
165+
/>
166+
</div>
167+
<div>
168+
<DateRangePicker
169+
onChange={this.handleRangeChange.bind(this, 'dateRangePickerI')}
170+
className={'PreviewArea'}
171+
months={1}
172+
minDate={addDays(new Date(), -300)}
173+
maxDate={addDays(new Date(), 900)}
174+
direction="vertical"
175+
scroll={{ enabled: true }}
176+
ranges={[
177+
{
178+
startDate: this.state.dateRangePickerI.selection.startDate,
179+
endDate: this.state.dateRangePickerI.selection.endDate,
180+
key: 'selection',
181+
},
182+
]}
144183
/>
145184
</div>
146185
</Section>

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"dev": "NODE_ENV=development & webpack-dev-server --hot --inline",
8-
"prebuild": "rm -rf dist/* & rm -rf demo/dist/*",
8+
"clear": "rm -rf dist/* & rm -rf demo/dist/*",
99
"build": "NODE_ENV=production & yarn build-library & yarn build-demo",
1010
"build-demo": "webpack -p",
1111
"build-library": "babel ./src --out-dir ./dist --ignore test.js & postcss 'src/styles.scss' -d dist --ext css & postcss 'src/theme/*.scss' -d 'dist/theme' --ext css",
1212
"lint": "eslint 'src/**/*.js'",
13-
"test": "jest"
13+
"test": "jest",
14+
"preversion": "yarn clear & yarn build"
1415
},
1516
"keywords": [
1617
"react",
@@ -33,7 +34,8 @@
3334
},
3435
"dependencies": {
3536
"classnames": "^2.2.1",
36-
"prop-types": "^15.5.10"
37+
"prop-types": "^15.5.10",
38+
"react-list": "^0.8.8"
3739
},
3840
"peerDependencies": {
3941
"react": "^0.14 || ^15.0.0-rc || >=15.0"

0 commit comments

Comments
 (0)