homebox/frontend/components/Form/TextArea.vue

74 lines
1.7 KiB
Vue
Raw Normal View History

2022-09-02 17:46:20 +00:00
<template>
<div v-if="!inline" class="form-control w-full">
2022-09-02 17:46:20 +00:00
<label class="label">
<span class="label-text">{{ label }}</span>
</label>
<textarea ref="el" v-model="value" class="textarea w-full textarea-bordered h-28" :placeholder="placeholder" />
2022-09-02 17:46:20 +00:00
<label v-if="limit" class="label">
<span class="label-text-alt"></span>
<span class="label-text-alt"> {{ valueLen }}/{{ limit }}</span>
</label>
</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>
<textarea
ref="el"
v-model="value"
class="textarea textarea-bordered w-full col-span-3 mt-3 h-28"
auto-grow
:placeholder="placeholder"
auto-height
/>
2022-09-07 05:58:59 +00:00
</div>
2022-09-02 17:46:20 +00:00
</template>
<script lang="ts" setup>
const emit = defineEmits(["update:modelValue"]);
2022-09-02 17:46:20 +00:00
const props = defineProps({
modelValue: {
2022-09-07 05:58:59 +00:00
type: [String],
2022-09-02 17:46:20 +00:00
required: true,
},
label: {
type: String,
required: true,
},
type: {
type: String,
default: "text",
2022-09-02 17:46:20 +00:00
},
limit: {
type: [Number, String],
default: null,
},
placeholder: {
type: String,
default: "",
2022-09-02 17:46:20 +00:00
},
2022-09-07 05:58:59 +00:00
inline: {
type: Boolean,
default: false,
},
2022-09-02 17:46:20 +00:00
});
const el = ref();
function setHeight() {
el.value.style.height = "auto";
el.value.style.height = el.value.scrollHeight + 5 + "px";
}
onUpdated(() => {
console.log("updated");
if (props.inline) {
setHeight();
}
});
const value = useVModel(props, "modelValue", emit);
2022-09-02 17:46:20 +00:00
const valueLen = computed(() => {
return value.value ? value.value.length : 0;
});
</script>