Skip to content

Commit

Permalink
allow changing opacity/line weight with a drag touch
Browse files Browse the repository at this point in the history
It's tedious to have to type numbers for these on mobile, and the sliders themselves are a bit too large for the UI.
  • Loading branch information
hiddenist committed Dec 15, 2023
1 parent 10033f2 commit dd69002
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/web/src/components/EditableNumericLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ export function EditableNumericLabel(props: {
props.onChange(value)
}

let lastTouchY: number | null = null
const handleTouchMove = (e: TouchEvent) => {
e.preventDefault()
if (lastTouchY === null) {
lastTouchY = e.touches[0].clientY
return
}
if (e.touches[0].clientY > lastTouchY) {
props.onChange((value) => value - 1)
} else {
props.onChange((value) => value + 1)
}
lastTouchY = e.touches[0].clientY
}

const handleTouchEnd = () => {
lastTouchY = null
}

return (
<span
style={{ caretColor: "currentColor" }}
Expand All @@ -89,6 +108,8 @@ export function EditableNumericLabel(props: {
onWheel={handleScrollWheel}
onPaste={handlePaste}
onBlur={handleBlur}
onTouchEnd={handleTouchEnd}
onTouchMove={handleTouchMove}
>
{props.displayValue}
</span>
Expand Down

0 comments on commit dd69002

Please sign in to comment.