diff --git a/app/components/InputAddon.vue b/app/components/InputAddon.vue index 1507869..019f0ec 100644 --- a/app/components/InputAddon.vue +++ b/app/components/InputAddon.vue @@ -1,11 +1,19 @@ @@ -14,6 +22,79 @@ import { cn } from '@/lib/utils'; const props = defineProps({ icon: { type: [Object, Function], required: true }, + dragStartValue: { type: Number, required: false }, class: { type: null, required: false }, }); + +const pixelsPerStep = 3; +let drag = null; + +function startDrag(event) { + const input = event.currentTarget.previousElementSibling; + + if ( + drag || + event.button !== 0 || + input?.type !== 'number' || + input.disabled || + input.readOnly + ) { + return; + } + + event.preventDefault(); + event.currentTarget.setPointerCapture(event.pointerId); + drag = { input, pointerId: event.pointerId, x: event.clientX, moved: false }; +} + +function adjustValue(event) { + if (drag?.pointerId !== event.pointerId) return; + + const steps = Math.trunc((event.clientX - drag.x) / pixelsPerStep); + if (!steps) return; + + drag.x += steps * pixelsPerStep; + drag.moved = true; + + const { input } = drag; + if (input.disabled || input.readOnly) return; + + const previousValue = input.value; + if (input.value === '' && props.dragStartValue != null) { + input.valueAsNumber = props.dragStartValue; + } + + if (steps > 0) { + input.stepUp(steps); + } else { + input.stepDown(-steps); + } + + if (input.value !== previousValue) { + input.dispatchEvent(new Event('input', { bubbles: true })); + } +} + +function finishDrag(event) { + if (drag?.pointerId !== event.pointerId) return; + + if (!drag.moved) drag.input.focus(); + drag = null; +} + +function clearDrag(event) { + if (drag?.pointerId === event.pointerId) drag = null; +} + + diff --git a/app/components/InspectorNumberField.vue b/app/components/InspectorNumberField.vue new file mode 100644 index 0000000..ea69520 --- /dev/null +++ b/app/components/InspectorNumberField.vue @@ -0,0 +1,72 @@ + + + diff --git a/app/components/ModalPreferences.vue b/app/components/ModalPreferences.vue index bdaf975..5639303 100644 --- a/app/components/ModalPreferences.vue +++ b/app/components/ModalPreferences.vue @@ -293,6 +293,7 @@ -
+

Effects & spacing

- +
-
- - -
- - -
-
+ + +
-
- - -
- - -
-
+
+ + +
-
-
+