UX: add helper for gps selector

This commit is contained in:
Pieter Vander Vennet 2025-06-07 04:46:43 +02:00
parent c215051ec5
commit 886b25c0b4
4 changed files with 108 additions and 6 deletions

View file

@ -0,0 +1,36 @@
export function dragDetection(htmlElement: HTMLElement, callback: () => {}) {
let isDown = false
let threshold = 5
let start = null
htmlElement.addEventListener("pointerdown", (e) => {
isDown = true
start = { x: e.clientX, y: e.clientY }
})
htmlElement.addEventListener("pointermove", (e) => {
if (!isDown || !start) return
const dx = e.clientX - start.x
const dy = e.clientY - start.y
if (Math.hypot(dx, dy) > threshold) {
callback()
isDown = false
}
})
htmlElement.addEventListener("pointerup", () => {
isDown = false
start = null
})
htmlElement.addEventListener("pointerleave", () => {
isDown = false
start = null
})
return {
destroy: () => {
},
}
}