srcdev-nuxt-forms 4.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.
|
@@ -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>
|
package/package.json
CHANGED