mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-09 05:44:01 +00:00
26 lines
703 B
TypeScript
26 lines
703 B
TypeScript
|
|
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 };
|
||
|
|
};
|