This repository was archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathDateTimePickerTime.js
120 lines (96 loc) · 3.4 KB
/
DateTimePickerTime.js
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
import React, { Component, PropTypes } from "react";
import { Glyphicon } from "react-bootstrap";
import DateTimePickerMinutes from "./DateTimePickerMinutes";
import DateTimePickerHours from "./DateTimePickerHours";
import Constants from "./Constants.js";
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="timepicker-picker">
<table className="table-condensed">
<tbody>
<tr>
<td><a tabIndex="-1" className="btn" onClick={this.props.addHour}><Glyphicon glyph="chevron-up" /></a></td>
<td className="separator" onKeyUp={this.onKeyUp}></td>
<td><a tabIndex="-1" className="btn" onClick={this.props.addMinute}><Glyphicon glyph="chevron-up" /></a></td>
<td className="separator"></td>
</tr>
<tr>
<td><span className="timepicker-hour" onClick={this.showHours}>{this.props.selectedDate.format("h")}</span></td>
<td className="separator">:</td>
<td><span className="timepicker-minute" onClick={this.showMinutes}>{this.props.selectedDate.format("mm")}</span></td>
<td className="separator"></td>
<td><button tabIndex="-1" className="btn btn-primary" onClick={this.props.togglePeriod} type="button">{this.props.selectedDate.format("A")}</button></td>
</tr>
<tr>
<td><a tabIndex="-1" className="btn" onClick={this.props.subtractHour}><Glyphicon glyph="chevron-down" /></a></td>
<td className="separator"></td>
<td><a tabIndex="-1" className="btn" onClick={this.props.subtractMinute}><Glyphicon glyph="chevron-down" /></a></td>
<td className="separator"></td>
</tr>
</tbody>
</table>
</div>
);
} else {
return "";
}
}
render() {
return (
<div className="timepicker">
{this.renderPicker()}
{this.renderHours()}
{this.renderMinutes()}
</div>
);
}
}
module.exports = DateTimePickerTime;