Add hook for hideable scrollbar
This commit is contained in:
parent
8b5e463546
commit
147b155d60
3 changed files with 30 additions and 0 deletions
|
@ -3,3 +3,4 @@ export * from './use-is-mounted';
|
||||||
export * from './use-should-pad-titlebar';
|
export * from './use-should-pad-titlebar';
|
||||||
export * from './use-container-query';
|
export * from './use-container-query';
|
||||||
export * from './use-fast-average-color';
|
export * from './use-fast-average-color';
|
||||||
|
export * from './use-hide-scrollbar';
|
||||||
|
|
25
src/renderer/hooks/use-hide-scrollbar.ts
Normal file
25
src/renderer/hooks/use-hide-scrollbar.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useTimeout } from '@mantine/hooks';
|
||||||
|
|
||||||
|
export const useHideScrollbar = (timeout: number) => {
|
||||||
|
const [hideScrollbar, setHideScrollbar] = useState(false);
|
||||||
|
const { start, clear } = useTimeout(() => setHideScrollbar(true), timeout);
|
||||||
|
|
||||||
|
// Automatically hide the scrollbar after the timeout duration
|
||||||
|
useEffect(() => {
|
||||||
|
start();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const hideScrollbarElementProps = {
|
||||||
|
onMouseEnter: () => {
|
||||||
|
setHideScrollbar(false);
|
||||||
|
clear();
|
||||||
|
},
|
||||||
|
onMouseLeave: () => {
|
||||||
|
start();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return { hideScrollbarElementProps, isScrollbarHidden: hideScrollbar };
|
||||||
|
};
|
|
@ -75,6 +75,10 @@ button {
|
||||||
-webkit-app-region: no-drag;
|
-webkit-app-region: no-drag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.overlay-scrollbar {
|
||||||
|
overflow-y: overlay !important;
|
||||||
|
}
|
||||||
|
|
||||||
.hide-scrollbar {
|
.hide-scrollbar {
|
||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
scrollbar-color: transparent transparent;
|
scrollbar-color: transparent transparent;
|
||||||
|
|
Reference in a new issue