Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add year picker variation * removed rollup watch * add tests * add tests
- Loading branch information
1 parent
c4bdd55
commit 5f046b5
Showing
13 changed files
with
2,120 additions
and
1,842 deletions.
There are no files selected for viewing
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,11 @@ | ||
() => { | ||
const [startDate, setStartDate] = useState(new Date()); | ||
return ( | ||
<DatePicker | ||
selected={startDate} | ||
onChange={date => setStartDate(date)} | ||
showYearPicker | ||
dateFormat="yyyy" | ||
/> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { getYear } from "./date_utils"; | ||
import * as utils from "./date_utils"; | ||
|
||
export default class Year extends React.Component { | ||
static propTypes = { | ||
date: PropTypes.string, | ||
onDayClick: PropTypes.func | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
handleYearClick = (day, event) => { | ||
if (this.props.onDayClick) { | ||
this.props.onDayClick(day, event); | ||
} | ||
}; | ||
|
||
onYearClick = (e, y) => { | ||
this.handleYearClick( | ||
utils.getStartOfYear(utils.setYear(this.props.date, y)), | ||
e | ||
); | ||
}; | ||
|
||
render() { | ||
const yearsToShow = 11; | ||
const yearsList = []; | ||
const { date } = this.props; | ||
for ( | ||
let y = getYear(date) - yearsToShow, i = 0; | ||
y <= getYear(date); | ||
y++, i++ | ||
) { | ||
yearsList.push( | ||
<div | ||
onClick={ev => { | ||
this.onYearClick(ev, y); | ||
}} | ||
className="react-datepicker__year-container-text" | ||
key={y} | ||
> | ||
{y} | ||
</div> | ||
); | ||
} | ||
return <div className="react-datepicker__year-container">{yearsList}</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
Oops, something went wrong.