diff --git a/components/src/components/atoms/ScrollBox/ScrollBox.tsx b/components/src/components/atoms/ScrollBox/ScrollBox.tsx index b52f9737..a1494885 100644 --- a/components/src/components/atoms/ScrollBox/ScrollBox.tsx +++ b/components/src/components/atoms/ScrollBox/ScrollBox.tsx @@ -72,6 +72,7 @@ const IntersectElement = styled.div( ) type Props = { + hideDividers?: boolean | { top?: boolean; bottom?: boolean } topTriggerPx?: number bottomTriggerPx?: number onReachedTop?: () => void @@ -79,6 +80,7 @@ type Props = { } & React.HTMLAttributes export const ScrollBox = ({ + hideDividers = false, topTriggerPx = 16, bottomTriggerPx = 16, onReachedTop, @@ -90,6 +92,11 @@ export const ScrollBox = ({ const topRef = React.useRef(null) const bottomRef = React.useRef(null) + const hideTop = + typeof hideDividers === 'boolean' ? hideDividers : !!hideDividers?.top + const hideBottom = + typeof hideDividers === 'boolean' ? hideDividers : !!hideDividers?.bottom + const funcRef = React.useRef<{ onReachedTop?: () => void onReachedBottom?: () => void @@ -110,8 +117,10 @@ export const ScrollBox = ({ iref[1] = entry.time } } - intersectingTop[1] !== -1 && setShowTop(!intersectingTop[0]) - intersectingBottom[1] !== -1 && setShowBottom(!intersectingBottom[0]) + intersectingTop[1] !== -1 && !hideTop && setShowTop(!intersectingTop[0]) + intersectingBottom[1] !== -1 && + !hideBottom && + setShowBottom(!intersectingBottom[0]) intersectingTop[0] && funcRef.current.onReachedTop?.() intersectingBottom[0] && funcRef.current.onReachedBottom?.() } @@ -133,6 +142,7 @@ export const ScrollBox = ({ return () => { observer.disconnect() } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [bottomTriggerPx, topTriggerPx]) React.useEffect(() => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ae3372ec..34005152 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5939,6 +5939,10 @@ packages: /caniuse-lite/1.0.30001436: resolution: {integrity: sha512-ZmWkKsnC2ifEPoWUvSAIGyOYwT+keAaaWPHiQ9DfMqS1t6tfuyFYoWR78TeZtznkEQ64+vGXH9cZrElwR2Mrxg==} + /caniuse-lite/1.0.30001439: + resolution: {integrity: sha512-1MgUzEkoMO6gKfXflStpYgZDlFM7M/ck/bgfVCACO5vnAf0fXoNVHdWtqGU+MYca+4bL9Z5bpOVmR33cWW9G2A==} + dev: false + /capital-case/1.0.4: resolution: {integrity: sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==} dependencies: @@ -10394,7 +10398,7 @@ packages: dependencies: '@next/env': 12.3.0 '@swc/helpers': 0.4.11 - caniuse-lite: 1.0.30001436 + caniuse-lite: 1.0.30001439 postcss: 8.4.14 react: 17.0.2 react-dom: 17.0.2_react@17.0.2