Skip to content

Commit 3bf154e

Browse files
davidfurlongsimeg
authored andcommitted
Add AM/PM Arrows to toggle between states (arqex#124)
Add option to switch between AM and PM
1 parent cc4a965 commit 3bf154e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

css/react-datetime.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,4 @@ td.rdtYear:hover {
210210
width: 100%;
211211
font-size: 1.2em;
212212
margin-top: 37px;
213-
}
214-
215-
.rdtDayPart {
216-
margin-top: 43px;
217-
}
213+
}

src/TimeView.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ var DateTimePickerTime = React.createClass({
5757
}
5858
return '';
5959
},
60+
renderDayPart: function() {
61+
return DOM.div({ className: 'rdtCounter'}, [
62+
DOM.span({ key:'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'toggleDayPart', 'hours') }, '▲' ),
63+
DOM.div({ key: this.state.daypart, className: 'rdtCount'}, this.state.daypart ),
64+
DOM.span({ key:'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'toggleDayPart', 'hours') }, '▼' )
65+
]);
66+
},
6067
render: function() {
6168
var me = this,
6269
counters = []
@@ -69,7 +76,7 @@ var DateTimePickerTime = React.createClass({
6976
});
7077

7178
if (this.state.daypart !== false) {
72-
counters.push(DOM.div({ key: this.state.daypart, className: 'rdtDayPart'}, this.state.daypart ));
79+
counters.push( me.renderDayPart() );
7380
}
7481

7582
if ( this.state.counters.length === 3 && this.props.timeFormat.indexOf('S') !== -1 ){
@@ -168,6 +175,12 @@ var DateTimePickerTime = React.createClass({
168175
seconds: 2,
169176
milliseconds: 3
170177
},
178+
toggleDayPart: function( type ){ // type is always 'hours'
179+
var value = parseInt(this.state[ type ], 10) + 12;
180+
if ( value > this.timeConstraints[ type ].max )
181+
value = this.timeConstraints[ type ].min + (value - (this.timeConstraints[ type ].max + 1));
182+
return this.pad( type, value );
183+
},
171184
increase: function( type ){
172185
var value = parseInt(this.state[ type ], 10) + this.timeConstraints[ type ].step;
173186
if ( value > this.timeConstraints[ type ].max )

0 commit comments

Comments
 (0)