DateTimePickerYears.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { Component, PropTypes } from "react";
import cx from "classnames";
import s from "./DateTimePicker.scss";
export default class DateTimePickerYears extends Component {
static propTypes = {
subtractDecade: PropTypes.func.isRequired,
addDecade: PropTypes.func.isRequired,
viewDate: PropTypes.object.isRequired,
selectedDate: PropTypes.object.isRequired,
setViewYear: PropTypes.func.isRequired
}
renderYears = () => {
var classes, i, year, years;
years = [];
year = parseInt(this.props.viewDate.year() / 10, 10) * 10;
year--;
i = -1;
while (i < 11) {
classes = {
year: true,
[s.year]:true,
old: i === -1 | i === 10,
active: this.props.selectedDate.year() === year,
[s.active]:this.props.selectedDate.year() === year
};
years.push(<span className={cx(classes)} key={year}onClick={this.props.setViewYear}>{year}</span>);
year++;
i++;
}
return years;
}
render() {
var year;
year = parseInt(this.props.viewDate.year() / 10, 10) * 10;
return (
<div className={cx('datepicker-years',s.datepicker_years)} style={{display: "block"}}>
<table className="table-condensed">
<thead>
<tr>
<th className="prev" onClick={this.props.subtractDecade}>‹</th>
<th className="switch" colSpan="5">{year} - {year + 9}</th>
<th className="next" onClick={this.props.addDecade}>›</th>
</tr>
</thead>
<tbody>
<tr>
<td colSpan="7">{this.renderYears()}</td>
</tr>
</tbody>
</table>
</div>
);
}
}