srcdev-nuxt-forms 3.0.0 → 4.1.0
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/assets/styles/ally/_utils.css +20 -0
- package/assets/styles/ally/_variables.css +8 -0
- package/assets/styles/ally/index.css +2 -0
- package/assets/styles/forms/index.css +2 -0
- package/assets/styles/forms/themes/_error.css +85 -0
- package/assets/styles/forms/themes/_ghost.css +85 -0
- package/assets/styles/forms/themes/_input-action-underlined.css +20 -0
- package/assets/styles/forms/themes/_input-action.css +20 -0
- package/assets/styles/forms/themes/_primary.css +92 -0
- package/assets/styles/forms/themes/_secondary.css +85 -0
- package/assets/styles/forms/themes/_success.css +85 -0
- package/assets/styles/forms/themes/_tertiary.css +85 -0
- package/assets/styles/forms/themes/_warning.css +85 -0
- package/assets/styles/forms/themes/index.css +9 -0
- package/assets/styles/forms/variables/_sizes.css +71 -0
- package/assets/styles/forms/variables/_theme.css +11 -0
- package/assets/styles/forms/variables/index.css +2 -0
- package/assets/styles/main.css +5 -0
- package/assets/styles/typography/index.css +2 -0
- package/assets/styles/typography/utils/_font-classes.css +190 -0
- package/assets/styles/typography/utils/_weights.css +69 -0
- package/assets/styles/typography/utils/index.css +2 -0
- package/assets/styles/typography/variables/_colors.css +14 -0
- package/assets/styles/typography/variables/_reponsive-font-size.css +10 -0
- package/assets/styles/typography/variables/index.css +2 -0
- package/assets/styles/utils/_margin-helpers.css +334 -0
- package/assets/styles/utils/_padding-helpers.css +308 -0
- package/assets/styles/utils/_page.css +49 -0
- package/assets/styles/utils/index.css +3 -0
- package/assets/styles/variables/colors/_blue.css +15 -0
- package/assets/styles/variables/colors/_gray.css +16 -0
- package/assets/styles/variables/colors/_green.css +15 -0
- package/assets/styles/variables/colors/_orange.css +15 -0
- package/assets/styles/variables/colors/_red.css +15 -0
- package/assets/styles/variables/colors/_yellow.css +15 -0
- package/assets/styles/variables/colors/colors.css +6 -0
- package/assets/styles/variables/index.css +1 -0
- package/components/forms/c12/prop-validators/index.ts +38 -0
- package/components/forms/c12/utils.ts +14 -0
- package/components/forms/form-errors/InputError.vue +172 -0
- package/components/forms/form-errors/tests/InputError.spec.ts +67 -0
- package/components/forms/input-button/InputButtonCore.vue +191 -0
- package/components/forms/input-button/variants/InputButtonConfirm.vue +66 -0
- package/components/forms/input-button/variants/InputButtonSubmit.vue +62 -0
- package/components/forms/input-checkbox/MultipleCheckboxes.vue +203 -0
- package/components/forms/input-checkbox/SingleCheckbox.vue +169 -0
- package/components/forms/input-checkbox/tests/MultipleCheckboxes.spec.ts +98 -0
- package/components/forms/input-checkbox/tests/data/tags.json +67 -0
- package/components/forms/input-checkbox-radio/InputCheckboxRadioButton.vue +214 -0
- package/components/forms/input-checkbox-radio/InputCheckboxRadioCore.vue +191 -0
- package/components/forms/input-checkbox-radio/InputCheckboxRadioWithLabel.vue +111 -0
- package/components/forms/input-number/InputNumberCore.vue +203 -0
- package/components/forms/input-number/variants/InputNumberDefault.vue +154 -0
- package/components/forms/input-radio/MultipleRadiobuttons.vue +201 -0
- package/components/forms/input-radio/tests/MultipleRadioButtons.spec.ts +89 -0
- package/components/forms/input-radio/tests/data/tags.json +67 -0
- package/components/forms/input-range/InputRangeCore.vue +274 -0
- package/components/forms/input-range/variants/InputRangeDefault.vue +156 -0
- package/components/forms/input-range-fancy/InputRangeFancyCore.vue +450 -0
- package/components/forms/input-range-fancy/InputRangeFancyWithLabel.vue +124 -0
- package/components/forms/input-select/InputSelect.vue +289 -0
- package/components/forms/input-text/InputTextCore.vue +331 -0
- package/components/forms/input-text/variants/InputPasswordWithLabel.vue +130 -0
- package/components/forms/input-text/variants/InputTextAsNumberWithLabel.vue +187 -0
- package/components/forms/input-text/variants/InputTextWithLabel.vue +298 -0
- package/components/forms/input-textarea/InputTextareaCore.vue +234 -0
- package/components/forms/input-textarea/variants/InputTextareaWithLabel.vue +267 -0
- package/components/forms/toggle-switch/ToggleSwitchCore.vue +198 -0
- package/components/forms/toggle-switch/ToggleSwitchCoreOld.vue +216 -0
- package/components/forms/toggle-switch/variants/ToggleSwitchWithLabel.vue +105 -0
- package/components/forms/toggle-switch/variants/ToggleSwitchWithLabelInline.vue +102 -0
- package/components/forms/ui/FormField.vue +78 -0
- package/components/forms/ui/FormWrapper.vue +35 -0
- package/components/utils/colour-scheme-select/ColourSchemeSelect.vue +270 -0
- package/components/utils/colour-scheme-select/ColourSchemeSelectOld.vue +225 -0
- package/components/utils/dark-mode-switcher/DarkModeSwitcher.vue +47 -0
- package/composables/useApiRequest.ts +25 -0
- package/composables/useColourScheme.ts +25 -0
- package/composables/useErrorMessages.ts +59 -0
- package/composables/useFormControl.ts +248 -0
- package/composables/useSleep.ts +5 -0
- package/composables/useStyleClassPassthrough.ts +30 -0
- package/composables/useZodValidation.ts +148 -0
- package/nuxt.config.ts +0 -3
- package/package.json +1 -1
- package/types/types.forms.ts +217 -0
- package/types/types.zodFormControl.ts +21 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<fieldset
|
|
3
|
+
:aria-required="required"
|
|
4
|
+
:aria-invalid="fieldHasError"
|
|
5
|
+
class="input-select-fieldset"
|
|
6
|
+
:class="[inputVariant, { dirty: isDirty }, { active: isActive }, { error: fieldHasError }]"
|
|
7
|
+
:data-testid
|
|
8
|
+
:data-form-theme="formTheme"
|
|
9
|
+
:data-size="size"
|
|
10
|
+
>
|
|
11
|
+
<legend :class="[{ 'has-description': hasDescriptionSlot }]">{{ legend }}</legend>
|
|
12
|
+
|
|
13
|
+
<div v-if="hasDescriptionSlot" :id="`${name}-description`">
|
|
14
|
+
<slot name="description"></slot>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<select class="input-select" :class="[inputVariant]" :name>
|
|
18
|
+
<option v-if="placeholder" :value="null" disabled selected class="input-select-option placeholder">{{ placeholder }}</option>
|
|
19
|
+
<option v-for="item in fieldData.data" :key="item.id" :value="item.value" class="input-select-option">
|
|
20
|
+
<Icon :name="item.icon" class="icon" />
|
|
21
|
+
{{ item.label }}
|
|
22
|
+
</option>
|
|
23
|
+
</select>
|
|
24
|
+
|
|
25
|
+
<InputError :errorMessage="errorMessage" :showError="fieldHasError" :id="errorId" :isDetached="false" :inputVariant />
|
|
26
|
+
</fieldset>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import propValidators from '../c12/prop-validators';
|
|
31
|
+
import type { IFormMultipleOptions } from '@/types/types.forms';
|
|
32
|
+
|
|
33
|
+
const props = defineProps({
|
|
34
|
+
dataTestid: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: 'input-select',
|
|
37
|
+
},
|
|
38
|
+
name: {
|
|
39
|
+
type: String,
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
legend: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: true,
|
|
45
|
+
},
|
|
46
|
+
label: {
|
|
47
|
+
type: String,
|
|
48
|
+
required: true,
|
|
49
|
+
},
|
|
50
|
+
placeholder: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: '',
|
|
53
|
+
},
|
|
54
|
+
errorMessage: {
|
|
55
|
+
type: [Object, String],
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
required: {
|
|
59
|
+
type: Boolean,
|
|
60
|
+
default: false,
|
|
61
|
+
},
|
|
62
|
+
fieldHasError: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: false,
|
|
65
|
+
},
|
|
66
|
+
size: {
|
|
67
|
+
type: String as PropType<string>,
|
|
68
|
+
default: 'medium',
|
|
69
|
+
validator(value: string) {
|
|
70
|
+
return propValidators.size.includes(value);
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
styleClassPassthrough: {
|
|
74
|
+
type: Array as PropType<string[]>,
|
|
75
|
+
default: () => [],
|
|
76
|
+
},
|
|
77
|
+
theme: {
|
|
78
|
+
type: String as PropType<string>,
|
|
79
|
+
default: 'primary',
|
|
80
|
+
validator(value: string) {
|
|
81
|
+
return propValidators.theme.includes(value);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
inputVariant: {
|
|
85
|
+
type: String as PropType<string>,
|
|
86
|
+
default: 'normal',
|
|
87
|
+
validator(value: string) {
|
|
88
|
+
return propValidators.inputVariant.includes(value);
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const slots = useSlots();
|
|
94
|
+
const hasDescriptionSlot = computed(() => slots.description !== undefined);
|
|
95
|
+
const { elementClasses } = useStyleClassPassthrough(props.styleClassPassthrough);
|
|
96
|
+
|
|
97
|
+
const formTheme = computed(() => {
|
|
98
|
+
return props.fieldHasError ? 'error' : props.theme;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const id = useId();
|
|
102
|
+
const errorId = `${name}-error-message`;
|
|
103
|
+
const ariaDescribedby = computed(() => {
|
|
104
|
+
const ariaDescribedbyId = hasDescriptionSlot.value ? `${id}-description` : undefined;
|
|
105
|
+
return props.fieldHasError ? errorId : ariaDescribedbyId;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const modelValue = defineModel({ required: true });
|
|
109
|
+
const isDirty = defineModel('isDirty');
|
|
110
|
+
const isActive = defineModel('isActive');
|
|
111
|
+
const fieldData = defineModel('fieldData') as Ref<IFormMultipleOptions>;
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<style lang="css">
|
|
115
|
+
.input-select-fieldset {
|
|
116
|
+
--_input-select-fieldset-underline-color: transparent;
|
|
117
|
+
margin: 0;
|
|
118
|
+
padding: 0;
|
|
119
|
+
border: 0;
|
|
120
|
+
|
|
121
|
+
border-bottom-right-radius: var(--form-input-border-radius);
|
|
122
|
+
border-bottom-left-radius: var(--form-input-border-radius);
|
|
123
|
+
border-bottom: var(--form-element-border-width-underlined) solid var(--_input-select-fieldset-underline-color);
|
|
124
|
+
|
|
125
|
+
&.underlined {
|
|
126
|
+
--_input-select-fieldset-underline-color: var(--theme-form-input-border);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* &.error {
|
|
130
|
+
border-bottom: var(--form-element-border-width-underlined) solid var(--theme-form-input-border);
|
|
131
|
+
} */
|
|
132
|
+
|
|
133
|
+
legend {
|
|
134
|
+
font-family: var(--font-family);
|
|
135
|
+
font-size: 1.6rem;
|
|
136
|
+
font-weight: 500;
|
|
137
|
+
|
|
138
|
+
&.has-description {
|
|
139
|
+
margin-bottom: 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.label-description {
|
|
144
|
+
font-family: var(--font-family);
|
|
145
|
+
font-size: 1.6rem;
|
|
146
|
+
margin-top: 1.2rem;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.input-select {
|
|
150
|
+
&,
|
|
151
|
+
&::picker(select) {
|
|
152
|
+
appearance: base-select;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
&::picker(select) {
|
|
156
|
+
transition: display allow-discrete 0.5s, opacity 0.5s, overlay 0.5s allow-discrete;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
&:not(:open)::picker(select) {
|
|
160
|
+
opacity: 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
&:open::picker(select) {
|
|
164
|
+
opacity: 1;
|
|
165
|
+
|
|
166
|
+
@starting-style {
|
|
167
|
+
opacity: 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.input-select {
|
|
173
|
+
--_input-select-border: var(--form-element-border-width) solid var(--theme-form-input-border);
|
|
174
|
+
--_input-select-border-radius: var(--form-input-border-radius);
|
|
175
|
+
--_input-select-outline-color: var(--theme-form-input-outline);
|
|
176
|
+
--_input-select-outline: var(--form-element-outline-width) solid var(--_input-select-outline-color);
|
|
177
|
+
|
|
178
|
+
--_input-select-box-shadow: var(--_focus-box-shadow);
|
|
179
|
+
--_focus-box-shadow: var(--box-shadow-off);
|
|
180
|
+
|
|
181
|
+
--_input-select-text-color: var(--theme-form-input-text-color-normal);
|
|
182
|
+
--_input-select-text-font-size: var(--step-2);
|
|
183
|
+
--_input-select-line-height: 1.5;
|
|
184
|
+
|
|
185
|
+
--_input-select-background-color: var(--theme-form-input-bg-normal);
|
|
186
|
+
|
|
187
|
+
/* Underlined vars */
|
|
188
|
+
--_input-select-border-underlined: var(--form-element-border-width-underlined) solid var(--theme-form-input-border);
|
|
189
|
+
--_input-select-underlined-border-radius-top-left: 0;
|
|
190
|
+
--_input-select-underlined-border-radius-top-right: 0;
|
|
191
|
+
--_input-select-underlined-border-radius-bottom-left: 4px;
|
|
192
|
+
--_input-select-underlined-border-radius-bottom-right: 4px;
|
|
193
|
+
|
|
194
|
+
/* Placeholder vars */
|
|
195
|
+
--_placeholder-text-color: var(--theme-form-input-text-label-color-normal);
|
|
196
|
+
--_placeholder-text-margin-block: 0.8rem;
|
|
197
|
+
--_placeholder-text-size: var(--step-2);
|
|
198
|
+
--_placeholder-text-weight: normal;
|
|
199
|
+
--_placeholder-text-line-height: 1.5;
|
|
200
|
+
--_placeholder-text-background-color: var(--_input-text-with-label-background-color);
|
|
201
|
+
|
|
202
|
+
background-color: var(--_input-select-background-color);
|
|
203
|
+
|
|
204
|
+
border-radius: var(--_input-select-border-radius);
|
|
205
|
+
border: var(--_input-select-border);
|
|
206
|
+
outline: var(--_input-select-outline);
|
|
207
|
+
|
|
208
|
+
color: var(--_input-select-text-color);
|
|
209
|
+
font-size: var(--_input-select-text-font-size);
|
|
210
|
+
line-height: var(--_input-select-line-height);
|
|
211
|
+
|
|
212
|
+
padding-block-start: calc(var(--form-element-padding-block-start) - 2px);
|
|
213
|
+
padding-block-end: calc(var(--form-element-padding-block-start) - 3px);
|
|
214
|
+
|
|
215
|
+
min-width: 100%;
|
|
216
|
+
|
|
217
|
+
&:focus-visible {
|
|
218
|
+
--_input-select-box-shadow: var(--box-shadow-on);
|
|
219
|
+
--_input-select-outline: var(--form-element-outline-width) solid hsl(from var(--theme-form-input-outline-focus) h s 90%);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
&.underlined {
|
|
223
|
+
--_input-select-text-color: var(--theme-form-input-text-label-color-underlined);
|
|
224
|
+
--_input-select-background-color: color-mix(in srgb, currentColor 5%, transparent);
|
|
225
|
+
/* --_input-select-background-color: var(--theme-form-input-bg-underlined); */
|
|
226
|
+
--_input-select-outline-color: transparent;
|
|
227
|
+
--_input-select-text-color: var(--_input-text-core-color);
|
|
228
|
+
|
|
229
|
+
border-color: transparent;
|
|
230
|
+
/* border-bottom: var(--_input-select-border-underlined);
|
|
231
|
+
border-top-left-radius: var(--_input-select-underlined-border-radius-top-left);
|
|
232
|
+
border-top-right-radius: var(--_input-select-underlined-border-radius-top-right);
|
|
233
|
+
border-bottom-left-radius: var(--_input-select-underlined-border-radius-bottom-left);
|
|
234
|
+
border-bottom-right-radius: var(--_input-select-underlined-border-radius-bottom-right);
|
|
235
|
+
|
|
236
|
+
&.error {
|
|
237
|
+
--_input-select-border-underlined: var(--form-element-border-width-underlined) solid transparent;
|
|
238
|
+
} */
|
|
239
|
+
|
|
240
|
+
&.active,
|
|
241
|
+
&.dirty {
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
&.outlined {
|
|
246
|
+
&.active,
|
|
247
|
+
&.dirty {
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
&:not(.normal) {
|
|
252
|
+
&.active,
|
|
253
|
+
&.dirty {
|
|
254
|
+
}
|
|
255
|
+
&:focus-within {
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/*
|
|
260
|
+
* Apply generic styles
|
|
261
|
+
**/
|
|
262
|
+
|
|
263
|
+
&.underlined {
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
&.outlined {
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
&:not(.normal) {
|
|
270
|
+
&:focus-visible {
|
|
271
|
+
/* --_input-select-box-shadow: var(--box-shadow-on);
|
|
272
|
+
--_input-select-outline: var(--form-element-outline-width) solid hsl(from var(--theme-form-input-outline-focus) h s 90%); */
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.input-select-option {
|
|
277
|
+
color: var(--_placeholder-text-color);
|
|
278
|
+
margin-block: var(--_placeholder-text-margin-block);
|
|
279
|
+
font-size: var(--_placeholder-text-size);
|
|
280
|
+
font-weight: var(--_placeholder-text-weight);
|
|
281
|
+
line-height: var(--_placeholder-text-line-height);
|
|
282
|
+
|
|
283
|
+
&.placeholder {
|
|
284
|
+
/* background-color: var(--_placeholder-text-background-color); */
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
</style>
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="input-text-wrapper"
|
|
4
|
+
:data-form-theme="formTheme"
|
|
5
|
+
:data-size="size"
|
|
6
|
+
:class="[inputVariant, { dirty: isDirty }, { active: isActive }, { error: fieldHasError }, { 'has-left-slot': hasLeftSlot }, { 'has-right-slot': hasRightSlot }]"
|
|
7
|
+
>
|
|
8
|
+
<span v-if="hasLeftSlot" class="slot left-slot">
|
|
9
|
+
<slot name="left"></slot>
|
|
10
|
+
</span>
|
|
11
|
+
|
|
12
|
+
<input
|
|
13
|
+
:type
|
|
14
|
+
:placeholder
|
|
15
|
+
:id
|
|
16
|
+
:name
|
|
17
|
+
:required
|
|
18
|
+
:maxlength
|
|
19
|
+
:class="['input-text-core', elementClasses, { dirty: isDirty }, { active: isActive }]"
|
|
20
|
+
v-model="modelValue"
|
|
21
|
+
ref="inputField"
|
|
22
|
+
:aria-invalid="fieldHasError"
|
|
23
|
+
:aria-describedby
|
|
24
|
+
:pattern="inputPattern"
|
|
25
|
+
:inputmode
|
|
26
|
+
@focusin="updateFocus(true)"
|
|
27
|
+
@focusout="updateFocus(false)"
|
|
28
|
+
/>
|
|
29
|
+
|
|
30
|
+
<span v-if="hasRightSlot" class="slot right-slot">
|
|
31
|
+
<slot name="right"></slot>
|
|
32
|
+
</span>
|
|
33
|
+
</div>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
import propValidators from '../c12/prop-validators';
|
|
38
|
+
|
|
39
|
+
const props = defineProps({
|
|
40
|
+
type: {
|
|
41
|
+
type: String as PropType<'text' | 'email' | 'password' | 'number' | 'tel' | 'url'>,
|
|
42
|
+
// type: String,
|
|
43
|
+
default: 'text',
|
|
44
|
+
validator(value: string) {
|
|
45
|
+
return propValidators.inputTypesText.includes(value);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
inputmode: {
|
|
49
|
+
type: String as PropType<'text' | 'email' | 'tel' | 'url' | 'search' | 'numeric' | 'none' | 'decimal'>,
|
|
50
|
+
default: 'text',
|
|
51
|
+
validator(value: string) {
|
|
52
|
+
return propValidators.inputMode.includes(value);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
maxlength: {
|
|
56
|
+
type: Number,
|
|
57
|
+
default: 255,
|
|
58
|
+
},
|
|
59
|
+
id: {
|
|
60
|
+
type: String,
|
|
61
|
+
required: true,
|
|
62
|
+
},
|
|
63
|
+
name: {
|
|
64
|
+
type: String,
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
required: {
|
|
68
|
+
type: Boolean,
|
|
69
|
+
default: false,
|
|
70
|
+
},
|
|
71
|
+
placeholder: {
|
|
72
|
+
type: String,
|
|
73
|
+
default: '',
|
|
74
|
+
},
|
|
75
|
+
fieldHasError: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: false,
|
|
78
|
+
},
|
|
79
|
+
styleClassPassthrough: {
|
|
80
|
+
type: Array as PropType<string[]>,
|
|
81
|
+
default: () => [],
|
|
82
|
+
},
|
|
83
|
+
theme: {
|
|
84
|
+
type: String as PropType<string>,
|
|
85
|
+
default: 'primary',
|
|
86
|
+
validator(value: string) {
|
|
87
|
+
return propValidators.theme.includes(value);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
ariaDescribedby: {
|
|
91
|
+
type: String,
|
|
92
|
+
default: null,
|
|
93
|
+
},
|
|
94
|
+
size: {
|
|
95
|
+
type: String as PropType<string>,
|
|
96
|
+
default: 'normal',
|
|
97
|
+
validator(value: string) {
|
|
98
|
+
return propValidators.size.includes(value);
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
inputVariant: {
|
|
102
|
+
type: String as PropType<string>,
|
|
103
|
+
default: 'normal',
|
|
104
|
+
validator(value: string) {
|
|
105
|
+
return propValidators.inputVariant.includes(value);
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const slots = useSlots();
|
|
111
|
+
const hasLeftSlot = computed(() => slots.left !== undefined);
|
|
112
|
+
const hasRightSlot = computed(() => slots.right !== undefined);
|
|
113
|
+
|
|
114
|
+
const formTheme = computed(() => {
|
|
115
|
+
return props.fieldHasError ? 'error' : props.theme;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const modelValue = defineModel();
|
|
119
|
+
const isDirty = defineModel('isDirty');
|
|
120
|
+
const isActive = defineModel('isActive');
|
|
121
|
+
|
|
122
|
+
const inputPattern = computed(() => {
|
|
123
|
+
return props.inputmode === 'numeric' ? '[0-9]+' : undefined;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const updateFocus = (isFocused: boolean) => {
|
|
127
|
+
isActive.value = isFocused;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const inputField = ref<HTMLInputElement | null>(null);
|
|
131
|
+
|
|
132
|
+
const { elementClasses } = useStyleClassPassthrough(props.styleClassPassthrough);
|
|
133
|
+
|
|
134
|
+
// TODO: Move this to a utility function to allow removeEventListener on unmounted
|
|
135
|
+
// Leaving like this could lead to memory leaks
|
|
136
|
+
const validateInput = () => {
|
|
137
|
+
if (inputField.value !== null) {
|
|
138
|
+
inputField.value.addEventListener('beforeinput', (event: any) => {
|
|
139
|
+
let beforeValue = modelValue.value;
|
|
140
|
+
event.target.addEventListener(
|
|
141
|
+
'input',
|
|
142
|
+
() => {
|
|
143
|
+
if (inputField.value !== null && inputField.value.validity.patternMismatch) {
|
|
144
|
+
inputField.value.value = beforeValue as string;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{ once: true }
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
onMounted(() => {
|
|
154
|
+
if (props.inputmode === 'numeric') validateInput();
|
|
155
|
+
});
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<style lang="css">
|
|
159
|
+
.input-text-wrapper {
|
|
160
|
+
--_focus-box-shadow: var(--box-shadow-off);
|
|
161
|
+
--_input-text-core-color: var(--theme-form-input-text-color-normal);
|
|
162
|
+
|
|
163
|
+
--_input-text-wrapper-background-color: var(--theme-form-input-bg-normal);
|
|
164
|
+
|
|
165
|
+
--_input-text-wrapper-border: var(--form-element-border-width) solid var(--theme-form-input-border);
|
|
166
|
+
--_input-text-wrapper-border-radius: var(--form-input-border-radius);
|
|
167
|
+
|
|
168
|
+
--_input-text-wrapper-outline: var(--form-element-outline-width) solid var(--theme-form-input-outline);
|
|
169
|
+
--_input-text-wrapper-opacity: 1;
|
|
170
|
+
--_input-text-wrapper-box-shadow: var(--_focus-box-shadow);
|
|
171
|
+
--_input-text-wrapper-margin-inline: 0;
|
|
172
|
+
--_input-text-wrapper-padding-block: 0;
|
|
173
|
+
|
|
174
|
+
&.underlined {
|
|
175
|
+
--_input-text-core-color: var(--theme-form-input-text-color-underlined);
|
|
176
|
+
--_input-text-wrapper-background-color: transparent;
|
|
177
|
+
--_input-text-wrapper-padding-block: 0.5rem;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
&.outlined {
|
|
181
|
+
--_input-text-wrapper-margin-inline: 1px;
|
|
182
|
+
--_input-text-wrapper-background-color: var(--theme-form-input-bg-outlined);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&.normal {
|
|
186
|
+
&:focus-within {
|
|
187
|
+
--_input-text-wrapper-box-shadow: var(--box-shadow-on);
|
|
188
|
+
--_input-text-wrapper-outline: var(--form-element-outline-width) solid hsl(from var(--theme-form-input-outline-focus) h s 90%);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
&:not(.normal) {
|
|
193
|
+
--_input-text-wrapper-border: none;
|
|
194
|
+
--_input-text-wrapper-box-shadow: none;
|
|
195
|
+
--_input-text-wrapper-outline: none;
|
|
196
|
+
--_input-text-wrapper-opacity: 0;
|
|
197
|
+
|
|
198
|
+
&:focus {
|
|
199
|
+
--_input-text-wrapper-border: none;
|
|
200
|
+
--_input-text-wrapper-box-shadow: none;
|
|
201
|
+
--_input-text-wrapper-outline: none;
|
|
202
|
+
--_input-text-wrapper-background-color: transparent;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&:focus-within {
|
|
206
|
+
--_input-text-wrapper-border: none;
|
|
207
|
+
--_input-text-wrapper-box-shadow: none;
|
|
208
|
+
--_input-text-wrapper-outline: none;
|
|
209
|
+
--_input-text-wrapper-background-color: transparent;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
&.active,
|
|
213
|
+
&.dirty {
|
|
214
|
+
--_input-text-wrapper-border: none;
|
|
215
|
+
--_input-text-wrapper-box-shadow: none;
|
|
216
|
+
--_input-text-wrapper-outline: none;
|
|
217
|
+
--_input-text-wrapper-background-color: transparent;
|
|
218
|
+
|
|
219
|
+
--_input-text-wrapper-opacity: 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
display: flex;
|
|
224
|
+
align-items: center;
|
|
225
|
+
|
|
226
|
+
background-color: var(--_input-text-wrapper-background-color);
|
|
227
|
+
border-radius: var(--_input-text-wrapper-border-radius);
|
|
228
|
+
border: var(--_input-text-wrapper-border);
|
|
229
|
+
outline: var(--_input-text-wrapper-outline);
|
|
230
|
+
box-shadow: var(--_input-text-wrapper-box-shadow);
|
|
231
|
+
opacity: var(--_input-text-wrapper-opacity);
|
|
232
|
+
|
|
233
|
+
margin-inline: var(--_input-text-wrapper-margin-inline);
|
|
234
|
+
padding-block: var(--_input-text-wrapper-padding-block);
|
|
235
|
+
|
|
236
|
+
&:not(.normal) {
|
|
237
|
+
transition: opacity 0.2s ease-in-out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
&:not(:has(.input-button-core)) {
|
|
241
|
+
.slot {
|
|
242
|
+
display: inline-block;
|
|
243
|
+
|
|
244
|
+
.icon {
|
|
245
|
+
color: var(--_input-text-core-color);
|
|
246
|
+
aspect-ratio: 1;
|
|
247
|
+
height: var(--form-icon-size);
|
|
248
|
+
width: var(--form-icon-size);
|
|
249
|
+
margin: 0 !important;
|
|
250
|
+
padding: 0 !important;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
&.has-left-slot {
|
|
256
|
+
.left-slot {
|
|
257
|
+
display: flex;
|
|
258
|
+
align-items: center;
|
|
259
|
+
margin-inline-start: 1rem;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
&.has-right-slot {
|
|
264
|
+
.right-slot {
|
|
265
|
+
display: flex;
|
|
266
|
+
align-items: center;
|
|
267
|
+
margin-inline-end: 1rem;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.input-text-core {
|
|
272
|
+
background-color: transparent;
|
|
273
|
+
border: none;
|
|
274
|
+
outline: none;
|
|
275
|
+
box-shadow: none;
|
|
276
|
+
flex-grow: 1;
|
|
277
|
+
|
|
278
|
+
color: var(--_input-text-core-color);
|
|
279
|
+
font-family: var(--font-family);
|
|
280
|
+
font-size: var(--form-element-font-size);
|
|
281
|
+
line-height: var(--form-element-line-height);
|
|
282
|
+
|
|
283
|
+
padding-inline: var(--form-text-padding-inline);
|
|
284
|
+
padding-block-start: var(--form-element-padding-block-start);
|
|
285
|
+
padding-block-end: var(--form-element-padding-block-end);
|
|
286
|
+
|
|
287
|
+
&::placeholder,
|
|
288
|
+
&::-webkit-input-placeholder {
|
|
289
|
+
font-family: var(--font-family);
|
|
290
|
+
font-size: var(--form-element-font-size);
|
|
291
|
+
font-style: italic;
|
|
292
|
+
font-weight: 400;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
&:has(.has-left-button),
|
|
297
|
+
&:has(.has-right-button) {
|
|
298
|
+
.slot {
|
|
299
|
+
.input-button-core {
|
|
300
|
+
border: initial;
|
|
301
|
+
border-radius: 0;
|
|
302
|
+
outline: initial;
|
|
303
|
+
box-shadow: unset;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.left-slot {
|
|
308
|
+
margin-inline-end: 0;
|
|
309
|
+
border-right: 2px solid var(--theme-btn-bg-hover);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.right-slot {
|
|
313
|
+
margin-inline-end: 0;
|
|
314
|
+
border-left: 2px solid var(--theme-btn-bg-hover);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
input:autofill,
|
|
320
|
+
input:-internal-autofill-selected,
|
|
321
|
+
input:-webkit-autofill-strong-password,
|
|
322
|
+
input:-webkit-autofill-strong-password-viewable,
|
|
323
|
+
input:-webkit-autofill-and-obscured {
|
|
324
|
+
background-color: var(--theme-form-input-bg-normal) !important;
|
|
325
|
+
background-image: none !important;
|
|
326
|
+
color: var(--_input-text-core-color) !important;
|
|
327
|
+
-webkit-box-shadow: 0 0 0rem 1000px var(--theme-form-input-bg-normal) inset;
|
|
328
|
+
-webkit-text-fill-color: var(--_input-text-core-color);
|
|
329
|
+
transition: background-color 5000s ease-in-out 0s;
|
|
330
|
+
}
|
|
331
|
+
</style>
|