forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Range month year picker (Hacker0x01#1692)
* add range month picker * fix issue Hacker0x01#1685 * fix for failing time input on backspace * Add tests
- Loading branch information
1 parent
07845e4
commit 373ae02
Showing
11 changed files
with
19,697 additions
and
746 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from "react"; | ||
import DatePicker from "react-datepicker"; | ||
import isAfter from "date-fns/isAfter"; | ||
|
||
export default class RangeMonthPicker extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
startDate: new Date("2014/02/08"), | ||
endDate: new Date("2014/04/08") | ||
}; | ||
} | ||
|
||
handleChange = ({ startDate, endDate }) => { | ||
startDate = startDate || this.state.startDate; | ||
endDate = endDate || this.state.endDate; | ||
|
||
if (isAfter(startDate, endDate)) { | ||
endDate = startDate; | ||
} | ||
|
||
this.setState({ startDate, endDate }); | ||
}; | ||
|
||
handleChangeStart = startDate => this.handleChange({ startDate }); | ||
|
||
handleChangeEnd = endDate => this.handleChange({ endDate }); | ||
|
||
render() { | ||
return ( | ||
<div className="row"> | ||
<pre className="column example__code"> | ||
<code className="jsx"> | ||
{` | ||
<DatePicker | ||
selected={this.state.startDate} | ||
selectsStart | ||
startDate={this.state.startDate} | ||
endDate={this.state.endDate} | ||
dateFormat="MM/yyyy" | ||
showMonthYearPicker | ||
onChange={this.handleChangeStart} | ||
/> | ||
<DatePicker | ||
selected={this.state.endDate} | ||
selectsEnd | ||
startDate={this.state.startDate} | ||
endDate={this.state.endDate} | ||
dateFormat="MM/yyyy" | ||
showMonthYearPicker | ||
onChange={this.handleChangeEnd} | ||
/> | ||
`} | ||
</code> | ||
</pre> | ||
<div className="column"> | ||
<DatePicker | ||
selected={this.state.startDate} | ||
selectsStart | ||
startDate={this.state.startDate} | ||
endDate={this.state.endDate} | ||
dateFormat="MM/yyyy" | ||
showMonthYearPicker | ||
onChange={this.handleChangeStart} | ||
/> | ||
<DatePicker | ||
selected={this.state.endDate} | ||
selectsEnd | ||
startDate={this.state.startDate} | ||
endDate={this.state.endDate} | ||
dateFormat="MM/yyyy" | ||
showMonthYearPicker | ||
onChange={this.handleChangeEnd} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.