feat(SW-441): Added table block component

This commit is contained in:
Erik Tiekstra
2024-10-04 11:51:39 +02:00
parent 4979c22c4a
commit 5e4ef02ebf
23 changed files with 431 additions and 29 deletions

36
hooks/useScrollShadows.ts Normal file
View File

@@ -0,0 +1,36 @@
import { useEffect, useRef, useState } from "react"
const useScrollShadows = () => {
const containerRef = useRef<HTMLDivElement | null>(null)
const [showLeftShadow, setShowLeftShadow] = useState<boolean>(false)
const [showRightShadow, setShowRightShadow] = useState<boolean>(false)
useEffect(() => {
const handleScroll = () => {
const container = containerRef.current
if (!container) return
setShowLeftShadow(container.scrollLeft > 0)
setShowRightShadow(
container.scrollLeft < container.scrollWidth - container.clientWidth
)
}
const container = containerRef.current
if (container) {
container.addEventListener("scroll", handleScroll)
}
handleScroll()
return () => {
if (container) {
container.removeEventListener("scroll", handleScroll)
}
}
}, [])
return { containerRef, showLeftShadow, showRightShadow }
}
export default useScrollShadows