MCPcopy
hub / github.com/brimdata/zui / useScrollShadow

Function useScrollShadow

apps/zui/src/js/components/hooks/use-scroll-shadow.ts:5–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import useListener from "./useListener"
4
5export function useScrollShadow() {
6 const [ref, setRef] = useCallbackRef()
7
8 useEffect(() => {
9 ref?.classList.add("scroll-shadow")
10 return () => {
11 ref?.classList.remove("scroll-shadow")
12 }
13 }, [ref])
14
15 useListener(ref, "scroll", (e: UIEvent<HTMLElement>) => {
16 if (e.currentTarget.scrollTop === 0) {
17 e.currentTarget.classList.remove("scroll-shadow-show")
18 } else {
19 e.currentTarget.classList.add("scroll-shadow-show")
20 }
21 })
22
23 return setRef
24}

Callers

nothing calls this directly

Calls 4

useCallbackRefFunction · 0.85
useListenerFunction · 0.70
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected