From 3a6675081d9dddf3a6eba940d219b32de67109f2 Mon Sep 17 00:00:00 2001 From: oyeAnuj Date: Thu, 9 Mar 2017 18:23:51 -0800 Subject: [PATCH 1/2] First pass at adding hover label - adds the event listener, - calculates position and value - adds node for Label --- example/js/example-app.jsx | 1 + src/js/input-range/input-range.jsx | 148 ++++++++++++++++++++++++++++- src/js/input-range/slider.jsx | 2 + src/js/input-range/track.jsx | 64 +++++++++++++ 4 files changed, 213 insertions(+), 2 deletions(-) diff --git a/example/js/example-app.jsx b/example/js/example-app.jsx index 28621ae..49101d8 100644 --- a/example/js/example-app.jsx +++ b/example/js/example-app.jsx @@ -22,6 +22,7 @@ export default class ExampleApp extends React.Component { return (
this.updatePosition(key, position)); } + /** + * Handle any non-drag "mousemove" event received by the slider + * @private + * @param {SyntheticEvent} event + * @param {string} key + * @return {void} + */ + @autobind + handleMouseMove(event) { + if (this.props.disabled) { + return; + } + + const position = valueTransformer.getPositionFromEvent(event, this.getTrackClientRect()); + + const value = valueTransformer.getValueFromPosition(position, this.props.minValue, this.props.maxValue, this.getTrackClientRect()); + + console.log('MouseMove Position: ', position); + console.log('MouseMove Values: ', value); + + // TODO: Add CSS to label and remove console.log + + this.setState({ + hoverValue: value, + }); + } + + /** + * Handle any "mouseover" event received by the slider + * @private + * @param {SyntheticEvent} event + * @param {string} key + * @return {void} + */ + @autobind + handleMouseOver(event) { + if (this.props.disabled) { + return; + } + + const position = valueTransformer.getPositionFromEvent(event, this.getTrackClientRect()); + + const value = valueTransformer.getValueFromPosition(position, this.props.minValue, this.props.maxValue, this.getTrackClientRect()); + + console.log('MouseOver Position: ', position); + console.log('MouseOver Value: ', value); + + // TODO: Add CSS to hoverLabel and remove console.log + + this.setState({ + hovering: true, + hoverValue: value, + }); + } + + + /** + * Handle any "mouseout" event received by the slider + * @private + * @param {SyntheticEvent} event + * @param {string} key + * @return {void} + */ + @autobind + handleMouseOut(event) { + if (this.props.disabled) { + return; + } + + const position = valueTransformer.getPositionFromEvent(event, this.getTrackClientRect()); + const value = valueTransformer.getValueFromPosition(position, this.props.minValue, this.props.maxValue, this.getTrackClientRect()); + + console.log('MouseOut Position: ', position); + console.log('MouseOut Value: ', value); + + // TODO: Remove CSS from hoverLabel and remove console.log + + this.setState({ + hovering: false, + hoverValue: value, + }); + } + + /** * Handle any "keydown" event received by the slider * @private @@ -535,6 +662,9 @@ export default class InputRange extends React.Component { minValue={minValue} onSliderDrag={this.handleSliderDrag} onSliderKeyDown={this.handleSliderKeyDown} + onMouseOver={this.handleMouseOver} + onMouseOut={this.handleMouseOut} + onMouseMove={this.handleMouseMove} percentage={percentage} type={key} value={value} /> @@ -597,9 +727,23 @@ export default class InputRange extends React.Component { classNames={this.props.classNames} ref={(trackNode) => { this.trackNode = trackNode; }} percentages={percentages} - onTrackMouseDown={this.handleTrackMouseDown}> + onTrackMouseDown={this.handleTrackMouseDown} + onTrackMouseOver={this.handleMouseOver} + onTrackMouseOut={this.handleMouseOut} + onTrackMouseMove={this.handleMouseMove} > {this.renderSliders()} + { + this.props.showHoverLabel && this.state.hovering && + + + }