forked from creativetimofficial/vue-material-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaterialInput.vue
91 lines (88 loc) · 1.6 KB
/
MaterialInput.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
<script setup>
defineProps({
id: {
type: String,
default: "",
},
type: {
type: String,
default: "text",
},
label: {
type: [String, Object],
text: String,
class: String,
default: () => ({
class: "",
}),
},
value: {
type: String,
default: "",
},
placeholder: {
type: String,
default: "",
},
size: {
type: String,
default: "md",
},
error: {
type: Boolean,
default: false,
},
success: {
type: Boolean,
default: false,
},
isRequired: {
type: Boolean,
default: false,
},
isDisabled: {
type: Boolean,
default: false,
},
inputClass: {
type: String,
default: "",
},
icon: {
type: String,
default: "",
},
});
function getClasses(size, success, error) {
let sizeValue, isValidValue;
sizeValue = size && `form-control-${size}`;
if (error) {
isValidValue = "is-invalid";
} else if (success) {
isValidValue = "is-valid";
} else {
isValidValue = "";
}
return `${sizeValue} ${isValidValue}`;
}
</script>
<template>
<div class="input-group">
<label v-if="label" :class="label.class">{{
typeof label == "string" ? label : label.text
}}</label>
<span v-if="icon" class="input-group-text"
><i class="fas" :class="`fa-${icon}`" aria-hidden="true"></i
></span>
<input
:id="id"
:type="type"
class="form-control"
:class="[getClasses(size, success, error), inputClass]"
:value="value"
:placeholder="placeholder"
:isRequired="isRequired"
:disabled="isDisabled"
/>
</div>
</template>