MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / createHover

Function createHover

packages/shared/src/primitives.ts:36–67  ·  view source on GitHub ↗
(handle: (hovering: boolean) => void)

Source from the content-addressed store, hash-verified

34export const useIsMobile = createSingletonRoot(() => createMediaQuery('(max-width: 640px)'))
35
36export function createHover(handle: (hovering: boolean) => void): {
37 onMouseEnter: VoidFunction
38 onMouseLeave: VoidFunction
39} {
40 let state = false
41 let mounted = true
42
43 const mql = window.matchMedia('(hover: none)')
44 let is_touch = mql.matches
45
46 makeEventListener(mql, 'change', e => {
47 if (is_touch = e.matches) {
48 handle(state = false)
49 }
50 })
51
52 onCleanup(() => {
53 mounted = false
54 if (state) handle(state = false)
55 })
56
57 const onChange = (new_state: boolean): void => {
58 if (!is_touch && mounted && state !== new_state) {
59 handle(state = new_state)
60 }
61 }
62
63 return {
64 onMouseEnter: () => onChange(true),
65 onMouseLeave: () => setTimeout(() => onChange(false)),
66 }
67}
68
69/**
70 * Reactive array reducer — if at least one consumer (boolean signal) is enabled — the returned result will the `true`.

Callers 4

OwnerPathFunction · 0.90
OwnerNodeFunction · 0.90
ValuePreviewFunction · 0.90
GraphNodeFunction · 0.90

Calls 2

onCleanupFunction · 0.85
onChangeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…