audiobookshelf/client/components/ui/TextInputWithLabel.vue

59 lines
1.3 KiB
Vue
Raw Normal View History

2021-08-18 00:01:11 +02:00
<template>
<div class="w-full">
<slot>
2022-12-30 01:03:05 +01:00
<label :for="identifier" class="px-1 text-sm font-semibold" :class="{ 'text-gray-400': disabled }"
>{{ label }}<em v-if="note" class="font-normal text-xs pl-2">{{ note }}</em></label
>
</slot>
<ui-text-input :placeholder="label" :inputId="identifier" ref="input" v-model="inputValue" :disabled="disabled" :readonly="readonly" :type="type" class="w-full" :class="inputClass" @blur="inputBlurred" />
2021-08-18 00:01:11 +02:00
</div>
</template>
<script>
export default {
props: {
value: [String, Number],
label: String,
2021-09-14 03:18:58 +02:00
note: String,
type: {
type: String,
default: 'text'
},
readonly: Boolean,
disabled: Boolean,
inputClass: String
2021-08-18 00:01:11 +02:00
},
data() {
return {}
},
computed: {
inputValue: {
get() {
return this.value
},
set(val) {
this.$emit('input', val)
}
},
identifier() {
return Math.random().toString(36).substring(2)
2021-08-18 00:01:11 +02:00
}
},
2022-02-17 21:33:12 +01:00
methods: {
setFocus() {
if (this.$refs.input && this.$refs.input.setFocus) {
this.$refs.input.setFocus()
}
},
2022-02-17 21:33:12 +01:00
blur() {
if (this.$refs.input && this.$refs.input.blur) {
this.$refs.input.blur()
}
},
inputBlurred() {
this.$emit('blur')
2022-02-17 21:33:12 +01:00
}
},
2021-08-18 00:01:11 +02:00
mounted() {}
}
</script>