Line data Source code
1 : <template>
2 7 : <div class="flex flex-col gap-2">
3 : <label :for="fieldId" class="text-muted-foreground">{{ label }}</label>
4 : <div
5 : :class="
6 : cn(
7 : 'flex h-10 items-center gap-2 rounded-lg border border-solid border-transparent bg-secondary px-4 focus-within:border-foreground',
8 : error && 'border-destructive focus-within:border-destructive',
9 : locked && 'opacity-50',
10 : ui.field
11 : )
12 : "
13 : >
14 : <span v-if="prefix" class="text-muted-foreground" aria-hidden="true">
15 : {{ prefix }}
16 : </span>
17 : <input
18 : :id="fieldId"
19 : :value="input"
20 : type="text"
21 : :inputmode="prefix ? 'decimal' : 'numeric'"
22 : autocomplete="off"
23 : :disabled="locked"
24 : :aria-invalid="error ? true : undefined"
25 : :aria-describedby="describedBy"
26 : class="min-w-0 flex-1 border-none bg-transparent text-base text-foreground outline-none"
27 : :data-testid="inputTestId"
28 : @input="onInput"
29 : />
30 : </div>
31 : <p
32 : v-if="reserveNote || error || hint"
33 : :id="noteId"
34 : :class="
35 : cn(
36 : 'm-0',
37 : reserveNote && 'min-h-5',
38 : hint && !error ? 'text-muted-foreground' : 'text-destructive',
39 : ui.error
40 : )
41 : "
42 : :data-testid="noteTestId"
43 : aria-live="polite"
44 : >
45 : {{ error ?? hint }}
46 : </p>
47 : </div>
48 : </template>
49 :
50 : <script setup lang="ts">
51 : import { computed, useId } from 'vue'
52 :
53 : import { cn } from '@comfyorg/tailwind-utils'
54 :
55 : import type { AddCreditsUi } from './addCreditsPresentation'
56 :
57 : const {
58 : input,
59 : label,
60 : error,
61 : hint,
62 : prefix,
63 : locked,
64 : reserveNote,
65 : inputTestId,
66 : noteTestId,
67 : ui
68 : } = defineProps<{
69 : input: string
70 : label: string
71 : error?: string
72 : hint?: string
73 : prefix?: string
74 : locked: boolean
75 : /** Keeps the note line's height so an error does not shift the layout. */
76 : reserveNote?: boolean
77 : inputTestId: string
78 : noteTestId: string
79 : ui: AddCreditsUi
80 : }>()
81 :
82 4 : const emit = defineEmits<{ type: [input: string] }>()
83 :
84 4 : const fieldId = useId()
85 4 : const noteId = useId()
86 4 : const describedBy = computed(() => (error || hint ? noteId : undefined))
87 :
88 0 : function onInput(event: Event) {
89 0 : if (event.target instanceof HTMLInputElement) emit('type', event.target.value)
90 : }
91 : </script>
|