-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathBaseInput.vue
97 lines (96 loc) · 2.13 KB
/
BaseInput.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
<div class="form-group"
:class="{
'input-group': hasIcon,
'input-group-focus': focused
}">
<slot name="label">
<label v-if="label" class="control-label">
{{label}}
</label>
</slot>
<slot name="addonLeft">
<span v-if="addonLeftIcon" class="input-group-prepend">
<div class="input-group-text">
<i :class="addonLeftIcon"></i>
</div>
</span>
</slot>
<slot>
<input
:value="value"
v-bind="$attrs"
v-on="listeners"
class="form-control"
aria-describedby="addon-right addon-left">
</slot>
<slot name="addonRight">
<span v-if="addonRightIcon" class="input-group-append">
<div class="input-group-text">
<i :class="addonRightIcon"></i>
</div>
</span>
</slot>
<slot name="helperText"></slot>
</div>
</template>
<script>
export default {
inheritAttrs: false,
name: "base-input",
props: {
label: {
type: String,
description: "Input label"
},
value: {
type: [String, Number],
description: "Input value"
},
addonRightIcon: {
type: String,
description: "Input icon on the right"
},
addonLeftIcon: {
type: String,
description: "Input icon on the left"
},
},
model: {
prop: 'value',
event: 'input'
},
data() {
return {
focused: false
}
},
computed: {
hasIcon() {
const { addonRight, addonLeft } = this.$slots;
return addonRight !== undefined || addonLeft !== undefined || this.addonRightIcon !== undefined || this.addonLeftIcon !== undefined;
},
listeners() {
return {
...this.$listeners,
input: this.onInput,
blur: this.onBlur,
focus: this.onFocus
}
}
},
methods: {
onInput(evt) {
this.$emit('input', evt.target.value)
},
onFocus() {
this.focused = true;
},
onBlur() {
this.focused = false;
}
}
}
</script>
<style>
</style>