Created
April 23, 2019 14:16
-
-
Save krazyjakee/8c87cae9bb33cb89fecb8e2f233657a9 to your computer and use it in GitHub Desktop.
A small wrapper around react-scrollbars-custom to give it autohiding scrollbars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import RSC from 'react-scrollbars-custom'; | |
export default ({ autoHide, children, ...props }) => { | |
const [inUse, setInUse] = useState(); | |
const style = { style: autoHide && { display: inUse ? null : 'none' }}; | |
return <RSC | |
trackXProps={style} | |
trackYProps={style} | |
onMouseEnter={autoHide && (() => setInUse(true))} | |
onMouseLeave={autoHide && (() => setInUse(false))} | |
{...props} | |
>{children}</RSC>; | |
}; | |
// <Scrollbar autoHide noScrollX>Content!</Scrollbar> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're a life saver.