homebox/frontend/components/Form/TextField.vue

53 lines
1.1 KiB
Vue
Raw Permalink Normal View History

2022-09-01 22:32:03 +00:00
<template>
2022-09-07 05:58:59 +00:00
<div v-if="!inline" class="form-control w-full">
2022-09-01 22:32:03 +00:00
<label class="label">
<span class="label-text">{{ label }}</span>
</label>
<input ref="input" v-model="value" :type="type" class="input input-bordered w-full" />
2022-09-01 22:32:03 +00:00
</div>
2022-09-07 05:58:59 +00:00
<div v-else class="sm:grid sm:grid-cols-4 sm:items-start sm:gap-4">
<label class="label">
<span class="label-text">{{ label }}</span>
</label>
<input v-model="value" class="input input-bordered col-span-3 w-full mt-2" />
2022-09-07 05:58:59 +00:00
</div>
2022-09-01 22:32:03 +00:00
</template>
<script lang="ts" setup>
const props = defineProps({
2022-09-02 17:46:20 +00:00
label: {
2022-09-01 22:32:03 +00:00
type: String,
default: "",
2022-09-01 22:32:03 +00:00
},
2022-09-02 17:46:20 +00:00
modelValue: {
2022-09-07 05:58:59 +00:00
type: [String, Number],
2022-09-02 17:46:20 +00:00
default: null,
2022-09-01 22:32:03 +00:00
},
type: {
type: String,
default: "text",
2022-09-01 22:32:03 +00:00
},
triggerFocus: {
type: Boolean,
default: null,
},
2022-09-07 05:58:59 +00:00
inline: {
type: Boolean,
default: false,
},
2022-09-01 22:32:03 +00:00
});
const input = ref<HTMLElement | null>(null);
whenever(
() => props.triggerFocus,
() => {
if (input.value) {
input.value.focus();
}
}
);
const value = useVModel(props, "modelValue");
2022-09-01 22:32:03 +00:00
</script>