Add customizable scrollbar offset on scrollarea

This commit is contained in:
jeffvli 2023-01-08 20:46:20 -08:00
parent c51194cd03
commit d58ba92cbd

View file

@ -26,16 +26,16 @@ const StyledScrollArea = styled(MantineScrollArea)`
} }
`; `;
const StyledNativeScrollArea = styled.div` const StyledNativeScrollArea = styled.div<{ scrollBarOffset?: string }>`
height: 100%; height: 100%;
overflow-y: overlay; overflow-y: overlay !important;
&::-webkit-scrollbar-track { &::-webkit-scrollbar-track {
margin-top: 35px; margin-top: ${(props) => props.scrollBarOffset || '35px'};
} }
&::-webkit-scrollbar-thumb { &::-webkit-scrollbar-thumb {
margin-top: 35px; margin-top: ${(props) => props.scrollBarOffset || '35px'};
} }
`; `;
@ -55,11 +55,18 @@ interface NativeScrollAreaProps {
children: React.ReactNode; children: React.ReactNode;
debugScrollPosition?: boolean; debugScrollPosition?: boolean;
pageHeaderProps?: PageHeaderProps & { offset?: any; target?: any }; pageHeaderProps?: PageHeaderProps & { offset?: any; target?: any };
scrollBarOffset?: string;
} }
export const NativeScrollArea = forwardRef( export const NativeScrollArea = forwardRef(
( (
{ children, pageHeaderProps, debugScrollPosition, ...props }: NativeScrollAreaProps, {
children,
pageHeaderProps,
debugScrollPosition,
scrollBarOffset,
...props
}: NativeScrollAreaProps,
ref: Ref<HTMLDivElement>, ref: Ref<HTMLDivElement>,
) => { ) => {
const [hideScrollbar, setHideScrollbar] = useState(false); const [hideScrollbar, setHideScrollbar] = useState(false);
@ -112,6 +119,7 @@ export const NativeScrollArea = forwardRef(
<StyledNativeScrollArea <StyledNativeScrollArea
ref={mergedRef} ref={mergedRef}
className={hideScrollbar ? 'hide-scrollbar' : undefined} className={hideScrollbar ? 'hide-scrollbar' : undefined}
scrollBarOffset={scrollBarOffset}
onMouseEnter={() => { onMouseEnter={() => {
setHideScrollbar(false); setHideScrollbar(false);
clear(); clear();