react-toolbox/components/time_picker/ClockMinutes.jsx

62 lines
1.4 KiB
React
Raw Normal View History

import React from 'react';
2015-11-23 00:13:27 +03:00
import utils from '../utils/utils';
import style from './style.clock';
import Face from './ClockFace';
import Hand from './ClockHand';
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;
2015-10-22 02:31:17 +03:00
class Minutes extends React.Component {
static propTypes = {
center: React.PropTypes.object,
onChange: React.PropTypes.func,
radius: React.PropTypes.number,
2015-09-06 20:29:51 +03:00
selected: React.PropTypes.number,
spacing: React.PropTypes.number
};
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}
twoDigits
2015-10-11 22:17:12 +03:00
active={this.props.selected}
/>
2015-09-06 20:29:51 +03:00
<Hand ref='hand'
2015-10-11 22:17:12 +03:00
className={minutes.indexOf(this.props.selected) === -1 ? style.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}
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;