srcdev-nuxt-forms 0.0.23 → 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.
Files changed (64) hide show
  1. package/.prettierrc +2 -1
  2. package/LICENSE +21 -0
  3. package/assets/styles/forms/index.css +1 -0
  4. package/assets/styles/forms/themes/_error.css +9 -0
  5. package/assets/styles/forms/themes/_ghost.css +11 -0
  6. package/assets/styles/forms/themes/_primary.css +11 -1
  7. package/assets/styles/forms/themes/_secondary.css +13 -0
  8. package/assets/styles/forms/themes/_success.css +12 -0
  9. package/assets/styles/forms/themes/_tertiary.css +11 -0
  10. package/assets/styles/forms/themes/_warning.css +11 -0
  11. package/assets/styles/forms/themes/index.css +5 -0
  12. package/assets/styles/forms/utils/_a11y.css +5 -0
  13. package/assets/styles/forms/utils/index.css +1 -0
  14. package/assets/styles/forms/variables/_theme.css +56 -2
  15. package/assets/styles/variables/colors/_gray.css +1 -0
  16. package/assets/styles/variables/colors/_orange.css +1 -1
  17. package/assets/styles/variables/colors/_red.css +1 -1
  18. package/components/forms/c12/prop-validators/index.ts +13 -0
  19. package/components/forms/c12/utils.ts +14 -0
  20. package/components/forms/c12/validation-patterns/en.json +13 -1
  21. package/components/forms/form-errors/InputError.vue +132 -0
  22. package/components/forms/input-button/InputButtonCore.vue +370 -0
  23. package/components/forms/input-button/variants/InputButtonConfirm.vue +78 -0
  24. package/components/forms/input-button/variants/InputButtonSubmit.vue +74 -0
  25. package/components/forms/input-checkbox/InputCheckboxCore.vue +407 -0
  26. package/components/forms/input-checkbox/InputCheckboxWithLabel.vue +125 -0
  27. package/components/forms/input-checkbox/variants/MultipleCheckboxes.vue +194 -0
  28. package/components/forms/input-checkbox/variants/SingleCheckbox.vue +157 -0
  29. package/components/forms/input-radio/InputRadioCore.vue +226 -0
  30. package/components/forms/input-radio/InputRadioWithLabel.vue +118 -0
  31. package/components/forms/input-radio/variants/MultipleRadio.vue +183 -0
  32. package/components/forms/input-radio/variants/SingleRadio.vue +131 -0
  33. package/components/forms/input-range/InputRangeCore.vue +171 -0
  34. package/components/forms/input-range/variants/InputRangeDefault.vue +131 -0
  35. package/components/forms/input-text/InputTextCore.vue +115 -79
  36. package/components/forms/input-text/variants/material/InputEmailMaterial.vue +72 -0
  37. package/components/forms/input-text/variants/material/InputPasswordMaterial.vue +114 -0
  38. package/components/forms/input-text/variants/material/InputTextMaterial.vue +68 -0
  39. package/components/forms/input-text/variants/material/InputTextMaterialCore.vue +313 -0
  40. package/components/forms/input-textarea/InputTextareaCore.vue +170 -0
  41. package/components/forms/input-textarea/variants/material/InputTextareaMaterial.vue +75 -0
  42. package/components/forms/input-textarea/variants/material/InputTextareaMaterialCore.vue +290 -0
  43. package/components/forms/ui/FormField.vue +7 -2
  44. package/components/forms/ui/FormWrapper.vue +2 -2
  45. package/components/ui/content-grid/ContentGrid.vue +85 -0
  46. package/composables/useErrorMessages.ts +21 -9
  47. package/composables/useFormControl.ts +171 -41
  48. package/layouts/default.vue +28 -3
  49. package/nuxt.config.ts +26 -3
  50. package/package.json +9 -6
  51. package/pages/forms/examples/buttons/index.vue +155 -0
  52. package/pages/forms/examples/material/text-fields.vue +372 -0
  53. package/pages/index.vue +2 -70
  54. package/pages/limit-text.vue +43 -0
  55. package/server/api/places/list.get.ts +23 -0
  56. package/server/api/textFields.post.ts +37 -0
  57. package/server/api/utils/index.get.ts +20 -0
  58. package/server/data/places/cities.json +37 -0
  59. package/server/data/places/countries.json +55 -0
  60. package/server/data/utils/title.json +49 -0
  61. package/types/types.forms.ts +38 -13
  62. package/types/types.places.ts +8 -0
  63. package/components/forms/input-text/InputTextField.vue +0 -22
  64. package/components/forms/input-text/variants/InputTextMaterial.vue +0 -192
@@ -0,0 +1,313 @@
1
+ <template>
2
+ <div class="input-text-material" :class="[`theme-${theme}`, { error: fieldHasError }, { compact: compact }]">
3
+ <label class="input-text-label" :for="id" :class="[{ active: isFocused }, { error: fieldHasError }, { dirty: fieldIsDirty }, { compact: compact }]">
4
+ <span>{{ c12.label }}</span>
5
+ </label>
6
+ <div class="input-text-container" :class="[{ active: isFocused }, { error: fieldHasError }, { dirty: fieldIsDirty }, { compact: compact }]">
7
+ <slot name="input"></slot>
8
+ </div>
9
+ <InputError :errorMessaging :fieldHasError :id :isDetached="false" />
10
+ </div>
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ import type { InpuTextC12, IFormData } from '@/types/types.forms';
15
+
16
+ import propValidators from '../../../c12/prop-validators';
17
+
18
+ const props = defineProps({
19
+ size: {
20
+ type: String as PropType<string>,
21
+ default: 'normal',
22
+ validator(value: string) {
23
+ return propValidators.size.includes(value);
24
+ },
25
+ },
26
+ weight: {
27
+ type: String as PropType<string>,
28
+ default: 'wght-400',
29
+ validator(value: string) {
30
+ return propValidators.weight.includes(value);
31
+ },
32
+ },
33
+ theme: {
34
+ type: String as PropType<string>,
35
+ default: 'primary',
36
+ validator(value: string) {
37
+ return propValidators.theme.includes(value);
38
+ },
39
+ },
40
+ type: {
41
+ type: String,
42
+ required: true,
43
+ validator(value: string) {
44
+ return propValidators.inputTypesText.includes(value);
45
+ },
46
+ },
47
+ id: {
48
+ type: String,
49
+ required: true,
50
+ },
51
+ name: {
52
+ type: String,
53
+ default: null,
54
+ },
55
+ required: {
56
+ type: Boolean,
57
+ value: false,
58
+ },
59
+ c12: {
60
+ type: Object as PropType<InpuTextC12>,
61
+ required: true,
62
+ },
63
+ styleClassPassthrough: {
64
+ type: String,
65
+ default: '',
66
+ },
67
+ compact: {
68
+ type: Boolean,
69
+ value: false,
70
+ },
71
+ });
72
+
73
+ const errorMessaging = computed(() => {
74
+ if (
75
+ typeof modelValue.value!.formFieldsC12[props.name] !== 'undefined' &&
76
+ modelValue.value!.formFieldsC12[props.name].useCustomError &&
77
+ modelValue.value.data[props.name] === modelValue.value.formFieldsC12[props.name].previousValue
78
+ ) {
79
+ return modelValue.value.formFieldsC12[props.name]?.customErrors || [];
80
+ } else {
81
+ return props.c12.errorMessage;
82
+ }
83
+ });
84
+
85
+ const modelValue = defineModel() as Ref<IFormData>;
86
+
87
+ const isFocused = computed(() => {
88
+ return modelValue.value.focusedField == props.name;
89
+ });
90
+
91
+ const fieldIsDirty = computed(() => {
92
+ if (typeof modelValue.value!.formFieldsC12[props.name] !== 'undefined') {
93
+ return modelValue.value!.formFieldsC12[props.name].isDirty;
94
+ } else {
95
+ return false;
96
+ }
97
+ });
98
+
99
+ const fieldHasError = computed(() => {
100
+ if (typeof modelValue.value!.formFieldsC12[props.name] !== 'undefined') {
101
+ return modelValue.value!.submitAttempted && !modelValue.value!.formFieldsC12[props.name].isValid;
102
+ }
103
+ return false;
104
+ });
105
+ </script>
106
+
107
+ <style lang="css">
108
+ .input-text-material {
109
+ --_form-theme: var(--theme-form-primary);
110
+ --_focus-colour: var(--theme-form-primary-focus);
111
+ --_gutter: 12px;
112
+ --_border-width: var(--input-border-width-thin);
113
+ --_border-color: var(--_form-theme);
114
+ --_outline-width: var(--input-outline-width-thin);
115
+
116
+ &.theme-secondary {
117
+ --_form-theme: var(--theme-form-secondary);
118
+ --_focus-colour: var(--theme-form-secondary-focus);
119
+ }
120
+
121
+ &.error {
122
+ --_form-theme: var(--theme-error);
123
+ }
124
+
125
+ /*
126
+ &:has(.input-text:invalid),
127
+ &:has(.input-textarea:invalid) {
128
+ --_form-theme: green;
129
+ }
130
+ */
131
+
132
+ /*
133
+ &:not(:placeholder-shown):invalid {
134
+ --_form-theme: green;
135
+ }
136
+ &:has(.text-input:not(:placeholder-shown):invalid) {
137
+ --_form-theme: red;
138
+ }
139
+
140
+ */
141
+
142
+ .input-text-core {
143
+ background-color: transparent;
144
+ line-height: var(--line-height);
145
+
146
+ &:focus {
147
+ outline: none;
148
+ box-shadow: none;
149
+ border: none;
150
+ }
151
+
152
+ &:-internal-autofill-selected,
153
+ &:autofill {
154
+ background-color: transparent !important;
155
+ }
156
+ }
157
+
158
+ .input-text-label {
159
+ color: var(--_form-theme);
160
+ margin: initial;
161
+ line-height: var(--line-height);
162
+ padding: initial;
163
+ transition: color 0.2s ease-in-out;
164
+ }
165
+
166
+ display: grid;
167
+ border-radius: 2px;
168
+ border: var(--_border-width) solid var(--_border-color);
169
+
170
+ margin-bottom: 20px;
171
+ overflow: hidden;
172
+
173
+ &:focus-within {
174
+ --_border-color: white;
175
+ outline: var(--_outline-width) solid hsl(from var(--_form-theme) h s 50%);
176
+ background-color: hsl(from var(--_form-theme) h s 95%);
177
+ }
178
+
179
+ &:has(.input-text-core:focus-visible),
180
+ &:has(.input-button-core:focus-visible) {
181
+ /* box-shadow: 0 0 2px 3px var(--_focus-colour);
182
+ outline-color: var(--_focus-colour); */
183
+
184
+ outline: var(--focus-visible-outline);
185
+ box-shadow: var(--focus-visible-box-shadow);
186
+ }
187
+
188
+ &.error {
189
+ /* outline: calc(var(--_border-width) * 2) solid var(--theme-error); */
190
+
191
+ border: var(--_border-width) solid var(--theme-error);
192
+ outline: var(--_outline-width) solid hsl(from var(--theme-error) h s 75%);
193
+
194
+ background-color: hsl(from var(--theme-error) h s 95%);
195
+ }
196
+
197
+ .input-text-label {
198
+ grid-row: 1;
199
+ grid-column: 1;
200
+
201
+ font-family: var(--font-family);
202
+ font-size: 20px;
203
+ font-weight: 700;
204
+ padding: var(--_gutter);
205
+ transform: translateY(12px);
206
+ transition: all linear 0.2s;
207
+ background-color: transparent;
208
+ z-index: 2;
209
+
210
+ &.active,
211
+ &.dirty,
212
+ &.error {
213
+ font-size: 16px;
214
+ height: 1.5em;
215
+ transform: translateY(-2px);
216
+ z-index: auto;
217
+ }
218
+ }
219
+
220
+ .input-text-container {
221
+ display: grid;
222
+ grid-row: 1;
223
+ grid-column: 1;
224
+ margin-top: 2rem;
225
+ background-color: transparent;
226
+ opacity: 0;
227
+ transition: opacity linear 0.2s;
228
+
229
+ &.active,
230
+ &.dirty,
231
+ &.error {
232
+ opacity: 1;
233
+ }
234
+
235
+ .input-text-core {
236
+ font-family: var(--font-family);
237
+ border: 0px solid green;
238
+ padding: calc(var(--_gutter) / 2) var(--_gutter);
239
+ font-size: var(--font-size);
240
+ margin: 0;
241
+ /* opacity: 0;
242
+ transition: opacity linear 0.2s;
243
+
244
+ &.active,
245
+ &.dirty {
246
+ opacity: 1;
247
+ } */
248
+ /*
249
+ &::placeholder,
250
+ &:-ms-input-placeholder,
251
+ &::-moz-placeholder, */
252
+ &::-webkit-input-placeholder {
253
+ font-family: var(--font-family);
254
+ /* color: var(--gray-5); */
255
+ color: hsl(from var(--_form-theme) h s 50%);
256
+ font-size: var(--font-size);
257
+ font-style: italic;
258
+ font-weight: 500;
259
+ }
260
+ }
261
+ }
262
+ }
263
+
264
+ /*
265
+ * Compact UI
266
+ **/
267
+
268
+ .input-text-material {
269
+ &.compact {
270
+ overflow: initial;
271
+
272
+ &:focus-within {
273
+ background-color: initial;
274
+ }
275
+
276
+ &.error {
277
+ background-color: initial;
278
+ }
279
+ }
280
+
281
+ .input-text-label {
282
+ &.compact {
283
+ align-content: center;
284
+ font-size: 16px;
285
+ padding: 0 12px;
286
+ transform: translateY(0);
287
+
288
+ span {
289
+ padding: 0 8px;
290
+ }
291
+
292
+ &.active,
293
+ &.dirty,
294
+ &.error {
295
+ font-size: 16px;
296
+ font-weight: 500;
297
+ transform: translateY(-14px);
298
+ z-index: auto;
299
+
300
+ span {
301
+ background-color: white;
302
+ }
303
+ }
304
+ }
305
+ }
306
+
307
+ .input-text-container {
308
+ &.compact {
309
+ margin: 10px 8px 6px 8px;
310
+ }
311
+ }
312
+ }
313
+ </style>
@@ -0,0 +1,170 @@
1
+ <template>
2
+ <div class="input-textarea-wrapper" :class="[{ 'has-left-content': hasLeftContent }, { 'has-right-content': hasRightContent }]">
3
+ <span v-if="hasLeftContent" class="left-content">
4
+ <slot name="left"></slot>
5
+ </span>
6
+
7
+ <textarea
8
+ :id
9
+ :name
10
+ :pattern="componentValidation.pattern"
11
+ :maxlength="componentValidation.maxlength"
12
+ :required
13
+ :class="['input-textarea-core', 'text-normal', styleClassPassthrough, { active: isFocused }, { dirty: fieldIsDirty }, { error: fieldHasError }]"
14
+ v-model="<string>modelValue.data[name]"
15
+ ref="inputField"
16
+ :placeholder="c12.placeholder"
17
+ :aria-invalid="fieldHasError"
18
+ :aria-describedby="`${id}-error-message`"
19
+ @focusin="updateFocus(name, true)"
20
+ @focusout="updateFocus(name, false)"
21
+ ></textarea>
22
+
23
+ <span v-if="hasRightContent" class="right-content">
24
+ <slot name="right"></slot>
25
+ </span>
26
+ </div>
27
+ </template>
28
+
29
+ <script setup lang="ts">
30
+ import type { InpuTextC12, IFormFieldC12, IFormData } from '@/types/types.forms';
31
+ import { validationConfig } from '@/components/forms/c12/validation-patterns';
32
+
33
+ const props = defineProps({
34
+ id: {
35
+ type: String,
36
+ required: true,
37
+ },
38
+ name: {
39
+ type: String,
40
+ required: true,
41
+ },
42
+ validation: {
43
+ type: String,
44
+ default: null,
45
+ },
46
+ required: {
47
+ type: Boolean,
48
+ value: false,
49
+ },
50
+ c12: {
51
+ type: Object as PropType<InpuTextC12>,
52
+ required: true,
53
+ },
54
+ styleClassPassthrough: {
55
+ type: String,
56
+ default: '',
57
+ },
58
+ });
59
+
60
+ const slots = useSlots();
61
+ const hasLeftContent = computed(() => slots.left !== undefined);
62
+ const hasRightContent = computed(() => slots.right !== undefined);
63
+
64
+ const modelValue = defineModel() as Ref<IFormData>;
65
+
66
+ const updateFocus = (name: string, isFocused: boolean) => {
67
+ console.log(`textarea | updateFocus: ${name} ${isFocused}`);
68
+ modelValue.value.focusedField = isFocused ? name : '';
69
+ };
70
+
71
+ const isFocused = computed(() => {
72
+ return modelValue.value.focusedField == name.value;
73
+ });
74
+
75
+ const name = computed(() => {
76
+ return props.name !== null ? props.name : props.id;
77
+ });
78
+
79
+ const validatorLocale = toRef(useRuntimeConfig().public.validatorLocale);
80
+
81
+ const componentValidation = validationConfig[validatorLocale.value][props.validation];
82
+ const inputField = ref<HTMLInputElement | null>(null);
83
+
84
+ const fieldIsDirty = computed(() => {
85
+ return modelValue.value!.formFieldsC12[name.value].isDirty;
86
+ });
87
+ const fieldHasError = computed(() => {
88
+ return modelValue.value!.submitAttempted && !modelValue.value!.formFieldsC12[name.value].isValid;
89
+ });
90
+
91
+ // const { fieldHasError } = useFormControl(name.value);
92
+
93
+ const formFieldC12 = <IFormFieldC12>{
94
+ label: props.c12.label,
95
+ placeholder: props.c12.placeholder,
96
+ errorMessage: props.c12.errorMessage,
97
+ useCustomError: false,
98
+ customErrors: {},
99
+ isValid: false,
100
+ isDirty: false,
101
+ type: 'string',
102
+ previousValue: null,
103
+ };
104
+ modelValue.value!.formFieldsC12[name.value] = formFieldC12;
105
+
106
+ const { initFormFieldsC12 } = useFormControl();
107
+ initFormFieldsC12(props.name, formFieldC12);
108
+
109
+ const fieldValue = computed(() => {
110
+ return modelValue.value.data[name.value];
111
+ });
112
+
113
+ watch(fieldValue, () => {
114
+ if (!modelValue.value!.formFieldsC12[name.value].isDirty) {
115
+ modelValue.value!.formFieldsC12[name.value].isDirty = modelValue.value.data[name.value] !== '';
116
+ }
117
+ modelValue.value!.formFieldsC12[name.value].isValid = inputField.value?.validity.valid ?? false;
118
+ modelValue.value!.validityState[name.value] = inputField.value?.validity.valid ?? false;
119
+
120
+ if (modelValue.value!.formFieldsC12[name.value].useCustomError && modelValue.value.data[props.name] === modelValue.value.formFieldsC12[props.name].previousValue) {
121
+ modelValue.value!.validityState[name.value] = false;
122
+ modelValue.value!.formFieldsC12[name.value].isValid = false;
123
+ modelValue.value.displayErrorMessages = true;
124
+ }
125
+ });
126
+
127
+ const isValid = () => {
128
+ setTimeout(() => {
129
+ modelValue.value!.validityState[name.value] = inputField.value?.validity.valid ?? false;
130
+ modelValue.value!.formFieldsC12[name.value].isValid = inputField.value?.validity.valid ?? false;
131
+ if (!modelValue.value!.formFieldsC12[name.value].isDirty) {
132
+ modelValue.value!.formFieldsC12[name.value].isDirty = modelValue.value.data[name.value] !== '';
133
+ }
134
+ }, 0);
135
+ };
136
+
137
+ onMounted(() => {
138
+ isValid();
139
+ });
140
+ </script>
141
+
142
+ <style lang="css">
143
+ .input-textarea-wrapper {
144
+ align-items: center;
145
+ display: grid;
146
+ grid-template-columns: 1fr;
147
+
148
+ &.has-left-content {
149
+ grid-template-columns: auto 1fr;
150
+ margin-left: var(--_gutter);
151
+
152
+ .left-content {
153
+ display: flex;
154
+ align-items: center;
155
+ }
156
+ }
157
+
158
+ &.has-right-content {
159
+ display: grid;
160
+ grid-template-columns: 1fr auto;
161
+ /* display: flex; */
162
+ margin-right: var(--_gutter);
163
+
164
+ .right-content {
165
+ display: flex;
166
+ align-items: center;
167
+ }
168
+ }
169
+ }
170
+ </style>
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <InputTextareaMaterialCore :type :id :name :required :c12 :styleClassPassthrough :theme v-model="modelValue">
3
+ <template #input>
4
+ <InputTextareaCore :id :name :validation :required v-model="modelValue" :c12 :style-class-passthrough="styleClassPassthrough" />
5
+ </template>
6
+ </InputTextareaMaterialCore>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import type { InpuTextC12, IFormData } from '@/types/types.forms';
11
+
12
+ import propValidators from '../../../c12/prop-validators';
13
+
14
+ const props = defineProps({
15
+ size: {
16
+ type: String as PropType<string>,
17
+ default: 'normal',
18
+ validator(value: string) {
19
+ return propValidators.size.includes(value);
20
+ },
21
+ },
22
+ weight: {
23
+ type: String as PropType<string>,
24
+ default: 'wght-400',
25
+ validator(value: string) {
26
+ return propValidators.weight.includes(value);
27
+ },
28
+ },
29
+ theme: {
30
+ type: String as PropType<string>,
31
+ default: 'primary',
32
+ validator(value: string) {
33
+ return propValidators.theme.includes(value);
34
+ },
35
+ },
36
+ type: {
37
+ // type: String as PropType<"text" | "password" | "tel" | "number" | "email" | "url">, // This breaks props setup in unit tests
38
+ type: String,
39
+ validator(value: string) {
40
+ return ['text', 'password', 'tel', 'number', 'email', 'url'].includes(value);
41
+ },
42
+ },
43
+ id: {
44
+ // type: String as PropType<string>,
45
+ type: String,
46
+ required: true,
47
+ },
48
+ name: {
49
+ type: String,
50
+ default: null,
51
+ },
52
+ validation: {
53
+ type: String,
54
+ default: '',
55
+ },
56
+ required: {
57
+ type: Boolean,
58
+ value: false,
59
+ },
60
+ c12: {
61
+ type: Object as PropType<InpuTextC12>,
62
+ required: true,
63
+ },
64
+ styleClassPassthrough: {
65
+ type: String,
66
+ default: '',
67
+ },
68
+ });
69
+
70
+ const name = computed(() => {
71
+ return props.name !== null ? props.name : props.id;
72
+ });
73
+
74
+ const modelValue = defineModel() as Ref<IFormData>;
75
+ </script>