@vue-interface/input-field 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/InputField.vue +129 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-interface/input-field",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "A Vue input field component.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/input-field.umd.cjs",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"homepage": "https://vue-interface.github.io/packages/input-field",
|
|
36
36
|
"readme": "README.md",
|
|
37
37
|
"files": [
|
|
38
|
+
"src",
|
|
38
39
|
"dist",
|
|
39
40
|
"index.css",
|
|
40
41
|
"README.md",
|
|
@@ -42,8 +43,8 @@
|
|
|
42
43
|
],
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"vue": "^3.3.4",
|
|
45
|
-
"@vue-interface/activity-indicator": "3.0.
|
|
46
|
-
"@vue-interface/form-control": "2.0.
|
|
46
|
+
"@vue-interface/activity-indicator": "3.0.3",
|
|
47
|
+
"@vue-interface/form-control": "2.0.4"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"dev": "vite",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<script setup lang="ts" generic="ModelValue, Value">
|
|
2
|
+
import { ActivityIndicator } from '@vue-interface/activity-indicator';
|
|
3
|
+
import type { FormControlEvents, FormControlProps, FormControlSlots } from '@vue-interface/form-control';
|
|
4
|
+
import { FormControlErrors, FormControlFeedback, useFormControl } from '@vue-interface/form-control';
|
|
5
|
+
import { InputHTMLAttributes, useTemplateRef } from 'vue';
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<InputFieldProps<ModelValue,Value>>(), {
|
|
8
|
+
formControlClass: 'form-control',
|
|
9
|
+
labelClass: 'form-label'
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
defineOptions({
|
|
13
|
+
inheritAttrs: false
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const model = defineModel<ModelValue>();
|
|
17
|
+
|
|
18
|
+
defineSlots<FormControlSlots<InputFieldControlSizePrefix,ModelValue>>();
|
|
19
|
+
|
|
20
|
+
const emit = defineEmits<FormControlEvents<ModelValue>>();
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
controlAttributes,
|
|
24
|
+
formGroupClasses,
|
|
25
|
+
listeners
|
|
26
|
+
} = useFormControl<InputHTMLAttributes, InputFieldControlSizePrefix, ModelValue, Value>({ model, props, emit });
|
|
27
|
+
|
|
28
|
+
const field = useTemplateRef<HTMLInputElement>('field');
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script lang="ts">
|
|
32
|
+
export type InputFieldControlSizePrefix = 'form-control';
|
|
33
|
+
|
|
34
|
+
export type InputFieldProps<ModelValue, Value> = FormControlProps<
|
|
35
|
+
InputHTMLAttributes,
|
|
36
|
+
InputFieldControlSizePrefix,
|
|
37
|
+
ModelValue,
|
|
38
|
+
Value
|
|
39
|
+
>;
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<div
|
|
44
|
+
class="input-field"
|
|
45
|
+
:class="formGroupClasses">
|
|
46
|
+
<slot name="label">
|
|
47
|
+
<label
|
|
48
|
+
v-if="label"
|
|
49
|
+
ref="label"
|
|
50
|
+
:class="labelClass"
|
|
51
|
+
:for="controlAttributes.id">
|
|
52
|
+
{{ label }}
|
|
53
|
+
</label>
|
|
54
|
+
</slot>
|
|
55
|
+
|
|
56
|
+
<div class="form-control-inner">
|
|
57
|
+
<slot
|
|
58
|
+
name="control"
|
|
59
|
+
v-bind="{ controlAttributes, listeners }">
|
|
60
|
+
<div
|
|
61
|
+
v-if="$slots.icon"
|
|
62
|
+
class="form-control-inner-icon"
|
|
63
|
+
@click="field?.focus()">
|
|
64
|
+
<slot name="icon" />
|
|
65
|
+
</div>
|
|
66
|
+
<input
|
|
67
|
+
ref="field"
|
|
68
|
+
v-model="model"
|
|
69
|
+
v-bind="{...controlAttributes, ...listeners}">
|
|
70
|
+
</slot>
|
|
71
|
+
|
|
72
|
+
<div class="form-control-activity-indicator">
|
|
73
|
+
<slot name="activity">
|
|
74
|
+
<Transition name="input-field-fade">
|
|
75
|
+
<ActivityIndicator
|
|
76
|
+
v-if="activity && indicator"
|
|
77
|
+
key="activity"
|
|
78
|
+
ref="activity"
|
|
79
|
+
:type="indicator"
|
|
80
|
+
:size="indicatorSize" />
|
|
81
|
+
</Transition>
|
|
82
|
+
</slot>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<slot
|
|
87
|
+
name="errors"
|
|
88
|
+
v-bind="{ error, errors, id: $attrs.id, name: $attrs.name }">
|
|
89
|
+
<FormControlErrors
|
|
90
|
+
v-if="!!(error || errors)"
|
|
91
|
+
:id="id"
|
|
92
|
+
v-slot="{ error }"
|
|
93
|
+
:name="name"
|
|
94
|
+
:error="error"
|
|
95
|
+
:errors="errors">
|
|
96
|
+
<div
|
|
97
|
+
invalid
|
|
98
|
+
class="invalid-feedback">
|
|
99
|
+
{{ error }}<br>
|
|
100
|
+
</div>
|
|
101
|
+
</FormControlErrors>
|
|
102
|
+
</slot>
|
|
103
|
+
|
|
104
|
+
<slot
|
|
105
|
+
name="feedback"
|
|
106
|
+
v-bind="{ feedback }">
|
|
107
|
+
<FormControlFeedback
|
|
108
|
+
v-slot="{ feedback }"
|
|
109
|
+
:feedback="feedback">
|
|
110
|
+
<div
|
|
111
|
+
valid
|
|
112
|
+
class="valid-feedback">
|
|
113
|
+
{{ feedback }}
|
|
114
|
+
</div>
|
|
115
|
+
</FormControlFeedback>
|
|
116
|
+
</slot>
|
|
117
|
+
|
|
118
|
+
<slot
|
|
119
|
+
name="help"
|
|
120
|
+
v-bind="{ helpText }">
|
|
121
|
+
<small
|
|
122
|
+
v-if="helpText"
|
|
123
|
+
ref="help"
|
|
124
|
+
class="form-help">
|
|
125
|
+
{{ helpText }}
|
|
126
|
+
</small>
|
|
127
|
+
</slot>
|
|
128
|
+
</div>
|
|
129
|
+
</template>
|