Files
thetool/public/plugins/vue/tt-components/tt-input.js
2024-11-12 18:24:25 +01:00

47 lines
1.3 KiB
JavaScript

Vue.component('tt-input', {
props: {
label: String,
type: String,
disabled: Boolean,
placeholder: String,
required: Boolean,
row: Boolean,
value: [String, Number],
hint: String,
additionalProps: Object,
sm: {type: Boolean, default: false},
},
data() {
return {
inputValue: this.value,
};
},
watch: {
value(val) {
this.inputValue = val;
}
},
template: `
<div class="form-group" :class="{'row': row}">
<slot name="prepend"></slot>
<label
:class="{'col-form-label': row, 'col-sm-4': row, 'col-form-label-sm': sm && row}"
v-if="label"
:for="label">{{ label }}</label>
<input :type="type"
:id="label"
:name="label"
class="form-control"
:class="{'form-control-sm': sm, 'col-sm-8': row}"
:placeholder="placeholder"
:required="required"
:disabled="disabled"
v-bind="additionalProps"
v-model="inputValue"
@input="$emit('input', $event.target.value)"
>
<small v-if="hint" class="form-text text-muted">{{ hint }}</small>
</div>
`
});