srcdev-nuxt-forms 0.1.0 → 0.2.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/LICENSE +21 -0
- package/assets/styles/forms/index.css +1 -0
- package/assets/styles/forms/themes/_primary.css +2 -0
- package/assets/styles/forms/themes/_secondary.css +2 -0
- package/assets/styles/forms/utils/_a11y.css +5 -0
- package/assets/styles/forms/utils/index.css +1 -0
- package/assets/styles/forms/variables/_theme.css +11 -17
- package/assets/styles/variables/colors/_gray.css +1 -0
- package/components/forms/c12/prop-validators/index.ts +8 -20
- package/components/forms/c12/utils.ts +14 -0
- package/components/forms/c12/validation-patterns/en.json +12 -0
- package/components/forms/form-errors/InputError.vue +132 -0
- package/components/forms/input-button/InputButtonCore.vue +11 -8
- package/components/forms/input-button/variants/InputButtonConfirm.vue +1 -1
- package/components/forms/input-button/variants/InputButtonSubmit.vue +1 -1
- package/components/forms/input-checkbox/InputCheckboxCore.vue +407 -0
- package/components/forms/input-checkbox/InputCheckboxWithLabel.vue +125 -0
- package/components/forms/input-checkbox/variants/MultipleCheckboxes.vue +194 -0
- package/components/forms/input-checkbox/variants/SingleCheckbox.vue +157 -0
- package/components/forms/input-radio/InputRadioCore.vue +226 -0
- package/components/forms/input-radio/InputRadioWithLabel.vue +118 -0
- package/components/forms/input-radio/variants/MultipleRadio.vue +183 -0
- package/components/forms/input-radio/variants/SingleRadio.vue +131 -0
- package/components/forms/input-range/InputRangeCore.vue +171 -0
- package/components/forms/input-range/variants/InputRangeDefault.vue +131 -0
- package/components/forms/input-text/InputTextCore.vue +61 -31
- package/components/forms/input-text/variants/material/InputPasswordMaterial.vue +27 -1
- package/components/forms/input-text/variants/material/InputTextMaterial.vue +1 -8
- package/components/forms/input-text/variants/material/InputTextMaterialCore.vue +83 -28
- package/components/forms/input-textarea/InputTextareaCore.vue +170 -0
- package/components/forms/input-textarea/variants/material/InputTextareaMaterial.vue +75 -0
- package/components/forms/input-textarea/variants/material/InputTextareaMaterialCore.vue +290 -0
- package/components/ui/content-grid/ContentGrid.vue +85 -0
- package/composables/useErrorMessages.ts +17 -5
- package/composables/useFormControl.ts +147 -37
- package/layouts/default.vue +7 -13
- package/nuxt.config.ts +22 -0
- package/package.json +9 -8
- package/pages/forms/examples/buttons/index.vue +14 -13
- package/pages/forms/examples/material/text-fields.vue +320 -84
- package/pages/limit-text.vue +43 -0
- package/server/api/places/list.get.ts +23 -0
- package/server/api/textFields.post.ts +37 -0
- package/server/api/utils/index.get.ts +20 -0
- package/server/data/places/cities.json +37 -0
- package/server/data/places/countries.json +55 -0
- package/server/data/utils/title.json +49 -0
- package/types/types.forms.ts +33 -3
- package/types/types.places.ts +8 -0
- package/pages/forms/examples/material/text-fields-compact.vue +0 -136
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<fieldset class="multiple-radio-fieldset" :class="[`theme-${theme}`, { error: fieldHasError }]" :aria-required="required" :aria-invalid="fieldHasError" role="radiogroup">
|
|
3
|
+
<legend :class="[{ 'has-description': hasDescription }]">
|
|
4
|
+
{{ legend }}
|
|
5
|
+
<span v-if="required"> (Required)</span>
|
|
6
|
+
</legend>
|
|
7
|
+
<template v-if="hasDescription">
|
|
8
|
+
<slot name="description"></slot>
|
|
9
|
+
</template>
|
|
10
|
+
<InputError :errorMessaging :fieldHasError :id="name" :isDetached="true" />
|
|
11
|
+
<div class="multiple-radio-items" :class="[optionsLayout]">
|
|
12
|
+
<template v-for="item in fieldData.data" :key="item.id">
|
|
13
|
+
<InputRadioWithLabel
|
|
14
|
+
:id="item.value"
|
|
15
|
+
:name
|
|
16
|
+
:required
|
|
17
|
+
:c12="{
|
|
18
|
+
label: item.label,
|
|
19
|
+
placeholder: 'eg. Type something here',
|
|
20
|
+
errorMessage: 'Please accept our terms and conditions',
|
|
21
|
+
}"
|
|
22
|
+
v-model="modelValue"
|
|
23
|
+
:true-value="item.value"
|
|
24
|
+
:theme
|
|
25
|
+
:size
|
|
26
|
+
:radioAppearance
|
|
27
|
+
/>
|
|
28
|
+
</template>
|
|
29
|
+
</div>
|
|
30
|
+
</fieldset>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import propValidators from '../../c12/prop-validators';
|
|
35
|
+
import type { IOptionsConfig, IFormMultipleOptions } from '@/types/types.forms';
|
|
36
|
+
|
|
37
|
+
import type { InpuTextC12, IFormFieldC12, IFormData } from '@/types/types.forms';
|
|
38
|
+
|
|
39
|
+
const props = defineProps({
|
|
40
|
+
name: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
legend: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
required: {
|
|
49
|
+
type: Boolean,
|
|
50
|
+
value: false,
|
|
51
|
+
},
|
|
52
|
+
c12: {
|
|
53
|
+
type: Object as PropType<InpuTextC12>,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
multipleOptions: {
|
|
57
|
+
type: Boolean,
|
|
58
|
+
default: false,
|
|
59
|
+
},
|
|
60
|
+
styleClassPassthrough: {
|
|
61
|
+
type: String,
|
|
62
|
+
default: '',
|
|
63
|
+
},
|
|
64
|
+
theme: {
|
|
65
|
+
type: String as PropType<string>,
|
|
66
|
+
default: 'primary',
|
|
67
|
+
validator(value: string) {
|
|
68
|
+
return propValidators.theme.includes(value);
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
size: {
|
|
72
|
+
type: String as PropType<string>,
|
|
73
|
+
default: 'medium',
|
|
74
|
+
validator(value: string) {
|
|
75
|
+
return propValidators.size.includes(value);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
optionsLayout: {
|
|
79
|
+
type: String as PropType<string>,
|
|
80
|
+
default: 'equal-widths',
|
|
81
|
+
validator(value: string) {
|
|
82
|
+
return propValidators.optionsLayout.includes(value);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
equalCols: {
|
|
86
|
+
type: Boolean,
|
|
87
|
+
default: true,
|
|
88
|
+
},
|
|
89
|
+
radioAppearance: {
|
|
90
|
+
type: String as PropType<string>,
|
|
91
|
+
default: null,
|
|
92
|
+
validator(value: string) {
|
|
93
|
+
return propValidators.radioAppearance.includes(value);
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const slots = useSlots();
|
|
99
|
+
const hasDescription = computed(() => slots.description !== undefined);
|
|
100
|
+
|
|
101
|
+
const modelValue = defineModel() as Ref<IFormData>;
|
|
102
|
+
const fieldData = defineModel('fieldData') as Ref<IFormMultipleOptions>;
|
|
103
|
+
|
|
104
|
+
const errorMessaging = computed(() => {
|
|
105
|
+
if (
|
|
106
|
+
typeof modelValue.value!.formFieldsC12[props.name] !== 'undefined' &&
|
|
107
|
+
modelValue.value!.formFieldsC12[props.name].useCustomError &&
|
|
108
|
+
modelValue.value.data[props.name] === modelValue.value.formFieldsC12[props.name].previousValue
|
|
109
|
+
) {
|
|
110
|
+
return modelValue.value.formFieldsC12[props.name]?.customErrors || [];
|
|
111
|
+
} else {
|
|
112
|
+
return props.c12.errorMessage;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// const isArray = Array.isArray(modelValue.value.data[props.name]);
|
|
117
|
+
// const formFieldC12 = <IFormFieldC12>{
|
|
118
|
+
// label: props.c12.label,
|
|
119
|
+
// placeholder: props.c12.placeholder,
|
|
120
|
+
// errorMessage: props.c12.errorMessage,
|
|
121
|
+
// useCustomError: false,
|
|
122
|
+
// customErrors: {},
|
|
123
|
+
// isValid: false,
|
|
124
|
+
// isDirty: false,
|
|
125
|
+
// type: isArray ? 'array' : 'string',
|
|
126
|
+
// previousValue: null,
|
|
127
|
+
// };
|
|
128
|
+
// modelValue.value.formFieldsC12[props.name] = formFieldC12;
|
|
129
|
+
|
|
130
|
+
const fieldHasError = computed(() => {
|
|
131
|
+
return modelValue.value!.submitAttempted && !modelValue.value!.formFieldsC12[props.name].isValid;
|
|
132
|
+
});
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<style lang="css">
|
|
136
|
+
.multiple-radio-fieldset {
|
|
137
|
+
--_form-theme: var(--theme-form-primary);
|
|
138
|
+
|
|
139
|
+
margin: 0;
|
|
140
|
+
padding: 0;
|
|
141
|
+
border: 0;
|
|
142
|
+
|
|
143
|
+
&.theme-secondary {
|
|
144
|
+
--_form-theme: var(--theme-form-secondary);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
&.error {
|
|
148
|
+
--_form-theme: var(--theme-error);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
legend {
|
|
152
|
+
color: var(--_form-theme);
|
|
153
|
+
|
|
154
|
+
font-family: var(--font-family);
|
|
155
|
+
font-size: 18px;
|
|
156
|
+
font-weight: 500;
|
|
157
|
+
|
|
158
|
+
&.has-description {
|
|
159
|
+
margin-bottom: 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.multiple-radio-items {
|
|
165
|
+
display: flex;
|
|
166
|
+
gap: 18px;
|
|
167
|
+
margin-top: 12px;
|
|
168
|
+
|
|
169
|
+
&.inline {
|
|
170
|
+
flex-direction: row;
|
|
171
|
+
flex-wrap: wrap;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
&.block {
|
|
175
|
+
flex-direction: column;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
&.equal-widths {
|
|
179
|
+
display: grid;
|
|
180
|
+
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
</style>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<fieldset class="single-radio-fieldset" :class="[`theme-${theme}`, { error: fieldHasError }]">
|
|
3
|
+
<legend :class="[{ 'has-description': hasDescription }]">{{ legend }}</legend>
|
|
4
|
+
<template v-if="hasDescription">
|
|
5
|
+
<slot name="description"></slot>
|
|
6
|
+
</template>
|
|
7
|
+
<InputError :errorMessaging :fieldHasError :id="name" :isDetached="true" />
|
|
8
|
+
<InputRadioWithLabel :id :name :required :c12 v-model="modelValue" :theme :size :radioAppearance />
|
|
9
|
+
</fieldset>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import propValidators from '../../c12/prop-validators';
|
|
14
|
+
|
|
15
|
+
import type { InpuTextC12, IFormFieldC12, IFormData } from '@/types/types.forms';
|
|
16
|
+
// import { validationConfig } from '@/components/forms/c12/validation-patterns';
|
|
17
|
+
|
|
18
|
+
const props = defineProps({
|
|
19
|
+
id: {
|
|
20
|
+
// type: String as PropType<string>,
|
|
21
|
+
type: String,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
name: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
legend: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
required: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
value: false,
|
|
35
|
+
},
|
|
36
|
+
c12: {
|
|
37
|
+
type: Object as PropType<InpuTextC12>,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
trueValue: {
|
|
41
|
+
type: [String, Number, Boolean],
|
|
42
|
+
default: true,
|
|
43
|
+
},
|
|
44
|
+
falseValue: {
|
|
45
|
+
type: [String, Number, Boolean],
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
// multipleOptions: {
|
|
49
|
+
// type: Boolean,
|
|
50
|
+
// default: false,
|
|
51
|
+
// },
|
|
52
|
+
styleClassPassthrough: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: '',
|
|
55
|
+
},
|
|
56
|
+
theme: {
|
|
57
|
+
type: String as PropType<string>,
|
|
58
|
+
default: 'primary',
|
|
59
|
+
validator(value: string) {
|
|
60
|
+
return propValidators.theme.includes(value);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
size: {
|
|
64
|
+
type: String as PropType<string>,
|
|
65
|
+
default: 'medium',
|
|
66
|
+
validator(value: string) {
|
|
67
|
+
return propValidators.size.includes(value);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
radioAppearance: {
|
|
71
|
+
type: String as PropType<string>,
|
|
72
|
+
default: null,
|
|
73
|
+
validator(value: string) {
|
|
74
|
+
return propValidators.radioAppearance.includes(value);
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const slots = useSlots();
|
|
80
|
+
const hasDescription = computed(() => slots.description !== undefined);
|
|
81
|
+
|
|
82
|
+
const modelValue = defineModel() as Ref<IFormData>;
|
|
83
|
+
const name = computed(() => {
|
|
84
|
+
return props.name !== null ? props.name : props.id;
|
|
85
|
+
});
|
|
86
|
+
const fieldHasError = computed(() => {
|
|
87
|
+
return modelValue.value!.submitAttempted && !modelValue.value!.formFieldsC12[props.name].isValid;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const errorMessaging = computed(() => {
|
|
91
|
+
if (
|
|
92
|
+
typeof modelValue.value!.formFieldsC12[props.name] !== 'undefined' &&
|
|
93
|
+
modelValue.value!.formFieldsC12[props.name].useCustomError &&
|
|
94
|
+
modelValue.value.data[props.name] === modelValue.value.formFieldsC12[props.name].previousValue
|
|
95
|
+
) {
|
|
96
|
+
return modelValue.value.formFieldsC12[props.name]?.customErrors || [];
|
|
97
|
+
} else {
|
|
98
|
+
return props.c12.errorMessage;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<style lang="css">
|
|
104
|
+
.single-radio-fieldset {
|
|
105
|
+
--_form-theme: var(--theme-form-primary);
|
|
106
|
+
|
|
107
|
+
margin: 0;
|
|
108
|
+
padding: 0;
|
|
109
|
+
border: 0;
|
|
110
|
+
|
|
111
|
+
&.theme-secondary {
|
|
112
|
+
--_form-theme: var(--theme-form-secondary);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&.error {
|
|
116
|
+
--_form-theme: var(--theme-error);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
legend {
|
|
120
|
+
color: var(--_form-theme);
|
|
121
|
+
font-family: var(--font-family);
|
|
122
|
+
font-size: 18px;
|
|
123
|
+
font-weight: 500;
|
|
124
|
+
margin-bottom: 12px;
|
|
125
|
+
|
|
126
|
+
&.has-description {
|
|
127
|
+
margin-bottom: 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
</style>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="input-range-wrapper">
|
|
3
|
+
<div v-if="hasLeftContent" class="slot left">
|
|
4
|
+
<slot name="left"></slot>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<input
|
|
8
|
+
type="range"
|
|
9
|
+
:id
|
|
10
|
+
:name
|
|
11
|
+
:required
|
|
12
|
+
:min
|
|
13
|
+
:max
|
|
14
|
+
:step
|
|
15
|
+
:class="['input-range-core', `input-range--${theme}`, `input-range--${size}`, `input-range--${weight}`, styleClassPassthrough]"
|
|
16
|
+
v-model="modelValue.data[name]"
|
|
17
|
+
ref="inputField"
|
|
18
|
+
/>
|
|
19
|
+
<div v-if="hasRightContent" class="slot right">
|
|
20
|
+
<slot name="right"></slot>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script setup lang="ts">
|
|
26
|
+
import propValidators from '../c12/prop-validators';
|
|
27
|
+
|
|
28
|
+
import type { InpuTextC12, IFormFieldC12, IFormData } from '@/types/types.forms';
|
|
29
|
+
const props = defineProps({
|
|
30
|
+
id: {
|
|
31
|
+
// type: String as PropType<string>,
|
|
32
|
+
type: String,
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
name: {
|
|
36
|
+
type: String,
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
required: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
value: false,
|
|
42
|
+
},
|
|
43
|
+
min: {
|
|
44
|
+
type: Number,
|
|
45
|
+
default: 0,
|
|
46
|
+
},
|
|
47
|
+
max: {
|
|
48
|
+
type: Number,
|
|
49
|
+
default: 100,
|
|
50
|
+
},
|
|
51
|
+
step: {
|
|
52
|
+
type: Number,
|
|
53
|
+
default: 1,
|
|
54
|
+
},
|
|
55
|
+
c12: {
|
|
56
|
+
type: Object as PropType<InpuTextC12>,
|
|
57
|
+
required: true,
|
|
58
|
+
},
|
|
59
|
+
styleClassPassthrough: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: '',
|
|
62
|
+
},
|
|
63
|
+
theme: {
|
|
64
|
+
type: String as PropType<string>,
|
|
65
|
+
default: 'primary',
|
|
66
|
+
validator(value: string) {
|
|
67
|
+
return propValidators.theme.includes(value);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
size: {
|
|
71
|
+
type: String as PropType<string>,
|
|
72
|
+
default: 'medium',
|
|
73
|
+
validator(value: string) {
|
|
74
|
+
return propValidators.size.includes(value);
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
weight: {
|
|
78
|
+
type: String as PropType<string>,
|
|
79
|
+
default: 'wght-400',
|
|
80
|
+
validator(value: string) {
|
|
81
|
+
return propValidators.weight.includes(value);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const slots = useSlots();
|
|
87
|
+
const hasLeftContent = computed(() => slots.left !== undefined);
|
|
88
|
+
const hasRightContent = computed(() => slots.right !== undefined);
|
|
89
|
+
|
|
90
|
+
const modelValue = defineModel() as Ref<IFormData>;
|
|
91
|
+
|
|
92
|
+
const name = computed(() => {
|
|
93
|
+
return props.name !== null ? props.name : props.id;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const inputField = ref<HTMLInputElement | null>(null);
|
|
97
|
+
|
|
98
|
+
const formFieldC12 = <IFormFieldC12>{
|
|
99
|
+
label: props.c12.label,
|
|
100
|
+
placeholder: props.c12.placeholder,
|
|
101
|
+
errorMessage: props.c12.errorMessage,
|
|
102
|
+
useCustomError: false,
|
|
103
|
+
customErrors: {},
|
|
104
|
+
isValid: false,
|
|
105
|
+
isDirty: false,
|
|
106
|
+
type: 'number',
|
|
107
|
+
previousValue: null,
|
|
108
|
+
};
|
|
109
|
+
modelValue.value!.formFieldsC12[name.value] = formFieldC12;
|
|
110
|
+
|
|
111
|
+
const { initFormFieldsC12 } = useFormControl();
|
|
112
|
+
initFormFieldsC12(props.name, formFieldC12);
|
|
113
|
+
|
|
114
|
+
const fieldValue = computed(() => {
|
|
115
|
+
return modelValue.value.data[name.value];
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
watch(fieldValue, () => {
|
|
119
|
+
if (!modelValue.value!.formFieldsC12[name.value].isDirty) {
|
|
120
|
+
modelValue.value!.formFieldsC12[name.value].isDirty = modelValue.value.data[name.value] !== '';
|
|
121
|
+
}
|
|
122
|
+
modelValue.value!.formFieldsC12[name.value].isValid = inputField.value?.validity.valid ?? false;
|
|
123
|
+
modelValue.value!.validityState[name.value] = inputField.value?.validity.valid ?? false;
|
|
124
|
+
|
|
125
|
+
if (modelValue.value!.formFieldsC12[name.value].useCustomError && modelValue.value.data[props.name] === modelValue.value.formFieldsC12[props.name].previousValue) {
|
|
126
|
+
modelValue.value!.validityState[name.value] = false;
|
|
127
|
+
modelValue.value!.formFieldsC12[name.value].isValid = false;
|
|
128
|
+
modelValue.value.displayErrorMessages = true;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const isValid = () => {
|
|
133
|
+
setTimeout(() => {
|
|
134
|
+
modelValue.value!.validityState[name.value] = inputField.value?.validity.valid ?? false;
|
|
135
|
+
modelValue.value!.formFieldsC12[name.value].isValid = inputField.value?.validity.valid ?? false;
|
|
136
|
+
if (!modelValue.value!.formFieldsC12[name.value].isDirty) {
|
|
137
|
+
modelValue.value!.formFieldsC12[name.value].isDirty = modelValue.value.data[name.value] !== '';
|
|
138
|
+
}
|
|
139
|
+
}, 0);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
onMounted(() => {
|
|
143
|
+
isValid();
|
|
144
|
+
});
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<style lang="css">
|
|
148
|
+
.input-range-wrapper {
|
|
149
|
+
--_form-theme: var(--theme-form-primary);
|
|
150
|
+
--_focus-colour: var(--theme-form-primary-focus);
|
|
151
|
+
--_gutter: 12px;
|
|
152
|
+
--_border-width: var(--input-border-width-thin);
|
|
153
|
+
--_border-color: var(--_form-theme);
|
|
154
|
+
--_outline-width: var(--input-outline-width-thin);
|
|
155
|
+
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: space-between;
|
|
159
|
+
gap: 10px;
|
|
160
|
+
|
|
161
|
+
.input-range-core {
|
|
162
|
+
flex-grow: 1;
|
|
163
|
+
height: 24px;
|
|
164
|
+
|
|
165
|
+
&:focus-visible {
|
|
166
|
+
outline: var(--focus-visible-outline);
|
|
167
|
+
box-shadow: var(--focus-visible-box-shadow);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
</style>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="input-range-with-label" :class="[styleClassPassthrough, `theme-${theme}`, { error: fieldHasError }]">
|
|
3
|
+
<label class="input-range-label" :for="id">{{ c12.label }}</label>
|
|
4
|
+
<template v-if="hasDescription">
|
|
5
|
+
<slot name="description"></slot>
|
|
6
|
+
</template>
|
|
7
|
+
<InputRangeCore :id :name :required :c12 v-model="modelValue" :theme :size :weight :min :max :step>
|
|
8
|
+
<template v-if="hasLeftContent" #left>
|
|
9
|
+
<slot name="left"></slot>
|
|
10
|
+
</template>
|
|
11
|
+
<template v-if="hasRightContent" #right>
|
|
12
|
+
<slot name="right"></slot>
|
|
13
|
+
</template>
|
|
14
|
+
</InputRangeCore>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import propValidators from '../../c12/prop-validators';
|
|
20
|
+
|
|
21
|
+
import type { InpuTextC12, IFormFieldC12, IFormData } from '@/types/types.forms';
|
|
22
|
+
// import { validationConfig } from '@/components/forms/c12/validation-patterns';
|
|
23
|
+
|
|
24
|
+
const props = defineProps({
|
|
25
|
+
id: {
|
|
26
|
+
// type: String as PropType<string>,
|
|
27
|
+
type: String,
|
|
28
|
+
required: true,
|
|
29
|
+
},
|
|
30
|
+
name: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
required: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
value: false,
|
|
37
|
+
},
|
|
38
|
+
min: {
|
|
39
|
+
type: Number,
|
|
40
|
+
default: 0,
|
|
41
|
+
},
|
|
42
|
+
max: {
|
|
43
|
+
type: Number,
|
|
44
|
+
default: 100,
|
|
45
|
+
},
|
|
46
|
+
step: {
|
|
47
|
+
type: Number,
|
|
48
|
+
default: 1,
|
|
49
|
+
},
|
|
50
|
+
c12: {
|
|
51
|
+
type: Object as PropType<InpuTextC12>,
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
54
|
+
styleClassPassthrough: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: '',
|
|
57
|
+
},
|
|
58
|
+
theme: {
|
|
59
|
+
type: String as PropType<string>,
|
|
60
|
+
default: 'primary',
|
|
61
|
+
validator(value: string) {
|
|
62
|
+
return propValidators.theme.includes(value);
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
size: {
|
|
66
|
+
type: String as PropType<string>,
|
|
67
|
+
default: 'medium',
|
|
68
|
+
validator(value: string) {
|
|
69
|
+
return propValidators.size.includes(value);
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
weight: {
|
|
73
|
+
type: String as PropType<string>,
|
|
74
|
+
default: 'wght-400',
|
|
75
|
+
validator(value: string) {
|
|
76
|
+
return propValidators.weight.includes(value);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const slots = useSlots();
|
|
82
|
+
const hasDescription = computed(() => slots.description !== undefined);
|
|
83
|
+
const hasLeftContent = computed(() => slots.left !== undefined);
|
|
84
|
+
const hasRightContent = computed(() => slots.right !== undefined);
|
|
85
|
+
|
|
86
|
+
const modelValue = defineModel() as Ref<IFormData>;
|
|
87
|
+
|
|
88
|
+
const name = computed(() => {
|
|
89
|
+
return props.name !== null ? props.name : props.id;
|
|
90
|
+
});
|
|
91
|
+
const fieldHasError = computed(() => {
|
|
92
|
+
return modelValue.value!.submitAttempted && !modelValue.value!.formFieldsC12[name.value].isValid;
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<style lang="css">
|
|
97
|
+
.input-range-with-label {
|
|
98
|
+
--_form-theme: var(--theme-form-primary);
|
|
99
|
+
--_border-width: var(--input-border-width-default);
|
|
100
|
+
--_outline-width: var(--input-outline-width-thin);
|
|
101
|
+
--_label-padding-inline: 10px;
|
|
102
|
+
|
|
103
|
+
&.theme-secondary {
|
|
104
|
+
--_form-theme: var(--theme-form-secondary);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&.error {
|
|
108
|
+
--_form-theme: var(--theme-error);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.input-range-label {
|
|
112
|
+
color: var(--_form-theme);
|
|
113
|
+
display: block;
|
|
114
|
+
font-family: var(--font-family);
|
|
115
|
+
font-size: 18px;
|
|
116
|
+
font-weight: 500;
|
|
117
|
+
margin-bottom: 12px;
|
|
118
|
+
|
|
119
|
+
&:hover {
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.label-description {
|
|
125
|
+
font-family: var(--font-family);
|
|
126
|
+
font-size: 16px;
|
|
127
|
+
margin-top: 12px;
|
|
128
|
+
color: var(--theme-form-secondary);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
</style>
|