Skip to content

Commit

Permalink
Merge branch 'main' into feat/new-colours
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Dec 12, 2022
2 parents 8f7854f + c72b360 commit 5b48242
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions components/src/components/atoms/ScrollBox/ScrollBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ const IntersectElement = styled.div(
)

type Props = {
hideDividers?: boolean | { top?: boolean; bottom?: boolean }
topTriggerPx?: number
bottomTriggerPx?: number
onReachedTop?: () => void
onReachedBottom?: () => void
} & React.HTMLAttributes<HTMLDivElement>

export const ScrollBox = ({
hideDividers = false,
topTriggerPx = 16,
bottomTriggerPx = 16,
onReachedTop,
Expand All @@ -90,6 +92,11 @@ export const ScrollBox = ({
const topRef = React.useRef<HTMLDivElement>(null)
const bottomRef = React.useRef<HTMLDivElement>(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
Expand All @@ -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?.()
}
Expand All @@ -133,6 +142,7 @@ export const ScrollBox = ({
return () => {
observer.disconnect()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bottomTriggerPx, topTriggerPx])

React.useEffect(() => {
Expand Down
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b48242

Please sign in to comment.