|
1 | 1 | <template> |
2 | | - <input |
3 | | - ref="input" |
4 | | - v-bind="{ |
5 | | - autocomplete, |
6 | | - autofocus, |
7 | | - disabled, |
8 | | - id, |
9 | | - minlength, |
10 | | - name, |
11 | | - pattern, |
12 | | - placeholder, |
13 | | - required, |
14 | | - spellcheck, |
15 | | - type, |
16 | | - value |
17 | | - }" |
18 | | - v-direction |
19 | | - :data-font="font" |
| 2 | + <k-string-input |
| 3 | + v-bind="$props" |
| 4 | + type="text" |
20 | 5 | class="k-text-input" |
21 | | - @input="onInput($event.target.value)" |
| 6 | + @input="$emit('input', $event)" |
| 7 | + @invalid="($invalid, $v) => $emit('invalid', $invalid, $v)" |
22 | 8 | /> |
23 | 9 | </template> |
24 | 10 |
|
25 | 11 | <script> |
26 | | -import Input, { props as InputProps } from "@/mixins/input.js"; |
27 | | -import { |
28 | | - font, |
29 | | - maxlength, |
30 | | - minlength, |
31 | | - pattern, |
32 | | - placeholder, |
33 | | - spellcheck |
34 | | -} from "@/mixins/props.js"; |
35 | | -
|
36 | | -import { |
37 | | - required as validateRequired, |
38 | | - minLength as validateMinLength, |
39 | | - maxLength as validateMaxLength, |
40 | | - email as validateEmail, |
41 | | - url as validateUrl |
42 | | -} from "vuelidate/lib/validators"; |
| 12 | +import StringInput, { props as StringInputProps } from "./StringInput.vue"; |
43 | 13 |
|
44 | 14 | export const props = { |
45 | | - mixins: [ |
46 | | - InputProps, |
47 | | - font, |
48 | | - maxlength, |
49 | | - minlength, |
50 | | - pattern, |
51 | | - placeholder, |
52 | | - spellcheck |
53 | | - ], |
54 | | - props: { |
55 | | - autocomplete: { |
56 | | - type: [Boolean, String], |
57 | | - default: "off" |
58 | | - }, |
59 | | - preselect: Boolean, |
60 | | - type: { |
61 | | - type: String, |
62 | | - default: "text" |
63 | | - }, |
64 | | - value: String |
65 | | - } |
| 15 | + mixins: [StringInputProps] |
66 | 16 | }; |
67 | 17 |
|
68 | 18 | /** |
69 | | - * @example <k-input :value="text" @input="text = $event" name="text" type="text" /> |
| 19 | + * @example <k-text-input :value="text" @input="text = $event" name="text" /> |
70 | 20 | */ |
71 | 21 | export default { |
72 | | - mixins: [Input, props], |
73 | | - watch: { |
74 | | - value() { |
75 | | - this.onInvalid(); |
76 | | - } |
77 | | - }, |
78 | | - mounted() { |
79 | | - this.onInvalid(); |
80 | | -
|
81 | | - if (this.$props.autofocus) { |
82 | | - this.focus(); |
83 | | - } |
84 | | -
|
85 | | - if (this.$props.preselect) { |
86 | | - this.select(); |
87 | | - } |
88 | | - }, |
89 | | - methods: { |
90 | | - onInput(value) { |
91 | | - this.$emit("input", value); |
92 | | - }, |
93 | | - onInvalid() { |
94 | | - this.$emit("invalid", this.$v.$invalid, this.$v); |
95 | | - }, |
96 | | - select() { |
97 | | - this.$refs.input.select(); |
98 | | - } |
99 | | - }, |
100 | | - validations() { |
101 | | - const validateMatch = (value) => { |
102 | | - return ( |
103 | | - (!this.required && !value) || !this.$refs.input.validity.patternMismatch |
104 | | - ); |
105 | | - }; |
106 | | -
|
107 | | - return { |
108 | | - value: { |
109 | | - required: this.required ? validateRequired : true, |
110 | | - minLength: this.minlength ? validateMinLength(this.minlength) : true, |
111 | | - maxLength: this.maxlength ? validateMaxLength(this.maxlength) : true, |
112 | | - email: this.type === "email" ? validateEmail : true, |
113 | | - url: this.type === "url" ? validateUrl : true, |
114 | | - pattern: this.pattern ? validateMatch : true |
115 | | - } |
116 | | - }; |
117 | | - } |
| 22 | + mixins: [StringInput, props] |
118 | 23 | }; |
119 | 24 | </script> |
120 | 25 |
|
|
0 commit comments