DateTimePickerTime.js
3.2 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
import React, { Component, PropTypes } from "react";
import DateTimePickerMinutes from "./DateTimePickerMinutes";
import DateTimePickerHours from "./DateTimePickerHours";
import Constants from "./Constants.js";
import cx from "classnames";
import s from "./DateTimePicker.scss";
export default class DateTimePickerTime extends Component {
static propTypes = {
setSelectedHour: PropTypes.func.isRequired,
setSelectedMinute: PropTypes.func.isRequired,
subtractHour: PropTypes.func.isRequired,
addHour: PropTypes.func.isRequired,
subtractMinute: PropTypes.func.isRequired,
addMinute: PropTypes.func.isRequired,
viewDate: PropTypes.object.isRequired,
selectedDate: PropTypes.object.isRequired,
togglePeriod: PropTypes.func.isRequired,
mode: PropTypes.oneOf([Constants.MODE_DATE, Constants.MODE_DATETIME, Constants.MODE_TIME])
}
state = {
minutesDisplayed: false,
hoursDisplayed: false
}
goBack = () => {
return this.setState({
minutesDisplayed: false,
hoursDisplayed: false
});
}
showMinutes = () => {
return this.setState({
minutesDisplayed: true
});
}
showHours = () => {
return this.setState({
hoursDisplayed: true
});
}
renderMinutes = () => {
if (this.state.minutesDisplayed) {
return <DateTimePickerMinutes {...this.props} onSwitch={this.goBack} />;
} else {
return null;
}
}
renderHours = () => {
if (this.state.hoursDisplayed) {
return <DateTimePickerHours {...this.props} onSwitch={this.goBack} />;
} else {
return null;
}
}
renderPicker = () => {
if (!this.state.minutesDisplayed && !this.state.hoursDisplayed) {
return (
<div className={cx(s.timepicker)}>
<table className="table-condensed">
<tbody>
<tr>
<td><a className="btn" onClick={this.props.addHour}><span className={cx(s.arrow_up)} /></a></td>
<td className="separator"></td>
<td><a className="btn" onClick={this.props.addMinute}><span className={cx(s.arrow_up)} /></a></td>
<td className="separator"></td>
</tr>
<tr>
<td><span className={cx(s.timepicker_hour,'timepicker-hour')} onClick={this.showHours}>{this.props.selectedDate.format("HH")}</span></td>
<td className="separator">:</td>
<td><span className={cx(s.timepicker_minute,'timepicker-minute')} onClick={this.showMinutes}>{this.props.selectedDate.format("mm")}</span></td>
<td className="separator"></td>
</tr>
<tr>
<td><a className="btn" onClick={this.props.subtractHour}><span className={cx(s.arrow_down)} /></a></td>
<td className="separator"></td>
<td><a className="btn" onClick={this.props.subtractMinute}><span className={cx(s.arrow_down)} /></a></td>
<td className="separator"></td>
</tr>
</tbody>
</table>
</div>
);
} else {
return "";
}
}
render() {
return (
<div className={cx("timepicker",s.timepicker)}>
{this.renderPicker()}
{this.renderHours()}
{this.renderMinutes()}
</div>
);
}
}