feishin/src/renderer/hooks/use-hide-scrollbar.ts

26 lines
761 B
TypeScript
Raw Normal View History

2023-02-08 03:44:05 -08:00
import { useTimeout } from '@mantine/hooks';
import { useEffect, useState } from 'react';
2023-02-08 03:44:05 -08:00
export const useHideScrollbar = (timeout: number) => {
2023-07-01 19:10:05 -07:00
const [hideScrollbar, setHideScrollbar] = useState(false);
const { clear, start } = useTimeout(() => setHideScrollbar(true), timeout);
2023-02-08 03:44:05 -08:00
2023-07-01 19:10:05 -07:00
// Automatically hide the scrollbar after the timeout duration
useEffect(() => {
start();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
2023-02-08 03:44:05 -08:00
2023-07-01 19:10:05 -07:00
const hideScrollbarElementProps = {
onMouseEnter: () => {
setHideScrollbar(false);
clear();
},
onMouseLeave: () => {
start();
},
};
2023-02-08 03:44:05 -08:00
2023-07-01 19:10:05 -07:00
return { hideScrollbarElementProps, isScrollbarHidden: hideScrollbar };
2023-02-08 03:44:05 -08:00
};