Open chenchenyuyu opened 4 years ago
onMove = (clientX: number, clientY: number) => { const { draggedThumbIndex } = this.state; const { direction, min, max, onChange, values, step, rtl } = this.props; if (draggedThumbIndex === -1) return null; const trackElement = this.trackRef.current!; const trackRect = trackElement.getBoundingClientRect(); const trackLength = isVertical(direction) ? trackRect.height : trackRect.width; let newValue = 0; switch (direction) { case Direction.Right: newValue = ((clientX - trackRect.left) / trackLength) (max - min) + min; break; case Direction.Left: newValue = ((trackLength - (clientX - trackRect.left)) / trackLength) (max - min) + min; break; case Direction.Down: newValue = ((clientY - trackRect.top) / trackLength) (max - min) + min; break; case Direction.Up: newValue = ((trackLength - (clientY - trackRect.top)) / trackLength) (max - min) + min; break; default: assertUnreachable(direction); }
onMove = (clientX: number, clientY: number) => { const { draggedThumbIndex } = this.state; const { direction, min, max, onChange, values, step, rtl } = this.props; if (draggedThumbIndex === -1) return null; const trackElement = this.trackRef.current!; const trackRect = trackElement.getBoundingClientRect(); const trackLength = isVertical(direction) ? trackRect.height : trackRect.width; let newValue = 0; switch (direction) { case Direction.Right: newValue = ((clientX - trackRect.left) / trackLength) (max - min) + min; break; case Direction.Left: newValue = ((trackLength - (clientX - trackRect.left)) / trackLength) (max - min) + min; break; case Direction.Down: newValue = ((clientY - trackRect.top) / trackLength) (max - min) + min; break; case Direction.Up: newValue = ((trackLength - (clientY - trackRect.top)) / trackLength) (max - min) + min; break; default: assertUnreachable(direction); }