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

Function Tooltip

packages/ui/src/components/tooltip.tsx:35–163  ·  view source on GitHub ↗
(props: TooltipProps)

Source from the content-addressed store, hash-verified

33}
34
35export function Tooltip(props: TooltipProps) {
36 let ref: HTMLDivElement | undefined
37 const [state, setState] = createStore({
38 open: false,
39 block: false,
40 expand: false,
41 })
42 const [local, others] = splitProps(props, [
43 "children",
44 "class",
45 "contentClass",
46 "contentStyle",
47 "inactive",
48 "forceOpen",
49 "ignoreSafeArea",
50 "value",
51 ])
52
53 const close = () => setState("open", false)
54
55 const inside = () => {
56 const active = document.activeElement
57 if (!ref || !active) return false
58 return ref.contains(active)
59 }
60
61 const drop = (expand = state.expand) => {
62 if (expand) return
63 if (ref?.matches(":hover")) return
64 if (inside()) return
65 setState("block", false)
66 }
67
68 const sync = () => {
69 const expand = !!ref?.querySelector('[aria-expanded="true"], [data-expanded]')
70 setState("expand", expand)
71 if (expand) {
72 setState("block", true)
73 close()
74 return
75 }
76 drop(expand)
77 }
78
79 const arm = () => {
80 setState("block", true)
81 close()
82 }
83
84 const leave = () => {
85 if (!inside()) close()
86 drop()
87 }
88
89 createEffect(() => {
90 if (!ref) return
91 sync()
92 const obs = new MutationObserver(sync)

Callers

nothing calls this directly

Calls 5

setStateFunction · 0.85
syncFunction · 0.70
armFunction · 0.70
dropFunction · 0.70
disconnectMethod · 0.45

Tested by

no test coverage detected