mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-15 00:21:28 +08:00

* feat: build overlay scrollbar component for Virtuoso elements * feat: apply overlay scroll to Virtuoso components * feat: build overlay scrollbar component for normal scrollable sections * feat: apply overlay scrollbar to normal scrollable sections * feat: add dark mode UI support to overlay scrollbars * chore: rename OverlayScrollbar to OverlayScrollbarForTypicalChildren * chore: move inline style to scss file * chore: rename VirtuosoOverlayScrollbar to OverlayScrollbarForVirtuosoChildren * chore: move OverlayScrollbarForTypicalChildren to components folder * chore: create a common component for handling Virtuoso and Typical scroll sections * chore: rename Virtuoso and Typical Overlay Scrollbar components * fix: fix the overlay scrollbar initialization flickering * fix: remove calculated height from typical overlay scrollbar + remove the explicit height: 100%
44 lines
893 B
TypeScript
44 lines
893 B
TypeScript
import { PartialOptions } from 'overlayscrollbars';
|
|
import { useOverlayScrollbars } from 'overlayscrollbars-react';
|
|
import {
|
|
Dispatch,
|
|
RefObject,
|
|
SetStateAction,
|
|
useEffect,
|
|
useRef,
|
|
useState,
|
|
} from 'react';
|
|
|
|
const useInitializeOverlayScrollbar = (
|
|
options: PartialOptions,
|
|
): {
|
|
setScroller: Dispatch<SetStateAction<null>>;
|
|
rootRef: RefObject<HTMLDivElement>;
|
|
} => {
|
|
const rootRef = useRef(null);
|
|
const [scroller, setScroller] = useState(null);
|
|
const [initialize, osInstance] = useOverlayScrollbars({
|
|
defer: true,
|
|
options,
|
|
});
|
|
|
|
useEffect(() => {
|
|
const { current: root } = rootRef;
|
|
|
|
if (scroller && root) {
|
|
initialize({
|
|
target: root,
|
|
elements: {
|
|
viewport: scroller,
|
|
},
|
|
});
|
|
}
|
|
|
|
return (): void => osInstance()?.destroy();
|
|
}, [scroller, initialize, osInstance]);
|
|
|
|
return { setScroller, rootRef };
|
|
};
|
|
|
|
export default useInitializeOverlayScrollbar;
|