Line data Source code
1 2 : <template>
2 22 : <label
3 : class="flex min-w-0 flex-1 items-center gap-1 rounded-md border bg-secondary px-1.5 py-1"
4 : >
5 : <span class="shrink-0 text-xs text-muted-foreground">{{ label }}</span>
6 : <Input
7 : v-model="draft"
8 : type="number"
9 : :min
10 : :max
11 : :step
12 : class="h-auto [appearance:textfield] rounded-none bg-transparent p-0 text-xs focus-visible:ring-0 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
13 : @change="onChange"
14 : />
15 : </label>
16 : </template>
17 :
18 : <script setup lang="ts">
19 : import { nextTick, ref, watch } from 'vue'
20 :
21 : import Input from '@comfyorg/design-system/input/Input'
22 :
23 : const {
24 : label,
25 : value,
26 : min,
27 : max,
28 : step = 1
29 : } = defineProps<{
30 : label: string
31 : value: number
32 : min?: number
33 : max?: number
34 : step?: number
35 : }>()
36 :
37 16 : const emit = defineEmits<{ commit: [value: number] }>()
38 :
39 16 : const draft = ref<string | number>(value)
40 :
41 16 : watch(
42 : () => value,
43 : (next) => {
44 4 : draft.value = next
45 : }
46 : )
47 :
48 1 : function onChange(): void {
49 1 : const raw = draft.value
50 1 : const next =
51 : typeof raw === 'string' && raw.trim() === '' ? Number.NaN : Number(raw)
52 1 : if (Number.isFinite(next)) {
53 0 : const low = min ?? -Infinity
54 0 : const high = max ?? Infinity
55 0 : emit('commit', Math.min(high, Math.max(low, next)))
56 : }
57 1 : void nextTick(() => {
58 1 : draft.value = value
59 : })
60 : }
61 : </script>
|