|
2 | 2 | <div class="material-input__component" :class="computedClasses"> |
3 | 3 | <div :class="{iconClass:icon}"> |
4 | 4 | <i class="el-input__icon material-input__icon" :class="['el-icon-' + icon]" v-if="icon"></i> |
5 | | - <input v-if="type === 'email'" type="email" class="material-input" :name="name" |
6 | | - :placeholder="fillPlaceHolder" v-model="currentValue" |
7 | | - :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :required="required" |
8 | | - @focus="handleMdFocus" |
9 | | - @blur="handleMdBlur" @input="handleModelInput"> |
10 | | - <input v-if="type === 'url'" type="url" class="material-input" :name="name" |
11 | | - :placeholder="fillPlaceHolder" |
12 | | - v-model="currentValue" |
13 | | - :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :required="required" |
14 | | - @focus="handleMdFocus" |
15 | | - @blur="handleMdBlur" @input="handleModelInput"> |
16 | | - <input v-if="type === 'number'" type="number" class="material-input" :name="name" |
17 | | - :placeholder="fillPlaceHolder" v-model="currentValue" :step="step" |
18 | | - :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :max="max" :min="min" |
19 | | - :minlength="minlength" :maxlength="maxlength" |
20 | | - :required="required" @focus="handleMdFocus" @blur="handleMdBlur" @input="handleModelInput"> |
21 | | - <input v-if="type === 'password'" type="password" class="material-input" :name="name" |
22 | | - :placeholder="fillPlaceHolder" |
23 | | - v-model="currentValue" :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :max="max" |
24 | | - :min="min" :required="required" |
25 | | - @focus="handleMdFocus" @blur="handleMdBlur" @input="handleModelInput"> |
26 | | - <input v-if="type === 'tel'" type="tel" class="material-input" :name="name" |
27 | | - :placeholder="fillPlaceHolder" |
28 | | - v-model="currentValue" |
29 | | - :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :required="required" |
30 | | - @focus="handleMdFocus" |
31 | | - @blur="handleMdBlur" @input="handleModelInput"> |
32 | | - <input v-if="type === 'text'" type="text" class="material-input" :name="name" |
33 | | - :placeholder="fillPlaceHolder" v-model="currentValue" |
34 | | - :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :minlength="minlength" |
35 | | - :maxlength="maxlength" |
36 | | - :required="required" @focus="handleMdFocus" @blur="handleMdBlur" @input="handleModelInput"> |
37 | | - |
| 5 | + <input v-if="type === 'email'" type="email" class="material-input" :name="name" :placeholder="fillPlaceHolder" v-model="currentValue" |
| 6 | + :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :required="required" @focus="handleMdFocus" |
| 7 | + @blur="handleMdBlur" @input="handleModelInput"> |
| 8 | + <input v-if="type === 'url'" type="url" class="material-input" :name="name" :placeholder="fillPlaceHolder" v-model="currentValue" |
| 9 | + :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :required="required" @focus="handleMdFocus" |
| 10 | + @blur="handleMdBlur" @input="handleModelInput"> |
| 11 | + <input v-if="type === 'number'" type="number" class="material-input" :name="name" :placeholder="fillPlaceHolder" v-model="currentValue" |
| 12 | + :step="step" :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :max="max" :min="min" :minlength="minlength" |
| 13 | + :maxlength="maxlength" :required="required" @focus="handleMdFocus" @blur="handleMdBlur" @input="handleModelInput"> |
| 14 | + <input v-if="type === 'password'" type="password" class="material-input" :name="name" :placeholder="fillPlaceHolder" v-model="currentValue" |
| 15 | + :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :max="max" :min="min" :required="required" @focus="handleMdFocus" |
| 16 | + @blur="handleMdBlur" @input="handleModelInput"> |
| 17 | + <input v-if="type === 'tel'" type="tel" class="material-input" :name="name" :placeholder="fillPlaceHolder" v-model="currentValue" |
| 18 | + :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :required="required" @focus="handleMdFocus" |
| 19 | + @blur="handleMdBlur" @input="handleModelInput"> |
| 20 | + <input v-if="type === 'text'" type="text" class="material-input" :name="name" :placeholder="fillPlaceHolder" v-model="currentValue" |
| 21 | + :readonly="readonly" :disabled="disabled" :autoComplete="autoComplete" :minlength="minlength" :maxlength="maxlength" |
| 22 | + :required="required" @focus="handleMdFocus" @blur="handleMdBlur" @input="handleModelInput"> |
38 | 23 | <span class="material-input-bar"></span> |
39 | | - |
40 | 24 | <label class="material-label"> |
41 | 25 | <slot></slot> |
42 | 26 | </label> |
43 | | - |
44 | 27 | </div> |
45 | 28 | </div> |
46 | 29 | </template> |
47 | 30 |
|
48 | 31 | <script> |
49 | | - // source:https://github.com/wemake-services/vue-material-input/blob/master/src/components/MaterialInput.vue |
| 32 | +// source:https://github.com/wemake-services/vue-material-input/blob/master/src/components/MaterialInput.vue |
50 | 33 |
|
51 | | - export default { |
52 | | -
|
53 | | - name: 'md-input', |
54 | | - computed: { |
55 | | - computedClasses() { |
56 | | - return { |
57 | | - 'material--active': this.focus, |
58 | | - 'material--disabled': this.disabled, |
59 | | - 'material--raised': Boolean(this.focus || this.currentValue) // has value |
60 | | - } |
61 | | - } |
| 34 | +export default { |
| 35 | + name: 'md-input', |
| 36 | + props: { |
| 37 | + icon: String, |
| 38 | + name: String, |
| 39 | + type: { |
| 40 | + type: String, |
| 41 | + default: 'text' |
| 42 | + }, |
| 43 | + value: [String, Number], |
| 44 | + placeholder: String, |
| 45 | + readonly: Boolean, |
| 46 | + disabled: Boolean, |
| 47 | + min: String, |
| 48 | + max: String, |
| 49 | + step: String, |
| 50 | + minlength: Number, |
| 51 | + maxlength: Number, |
| 52 | + required: { |
| 53 | + type: Boolean, |
| 54 | + default: true |
62 | 55 | }, |
63 | | - data() { |
| 56 | + autoComplete: { |
| 57 | + type: String, |
| 58 | + default: 'off' |
| 59 | + }, |
| 60 | + validateEvent: { |
| 61 | + type: Boolean, |
| 62 | + default: true |
| 63 | + } |
| 64 | + }, |
| 65 | + computed: { |
| 66 | + computedClasses() { |
64 | 67 | return { |
65 | | - currentValue: this.value, |
66 | | - focus: false, |
67 | | - fillPlaceHolder: null |
| 68 | + 'material--active': this.focus, |
| 69 | + 'material--disabled': this.disabled, |
| 70 | + 'material--raised': Boolean(this.focus || this.currentValue) // has value |
68 | 71 | } |
69 | | - }, |
70 | | - methods: { |
71 | | - handleModelInput(event) { |
72 | | - const value = event.target.value |
73 | | - this.$emit('input', value) |
74 | | - if (this.$parent.$options.componentName === 'ElFormItem') { |
75 | | - if (this.validateEvent) { |
76 | | - this.$parent.$emit('el.form.change', [value]) |
77 | | - } |
78 | | - } |
79 | | - this.$emit('change', value) |
80 | | -// this.handleValidation() |
81 | | - }, |
82 | | - handleMdFocus(event) { |
83 | | - this.focus = true |
84 | | - this.$emit('focus', event) |
85 | | - if (this.placeholder && this.placeholder !== '') { |
86 | | - this.fillPlaceHolder = this.placeholder |
87 | | - } |
88 | | - }, |
89 | | - handleMdBlur(event) { |
90 | | - this.focus = false |
91 | | - this.$emit('blur', event) |
92 | | - this.fillPlaceHolder = null |
93 | | - if (this.$parent.$options.componentName === 'ElFormItem') { |
94 | | - if (this.validateEvent) { |
95 | | - this.$parent.$emit('el.form.blur', [this.currentValue]) |
96 | | - } |
| 72 | + } |
| 73 | + }, |
| 74 | + data() { |
| 75 | + return { |
| 76 | + currentValue: this.value, |
| 77 | + focus: false, |
| 78 | + fillPlaceHolder: null |
| 79 | + } |
| 80 | + }, |
| 81 | + methods: { |
| 82 | + handleModelInput(event) { |
| 83 | + const value = event.target.value |
| 84 | + this.$emit('input', value) |
| 85 | + if (this.$parent.$options.componentName === 'ElFormItem') { |
| 86 | + if (this.validateEvent) { |
| 87 | + this.$parent.$emit('el.form.change', [value]) |
97 | 88 | } |
98 | 89 | } |
| 90 | + this.$emit('change', value) |
| 91 | + }, |
| 92 | + handleMdFocus(event) { |
| 93 | + this.focus = true |
| 94 | + this.$emit('focus', event) |
| 95 | + if (this.placeholder && this.placeholder !== '') { |
| 96 | + this.fillPlaceHolder = this.placeholder |
| 97 | + } |
99 | 98 | }, |
100 | | - props: { |
101 | | - icon: String, |
102 | | - name: String, |
103 | | - type: { |
104 | | - type: String, |
105 | | - default: 'text' |
106 | | - }, |
107 | | - value: [String, Number], |
108 | | - placeholder: String, |
109 | | - readonly: Boolean, |
110 | | - disabled: Boolean, |
111 | | - min: String, |
112 | | - max: String, |
113 | | - step: String, |
114 | | - minlength: Number, |
115 | | - maxlength: Number, |
116 | | - required: { |
117 | | - type: Boolean, |
118 | | - default: true |
119 | | - }, |
120 | | - autoComplete: { |
121 | | - type: String, |
122 | | - default: 'off' |
123 | | - }, |
124 | | - validateEvent: { |
125 | | - type: Boolean, |
126 | | - default: true |
| 99 | + handleMdBlur(event) { |
| 100 | + this.focus = false |
| 101 | + this.$emit('blur', event) |
| 102 | + this.fillPlaceHolder = null |
| 103 | + if (this.$parent.$options.componentName === 'ElFormItem') { |
| 104 | + if (this.validateEvent) { |
| 105 | + this.$parent.$emit('el.form.blur', [this.currentValue]) |
| 106 | + } |
127 | 107 | } |
128 | 108 | } |
129 | 109 | } |
| 110 | +} |
130 | 111 | </script> |
131 | 112 |
|
132 | 113 | <style rel="stylesheet/scss" lang="scss" scoped> |
|
0 commit comments