chenchenyuyu / chenchenyuyu.github.io

记录点点滴滴
http://cychenyu.com/
2 stars 0 forks source link

react Range component #121

Open chenchenyuyu opened 4 years ago

chenchenyuyu commented 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); }