geoproject-app/src/components/ui/NumberInput.vue

106 lines
2.2 KiB
Vue
Raw Normal View History

2025-12-09 17:08:40 +01:00
<template>
<div class="number-input">
<input
type="number"
:value="modelValue"
:min="min"
:max="max"
:step="step"
:id="id"
:class="inputClass"
:disabled="disabled"
@input="handleInput"
/>
<div class="spinner-buttons">
<button
type="button"
class="spinner-btn spinner-up"
@click="increment"
:disabled="disabled || (max !== undefined && modelValue >= max)"
tabindex="-1"
>
<svg
width="8"
height="6"
viewBox="0 0 8 6"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M4 0L7.4641 6H0.535898L4 0Z" fill="currentColor" />
2025-12-09 17:08:40 +01:00
</svg>
</button>
<button
type="button"
class="spinner-btn spinner-down"
@click="decrement"
:disabled="disabled || (min !== undefined && modelValue <= min)"
tabindex="-1"
>
<svg
width="8"
height="6"
viewBox="0 0 8 6"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M4 6L0.535898 0H7.4641L4 6Z" fill="currentColor" />
2025-12-09 17:08:40 +01:00
</svg>
</button>
</div>
</div>
</template>
<script setup>
const props = defineProps({
modelValue: {
type: Number,
required: true,
2025-12-09 17:08:40 +01:00
},
min: {
type: Number,
default: undefined,
2025-12-09 17:08:40 +01:00
},
max: {
type: Number,
default: undefined,
2025-12-09 17:08:40 +01:00
},
step: {
type: Number,
default: 1,
2025-12-09 17:08:40 +01:00
},
id: {
type: String,
default: undefined,
2025-12-09 17:08:40 +01:00
},
inputClass: {
type: String,
default: '',
2025-12-09 17:08:40 +01:00
},
disabled: {
type: Boolean,
default: false,
},
2025-12-09 17:08:40 +01:00
});
const emit = defineEmits(['update:modelValue']);
const handleInput = (event) => {
const value = Number(event.target.value);
emit('update:modelValue', value);
};
const increment = () => {
const newValue = props.modelValue + props.step;
if (props.max === undefined || newValue <= props.max) {
emit('update:modelValue', newValue);
}
};
const decrement = () => {
const newValue = props.modelValue - props.step;
if (props.min === undefined || newValue >= props.min) {
emit('update:modelValue', newValue);
}
};
</script>