DateTimePickerDate.js
3.9 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React, { Component, PropTypes } from "react";
import DateTimePickerDays from "./DateTimePickerDays";
import DateTimePickerMonths from "./DateTimePickerMonths";
import DateTimePickerYears from "./DateTimePickerYears";
import cx from "classnames";
import s from "./DateTimePicker.scss";
export default class DateTimePickerDate extends Component {
static propTypes = {
subtractMonth: PropTypes.func.isRequired,
addMonth: PropTypes.func.isRequired,
viewDate: PropTypes.object.isRequired,
selectedDate: PropTypes.object.isRequired,
showToday: PropTypes.bool,
viewMode: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
daysOfWeekDisabled: PropTypes.array,
setSelectedDate: PropTypes.func.isRequired,
subtractYear: PropTypes.func.isRequired,
addYear: PropTypes.func.isRequired,
setViewMonth: PropTypes.func.isRequired,
setViewYear: PropTypes.func.isRequired,
addDecade: PropTypes.func.isRequired,
subtractDecade: PropTypes.func.isRequired,
minDate: PropTypes.object,
maxDate: PropTypes.object
}
constructor(props) {
super(props);
const viewModes = {
"days": {
daysDisplayed: true,
monthsDisplayed: false,
yearsDisplayed: false
},
"months": {
daysDisplayed: false,
monthsDisplayed: true,
yearsDisplayed: false
},
"years": {
daysDisplayed: false,
monthsDisplayed: false,
yearsDisplayed: true
}
};
this.state = viewModes[this.props.viewMode] || viewModes[Object.keys(viewModes)[this.props.viewMode]] || viewModes.days;
}
showMonths = () => {
return this.setState({
daysDisplayed: false,
monthsDisplayed: true
});
}
showYears = () => {
return this.setState({
monthsDisplayed: false,
yearsDisplayed: true
});
}
setViewYear = (e) => {
this.props.setViewYear(e.target.innerHTML);
return this.setState({
yearsDisplayed: false,
monthsDisplayed: true
});
}
setViewMonth = (e) => {
this.props.setViewMonth(e.target.innerHTML);
return this.setState({
monthsDisplayed: false,
daysDisplayed: true
});
}
renderDays = () => {
if(this.props.showMonthPicker)
return null;
if (this.state.daysDisplayed) {
return (
<DateTimePickerDays
addMonth={this.props.addMonth}
daysOfWeekDisabled={this.props.daysOfWeekDisabled}
maxDate={this.props.maxDate}
minDate={this.props.minDate}
selectedDate={this.props.selectedDate}
setSelectedDate={this.props.setSelectedDate}
showMonths={this.showMonths}
showToday={this.props.showToday}
subtractMonth={this.props.subtractMonth}
viewDate={this.props.viewDate}
/>
);
} else {
return null;
}
}
renderMonths = () => {
if ((this.props.showMonthPicker&&!this.state.yearsDisplayed)||this.state.monthsDisplayed) {
return (
<DateTimePickerMonths
addYear={this.props.addYear}
selectedDate={this.props.selectedDate}
setViewMonth={this.setViewMonth}
showYears={this.showYears}
subtractYear={this.props.subtractYear}
viewDate={this.props.viewDate}
/>
);
} else {
return null;
}
}
renderYears = () => {
if (this.state.yearsDisplayed) {
return (
<DateTimePickerYears
addDecade={this.props.addDecade}
selectedDate={this.props.selectedDate}
setViewYear={this.setViewYear}
subtractDecade={this.props.subtractDecade}
viewDate={this.props.viewDate}
/>
);
} else {
return null;
}
}
render() {
return (
<div className={cx("datepicker",s.datepicker)}>
{this.renderDays()}
{this.renderMonths()}
{this.renderYears()}
</div>
);
}
}