39 lines
1.5 KiB
Vue
39 lines
1.5 KiB
Vue
<script setup lang="ts">
|
|
import type { HTMLAttributes } from "vue";
|
|
import { useVModel } from "@vueuse/core";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const props = defineProps<{
|
|
defaultValue?: string | number;
|
|
modelValue?: string | number | null;
|
|
class?: HTMLAttributes["class"];
|
|
invalid?: boolean;
|
|
}>();
|
|
|
|
const emits = defineEmits<{
|
|
(e: "update:modelValue", payload: string | number): void;
|
|
}>();
|
|
|
|
const modelValue = useVModel(props, "modelValue", emits, {
|
|
passive: true,
|
|
defaultValue: props.defaultValue,
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<input
|
|
v-model="modelValue"
|
|
data-slot="input"
|
|
:data-invalid="invalid ? '' : undefined"
|
|
:aria-invalid="invalid ? 'true' : undefined"
|
|
:class="
|
|
cn(
|
|
'border-input bg-card placeholder:text-muted-foreground selection:bg-brand selection:text-brand-foreground min-h-control w-full min-w-0 rounded-md border px-3 py-2 text-base shadow-xs transition-[border-color,box-shadow] outline-none file:mr-3 file:inline-flex file:min-h-8 file:border-0 file:bg-transparent file:text-body file:font-semibold disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 md:text-body',
|
|
'hover:border-primary/45 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/35',
|
|
'aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/25',
|
|
props.class,
|
|
)
|
|
"
|
|
/>
|
|
</template>
|