react-toolbox/components/time_picker/ClockMinutes.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-05-31 11:23:05 +03:00
import React, { Component, PropTypes } from 'react';
import utils from '../utils/utils.js';
import Hand from './ClockHand.js';
import Face from './ClockFace.js';
2015-09-06 20:29:51 +03:00
const minutes = utils.range(0, 60, 5);
2015-09-06 20:29:51 +03:00
const step = 360 / 60;
2016-05-31 11:23:05 +03:00
class Minutes extends Component {
static propTypes = {
2016-05-31 11:23:05 +03:00
center: PropTypes.object,
onChange: PropTypes.func,
radius: PropTypes.number,
selected: PropTypes.number,
spacing: PropTypes.number,
theme: PropTypes.shape({
small: PropTypes.string
2016-05-22 14:25:56 +03:00
})
};
2015-09-06 20:29:51 +03:00
static defaultProps = {
selected: 0,
onChange: null
};
2015-09-06 20:29:51 +03:00
2015-10-22 02:31:17 +03:00
handleHandMove = (degrees) => {
2015-09-06 20:29:51 +03:00
this.props.onChange(degrees / step);
2015-10-22 02:31:17 +03:00
};
2015-09-06 20:29:51 +03:00
2015-10-22 02:31:17 +03:00
handleMouseDown = (event) => {
2015-09-06 20:29:51 +03:00
this.refs.hand.mouseStart(event);
2015-10-22 02:31:17 +03:00
};
2015-09-06 20:29:51 +03:00
2015-10-22 02:31:17 +03:00
handleTouchStart = (event) => {
2015-09-06 20:29:51 +03:00
this.refs.hand.touchStart(event);
2015-10-22 02:31:17 +03:00
};
2015-09-06 20:29:51 +03:00
render () {
return (
<div>
<Face
2015-10-22 02:31:17 +03:00
onTouchStart={this.handleTouchStart}
onMouseDown={this.handleMouseDown}
2015-09-06 20:29:51 +03:00
numbers={minutes}
spacing={this.props.spacing}
radius={this.props.radius}
2015-10-11 22:17:12 +03:00
active={this.props.selected}
2016-05-22 14:25:56 +03:00
theme={this.props.theme}
twoDigits
2015-10-11 22:17:12 +03:00
/>
2015-09-06 20:29:51 +03:00
<Hand ref='hand'
2016-05-22 14:25:56 +03:00
className={minutes.indexOf(this.props.selected) === -1 ? this.props.theme.small : ''}
2015-09-08 12:03:01 +03:00
angle={this.props.selected * step}
2015-09-06 20:29:51 +03:00
length={this.props.radius - this.props.spacing}
2015-10-22 02:31:17 +03:00
onMove={this.handleHandMove}
2015-09-06 20:29:51 +03:00
origin={this.props.center}
2016-05-22 14:25:56 +03:00
theme={this.props.theme}
2015-10-11 22:17:12 +03:00
step={step}
/>
2015-09-06 20:29:51 +03:00
</div>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
export default Minutes;