MCPcopy Create free account
hub / github.com/anomalyco/opencode / ScrollView

Function ScrollView

packages/ui/src/components/scroll-view.tsx:45–250  ·  view source on GitHub ↗
(props: ScrollViewProps)

Source from the content-addressed store, hash-verified

43}
44
45export function ScrollView(props: ScrollViewProps) {
46 const i18n = useI18n()
47 const merged = mergeProps({ orientation: "vertical" }, props)
48 const [local, events, rest] = splitProps(
49 merged,
50 ["class", "children", "viewportRef", "orientation", "style"],
51 [
52 "onScroll",
53 "onWheel",
54 "onTouchStart",
55 "onTouchMove",
56 "onTouchEnd",
57 "onTouchCancel",
58 "onPointerDown",
59 "onClick",
60 "onKeyDown",
61 ],
62 )
63
64 let rootRef!: HTMLDivElement
65 let viewportRef!: HTMLDivElement
66 let thumbRef!: HTMLDivElement
67
68 const [state, setState] = createStore({
69 isHovered: false,
70 isDragging: false,
71 thumbHeight: 0,
72 thumbTop: 0,
73 showThumb: false,
74 })
75 const isHovered = () => state.isHovered
76 const isDragging = () => state.isDragging
77 const thumbHeight = () => state.thumbHeight
78 const thumbTop = () => state.thumbTop
79 const showThumb = () => state.showThumb
80
81 const updateThumb = () => {
82 if (!viewportRef) return
83 const { scrollTop, scrollHeight, clientHeight } = viewportRef
84
85 if (scrollHeight <= clientHeight || scrollHeight === 0) {
86 setState("showThumb", false)
87 return
88 }
89
90 setState("showThumb", true)
91 const trackPadding = 8
92 const trackHeight = clientHeight - trackPadding * 2
93
94 const minThumbHeight = 32
95 // Calculate raw thumb height based on ratio
96 let height = (clientHeight / scrollHeight) * trackHeight
97 height = Math.max(height, minThumbHeight)
98
99 const maxScrollTop = scrollHeight - clientHeight
100 const maxThumbTop = trackHeight - height
101
102 const top = maxScrollTop > 0 ? (scrollTop / maxScrollTop) * maxThumbTop : 0

Callers

nothing calls this directly

Calls 9

useI18nFunction · 0.90
updateThumbFunction · 0.85
setStateFunction · 0.85
showThumbFunction · 0.85
isHoveredFunction · 0.85
isDraggingFunction · 0.85
thumbHeightFunction · 0.85
thumbTopFunction · 0.85
onKeyDownFunction · 0.70

Tested by

no test coverage detected