handlers.handleMouseMove = event => {
event.preventDefault()
event.stopPropagation()
const dy = event.clientY - y0
const top1 = Math.min(Math.max(0, top0 + dy), scrollTopMax)
scrollSections(top1)
}
handlers.handleMouseUp = event => {
event.preventDefault()
event.stopPropagation()
window.removeEventListener('mousemove', handlers.handleMouseMove, true)
window.removeEventListener('mouseup', handlers.handleMouseUp, true)
scrollerDispatch({
type: VSCROLL,
scrolling: false
})
}
window.addEventListener('mousemove', handlers.handleMouseMove, true)
window.addEventListener('mouseup', handlers.handleMouseUp, true)
},
[scrollerDispatch, scrollTop, scrollTopMax, scrollSections]
)
useEffect(() => {
if (wheeling) {
const left = Math.min(Math.max(0, scrollTop + deltaY), scrollTopMax)
scrollSections(left)
}
}, [scrollTop, scrollTopMax, deltaY, wheeling, scrollSections])
return visible ? (
<div className='rrt-vscroller'>
<div
className='rrt-vscroller-bar'
style={{ height: `${bodyHeight}px`, marginTop: `${barTop}px` }}
onMouseDown={handleMouseDown}
>
<div
className={`rrt-vscroller-thumb${
scrolling ? ' rrt-vscroller-thumb-active' : ''
}`}
style={{
height: `${thumbHeight}px`,
top: `${marginTop}px`
}}
/>
</div>
</div>
) : null
}
VScroller.propTypes = {
state: ScrollerStateType
}
VScroller.displayName = 'VScroller'
export default VScroller
Copyright 2020 Ulrich Gaal
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.