diff --git a/src/common/Slider/Slider.js b/src/common/Slider/Slider.js index ae80f66da..cf4553a95 100644 --- a/src/common/Slider/Slider.js +++ b/src/common/Slider/Slider.js @@ -8,40 +8,18 @@ class Slider extends Component { super(props); this.orientation = props.orientation; - this.state = { - active: false - }; + this.onSlide = props.onSlide; + this.onComplete = props.onComplete; + this.onCancel = props.onCancel; } shouldComponentUpdate(nextProps, nextState) { - return nextState.active !== this.state.active || - nextProps.value !== this.props.value || + return nextProps.value !== this.props.value || nextProps.minimumValue !== this.props.minimumValue || nextProps.maximumValue !== this.props.maximumValue || nextProps.className !== this.props.className; } - onSlide = (...args) => { - this.setState({ active: true }); - if (typeof this.props.onSlide === 'function') { - this.props.onSlide(...args); - } - } - - onComplete = (...args) => { - this.setState({ active: false }); - if (typeof this.props.onComplete === 'function') { - this.props.onComplete(...args); - } - } - - onCancel = (...args) => { - this.setState({ active: false }); - if (typeof this.props.onCancel === 'function') { - this.props.onCancel(...args); - } - } - calculateSlidingValue = ({ mouseX, mouseY, sliderElement }) => { const { x: sliderX, y: sliderY, width: sliderWidth, height: sliderHeight } = sliderElement.getBoundingClientRect(); const sliderStart = this.orientation === 'horizontal' ? sliderX : sliderY; @@ -50,7 +28,7 @@ class Slider extends Component { const thumbStart = Math.min(Math.max(mouseStart - sliderStart, 0), sliderLength); const slidingValueCoef = this.orientation === 'horizontal' ? thumbStart / sliderLength : (sliderLength - thumbStart) / sliderLength; const slidingValue = slidingValueCoef * (this.props.maximumValue - this.props.minimumValue) + this.props.minimumValue; - return Math.floor(slidingValue); + return slidingValue; } onStartSliding = ({ currentTarget: sliderElement, clientX: mouseX, clientY: mouseY, button }) => { @@ -91,7 +69,7 @@ class Slider extends Component { const thumbStartProp = this.orientation === 'horizontal' ? 'left' : 'bottom'; const thumbStart = Math.min((this.props.value - this.props.minimumValue) / (this.props.maximumValue - this.props.minimumValue), 1); return ( -