DateTimePickerMonths.js
1.8 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
import React, { Component, PropTypes } from "react";
import cx from "classnames";
import s from "./DateTimePicker.scss";
import moment from "moment";
export default class DateTimePickerMonths extends Component {
static propTypes = {
subtractYear: PropTypes.func.isRequired,
addYear: PropTypes.func.isRequired,
viewDate: PropTypes.object.isRequired,
selectedDate: PropTypes.object.isRequired,
showYears: PropTypes.func.isRequired,
setViewMonth: PropTypes.func.isRequired
}
renderMonths = () => {
var classes, i, month, months, monthsShort;
month = this.props.selectedDate.month();
monthsShort = moment.monthsShort();
i = 0;
months = [];
while (i < 12) {
classes = {
month: true,
"active": i === month && this.props.viewDate.year() === this.props.selectedDate.year(),
[s.month]:true,
[s.active]:i === month && this.props.viewDate.year() === this.props.selectedDate.year(),
};
months.push(<span className={cx(classes)} key={i} onClick={this.props.setViewMonth}>{monthsShort[i]}</span>);
i++;
}
return months;
}
render() {
return (
<div className={cx('datepicker-months',s.datepicker_months)} style={{display: "block"}}>
<table className="table-condensed">
<thead>
<tr>
<th className="prev" onClick={this.props.subtractYear}>‹</th>
<th className="switch" colSpan="5" onClick={this.props.showYears}>{this.props.viewDate.year()}</th>
<th className="next" onClick={this.props.addYear}>›</th>
</tr>
</thead>
<tbody>
<tr>
<td colSpan="7">{this.renderMonths()}</td>
</tr>
</tbody>
</table>
</div>
);
}
}