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.
Files changed (87) hide show
  1. package/assets/styles/ally/_utils.css +20 -0
  2. package/assets/styles/ally/_variables.css +8 -0
  3. package/assets/styles/ally/index.css +2 -0
  4. package/assets/styles/forms/index.css +2 -0
  5. package/assets/styles/forms/themes/_error.css +85 -0
  6. package/assets/styles/forms/themes/_ghost.css +85 -0
  7. package/assets/styles/forms/themes/_input-action-underlined.css +20 -0
  8. package/assets/styles/forms/themes/_input-action.css +20 -0
  9. package/assets/styles/forms/themes/_primary.css +92 -0
  10. package/assets/styles/forms/themes/_secondary.css +85 -0
  11. package/assets/styles/forms/themes/_success.css +85 -0
  12. package/assets/styles/forms/themes/_tertiary.css +85 -0
  13. package/assets/styles/forms/themes/_warning.css +85 -0
  14. package/assets/styles/forms/themes/index.css +9 -0
  15. package/assets/styles/forms/variables/_sizes.css +71 -0
  16. package/assets/styles/forms/variables/_theme.css +11 -0
  17. package/assets/styles/forms/variables/index.css +2 -0
  18. package/assets/styles/main.css +5 -0
  19. package/assets/styles/typography/index.css +2 -0
  20. package/assets/styles/typography/utils/_font-classes.css +190 -0
  21. package/assets/styles/typography/utils/_weights.css +69 -0
  22. package/assets/styles/typography/utils/index.css +2 -0
  23. package/assets/styles/typography/variables/_colors.css +14 -0
  24. package/assets/styles/typography/variables/_reponsive-font-size.css +10 -0
  25. package/assets/styles/typography/variables/index.css +2 -0
  26. package/assets/styles/utils/_margin-helpers.css +334 -0
  27. package/assets/styles/utils/_padding-helpers.css +308 -0
  28. package/assets/styles/utils/_page.css +49 -0
  29. package/assets/styles/utils/index.css +3 -0
  30. package/assets/styles/variables/colors/_blue.css +15 -0
  31. package/assets/styles/variables/colors/_gray.css +16 -0
  32. package/assets/styles/variables/colors/_green.css +15 -0
  33. package/assets/styles/variables/colors/_orange.css +15 -0
  34. package/assets/styles/variables/colors/_red.css +15 -0
  35. package/assets/styles/variables/colors/_yellow.css +15 -0
  36. package/assets/styles/variables/colors/colors.css +6 -0
  37. package/assets/styles/variables/index.css +1 -0
  38. package/components/forms/c12/prop-validators/index.ts +38 -0
  39. package/components/forms/c12/utils.ts +14 -0
  40. package/components/forms/form-errors/InputError.vue +172 -0
  41. package/components/forms/form-errors/tests/InputError.spec.ts +67 -0
  42. package/components/forms/input-button/InputButtonCore.vue +191 -0
  43. package/components/forms/input-button/variants/InputButtonConfirm.vue +66 -0
  44. package/components/forms/input-button/variants/InputButtonSubmit.vue +62 -0
  45. package/components/forms/input-checkbox/MultipleCheckboxes.vue +203 -0
  46. package/components/forms/input-checkbox/SingleCheckbox.vue +169 -0
  47. package/components/forms/input-checkbox/tests/MultipleCheckboxes.spec.ts +98 -0
  48. package/components/forms/input-checkbox/tests/data/tags.json +67 -0
  49. package/components/forms/input-checkbox-radio/InputCheckboxRadioButton.vue +214 -0
  50. package/components/forms/input-checkbox-radio/InputCheckboxRadioCore.vue +191 -0
  51. package/components/forms/input-checkbox-radio/InputCheckboxRadioWithLabel.vue +111 -0
  52. package/components/forms/input-number/InputNumberCore.vue +203 -0
  53. package/components/forms/input-number/variants/InputNumberDefault.vue +154 -0
  54. package/components/forms/input-radio/MultipleRadiobuttons.vue +201 -0
  55. package/components/forms/input-radio/tests/MultipleRadioButtons.spec.ts +89 -0
  56. package/components/forms/input-radio/tests/data/tags.json +67 -0
  57. package/components/forms/input-range/InputRangeCore.vue +274 -0
  58. package/components/forms/input-range/variants/InputRangeDefault.vue +156 -0
  59. package/components/forms/input-range-fancy/InputRangeFancyCore.vue +450 -0
  60. package/components/forms/input-range-fancy/InputRangeFancyWithLabel.vue +124 -0
  61. package/components/forms/input-select/InputSelect.vue +289 -0
  62. package/components/forms/input-text/InputTextCore.vue +331 -0
  63. package/components/forms/input-text/variants/InputPasswordWithLabel.vue +130 -0
  64. package/components/forms/input-text/variants/InputTextAsNumberWithLabel.vue +187 -0
  65. package/components/forms/input-text/variants/InputTextWithLabel.vue +298 -0
  66. package/components/forms/input-textarea/InputTextareaCore.vue +234 -0
  67. package/components/forms/input-textarea/variants/InputTextareaWithLabel.vue +267 -0
  68. package/components/forms/toggle-switch/ToggleSwitchCore.vue +198 -0
  69. package/components/forms/toggle-switch/ToggleSwitchCoreOld.vue +216 -0
  70. package/components/forms/toggle-switch/variants/ToggleSwitchWithLabel.vue +105 -0
  71. package/components/forms/toggle-switch/variants/ToggleSwitchWithLabelInline.vue +102 -0
  72. package/components/forms/ui/FormField.vue +78 -0
  73. package/components/forms/ui/FormWrapper.vue +35 -0
  74. package/components/utils/colour-scheme-select/ColourSchemeSelect.vue +270 -0
  75. package/components/utils/colour-scheme-select/ColourSchemeSelectOld.vue +225 -0
  76. package/components/utils/dark-mode-switcher/DarkModeSwitcher.vue +47 -0
  77. package/composables/useApiRequest.ts +25 -0
  78. package/composables/useColourScheme.ts +25 -0
  79. package/composables/useErrorMessages.ts +59 -0
  80. package/composables/useFormControl.ts +248 -0
  81. package/composables/useSleep.ts +5 -0
  82. package/composables/useStyleClassPassthrough.ts +30 -0
  83. package/composables/useZodValidation.ts +148 -0
  84. package/nuxt.config.ts +0 -3
  85. package/package.json +1 -1
  86. package/types/types.forms.ts +217 -0
  87. package/types/types.zodFormControl.ts +21 -0
@@ -0,0 +1,154 @@
1
+ <template>
2
+ <div class="input-number-with-label" :data-form-theme="formTheme" :data-size="size" :class="[elementClasses, `theme-${theme}`, { error: fieldHasError }]">
3
+ <label class="input-number-label body-normal-bold" :for="id">{{ label }}</label>
4
+ <template v-if="hasDescription">
5
+ <slot name="description"></slot>
6
+ </template>
7
+
8
+ <InputNumberCore v-model="modelValue" :id :name :min :max :step :theme :required :size :weight :fieldHasError :styleClassPassthrough>
9
+ <template v-if="hasLeftContent" #left>
10
+ <InputButtonCore
11
+ type="button"
12
+ @click.stop.prevent="updateValue(-step, Number(modelValue) > min)"
13
+ :readonly="Number(modelValue) <= min"
14
+ :is-pending="false"
15
+ buttonText="Step down"
16
+ theme="input-action"
17
+ :size
18
+ >
19
+ <template #iconOnly>
20
+ <slot name="left"></slot>
21
+ </template>
22
+ </InputButtonCore>
23
+ </template>
24
+ <template v-if="hasRightContent" #right>
25
+ <InputButtonCore
26
+ type="button"
27
+ @click.stop.prevent="updateValue(step, Number(modelValue) < max)"
28
+ :readonly="Number(modelValue) >= max"
29
+ :is-pending="false"
30
+ buttonText="Step up"
31
+ theme="input-action"
32
+ :size
33
+ >
34
+ <template #iconOnly>
35
+ <slot name="right"></slot>
36
+ </template>
37
+ </InputButtonCore>
38
+ </template>
39
+ </InputNumberCore>
40
+ <InputError :errorMessage :showError="fieldHasError" :id :isDetached="true" />
41
+ </div>
42
+ </template>
43
+
44
+ <script setup lang="ts">
45
+ import propValidators from '../../c12/prop-validators';
46
+
47
+ const props = defineProps({
48
+ name: {
49
+ type: String,
50
+ required: true,
51
+ },
52
+ label: {
53
+ type: String,
54
+ required: true,
55
+ },
56
+ min: {
57
+ type: Number,
58
+ required: true,
59
+ },
60
+ max: {
61
+ type: Number,
62
+ required: true,
63
+ },
64
+ step: {
65
+ type: Number,
66
+ default: 1,
67
+ },
68
+ placeholder: {
69
+ type: String,
70
+ default: '',
71
+ },
72
+ errorMessage: {
73
+ type: [Object, String],
74
+ required: true,
75
+ },
76
+ fieldHasError: {
77
+ type: Boolean,
78
+ default: false,
79
+ },
80
+ required: {
81
+ type: Boolean,
82
+ default: false,
83
+ },
84
+ theme: {
85
+ type: String as PropType<string>,
86
+ default: 'primary',
87
+ validator(value: string) {
88
+ return propValidators.theme.includes(value);
89
+ },
90
+ },
91
+ size: {
92
+ type: String as PropType<string>,
93
+ default: 'medium',
94
+ validator(value: string) {
95
+ return propValidators.size.includes(value);
96
+ },
97
+ },
98
+ weight: {
99
+ type: String as PropType<string>,
100
+ default: 'wght-400',
101
+ validator(value: string) {
102
+ return propValidators.weight.includes(value);
103
+ },
104
+ },
105
+ styleClassPassthrough: {
106
+ type: Array as PropType<string[]>,
107
+ default: () => [],
108
+ },
109
+ });
110
+
111
+ const slots = useSlots();
112
+ const hasDescription = computed(() => slots.description !== undefined);
113
+ const hasLeftContent = computed(() => slots.left !== undefined);
114
+ const hasRightContent = computed(() => slots.right !== undefined);
115
+ const { elementClasses, updateElementClasses } = useStyleClassPassthrough(props.styleClassPassthrough);
116
+
117
+ const id = useId();
118
+ const formTheme = computed(() => {
119
+ return props.fieldHasError ? 'error' : props.theme;
120
+ });
121
+
122
+ const modelValue = defineModel<number | readonly number[]>();
123
+
124
+ const updateValue = (step: number, withinRangeLimit: boolean) => {
125
+ if (withinRangeLimit) {
126
+ modelValue.value = (Number(modelValue.value) + step) as number;
127
+ }
128
+ };
129
+
130
+ updateElementClasses(['has-left-button', 'has-right-button']);
131
+ </script>
132
+
133
+ <style lang="css">
134
+ .input-number-with-label {
135
+ --_border-width: var(--form-element-border-width);
136
+ --_outline-width: var(--form-element-outline-width);
137
+ --_label-padding-inline: 1rem;
138
+
139
+ .input-number-label {
140
+ display: block;
141
+ margin-block: 0.8rem;
142
+
143
+ &:hover {
144
+ cursor: pointer;
145
+ }
146
+ }
147
+
148
+ .label-description {
149
+ font-family: var(--font-family);
150
+ font-size: 1.6rem;
151
+ margin-top: 1.2rem;
152
+ }
153
+ }
154
+ </style>
@@ -0,0 +1,201 @@
1
+ <template>
2
+ <fieldset :aria-required="required" :aria-invalid="fieldHasError" role="radiogroup" class="multiple-radiobuttons-fieldset" :class="[elementClasses, { error: fieldHasError }]" :data-testid>
3
+ <legend :class="[{ 'has-description': hasDescriptionSlot }]">{{ legend }}</legend>
4
+
5
+ <div v-if="hasDescriptionSlot" :id="`${name}-description`">
6
+ <slot name="description"></slot>
7
+ </div>
8
+
9
+ <div class="multiple-radiobuttons-items" :class="[optionsLayout]">
10
+ <template v-for="item in fieldData.data" :key="item.id">
11
+ <InputCheckboxRadioButton
12
+ v-if="isButton"
13
+ type="radio"
14
+ :id="`${name}-${item.value}`"
15
+ :name="`${name}-${item.name}`"
16
+ :required
17
+ :label="item.label"
18
+ :fieldHasError
19
+ v-model="modelValue"
20
+ :true-value="item.value"
21
+ :size
22
+ :optionsLayout
23
+ :theme
24
+ :direction
25
+ :ariaDescribedby
26
+ >
27
+ <template #checkedIcon>
28
+ <slot name="checkedIcon"></slot>
29
+ </template>
30
+ <template #itemIcon>
31
+ <slot name="itemIcon">
32
+ <Icon name="material-symbols:add-2" class="icon" />
33
+ </slot>
34
+ </template>
35
+ </InputCheckboxRadioButton>
36
+ <InputCheckboxRadioWithLabel
37
+ v-else
38
+ type="radio"
39
+ :id="`${name}-${item.value}`"
40
+ :name="`${name}-${item.name}`"
41
+ :required
42
+ :label="item.label"
43
+ :fieldHasError
44
+ v-model="modelValue"
45
+ :true-value="item.value"
46
+ :size
47
+ :optionsLayout
48
+ :theme
49
+ :ariaDescribedby
50
+ >
51
+ <template #checkedIcon>
52
+ <slot name="checkedIcon"></slot>
53
+ </template>
54
+ </InputCheckboxRadioWithLabel>
55
+ </template>
56
+ </div>
57
+ <InputError :errorMessage="errorMessage" :showError="fieldHasError" :id="errorId" :isDetached="true" />
58
+ </fieldset>
59
+ </template>
60
+
61
+ <script setup lang="ts">
62
+ import propValidators from '../c12/prop-validators';
63
+ import type { IFormMultipleOptions } from '@/types/types.forms';
64
+
65
+ const props = defineProps({
66
+ dataTestid: {
67
+ type: String,
68
+ default: 'multiple-radio-buttons',
69
+ },
70
+ name: {
71
+ type: String,
72
+ required: true,
73
+ },
74
+ legend: {
75
+ type: String,
76
+ required: true,
77
+ },
78
+ label: {
79
+ type: String,
80
+ required: true,
81
+ },
82
+ placeholder: {
83
+ type: String,
84
+ default: '',
85
+ },
86
+ isButton: {
87
+ type: Boolean,
88
+ default: false,
89
+ },
90
+ errorMessage: {
91
+ type: [Object, String],
92
+ required: true,
93
+ },
94
+ required: {
95
+ type: Boolean,
96
+ default: false,
97
+ },
98
+ fieldHasError: {
99
+ type: Boolean,
100
+ default: false,
101
+ },
102
+ multipleOptions: {
103
+ type: Boolean,
104
+ default: false,
105
+ },
106
+ size: {
107
+ type: String as PropType<string>,
108
+ default: 'medium',
109
+ validator(value: string) {
110
+ return propValidators.size.includes(value);
111
+ },
112
+ },
113
+ optionsLayout: {
114
+ type: String as PropType<string>,
115
+ default: 'equal-widths',
116
+ validator(value: string) {
117
+ return propValidators.optionsLayout.includes(value);
118
+ },
119
+ },
120
+ equalCols: {
121
+ type: Boolean,
122
+ default: true,
123
+ },
124
+ styleClassPassthrough: {
125
+ type: Array as PropType<string[]>,
126
+ default: () => [],
127
+ },
128
+ theme: {
129
+ type: String as PropType<string>,
130
+ default: 'primary',
131
+ validator(value: string) {
132
+ return propValidators.theme.includes(value);
133
+ },
134
+ },
135
+ direction: {
136
+ type: String as PropType<'row' | 'row-reverse'>,
137
+ default: 'row',
138
+ validator(value: string) {
139
+ return ['row', 'row-reverse'].includes(value);
140
+ },
141
+ },
142
+ });
143
+
144
+ const slots = useSlots();
145
+ const hasDescriptionSlot = computed(() => slots.description !== undefined);
146
+ const { elementClasses } = useStyleClassPassthrough(props.styleClassPassthrough);
147
+
148
+ const id = useId();
149
+ const errorId = `${name}-error-message`;
150
+ const ariaDescribedby = computed(() => {
151
+ const ariaDescribedbyId = hasDescriptionSlot.value ? `${id}-description` : undefined;
152
+ return props.fieldHasError ? errorId : ariaDescribedbyId;
153
+ });
154
+
155
+ const modelValue = defineModel();
156
+ const fieldData = defineModel('fieldData') as Ref<IFormMultipleOptions>;
157
+ </script>
158
+
159
+ <style lang="css">
160
+ .multiple-radiobuttons-fieldset {
161
+ margin: 0;
162
+ padding: 0;
163
+ border: 0;
164
+
165
+ legend {
166
+ font-family: var(--font-family);
167
+ font-size: 1.6rem;
168
+ font-weight: 500;
169
+
170
+ &.has-description {
171
+ margin-bottom: 0;
172
+ }
173
+ }
174
+
175
+ .label-description {
176
+ font-family: var(--font-family);
177
+ font-size: 1.6rem;
178
+ margin-top: 1.2rem;
179
+ }
180
+ }
181
+
182
+ .multiple-radiobuttons-items {
183
+ display: flex;
184
+ gap: 1.2rem;
185
+ margin-top: 1.2rem;
186
+
187
+ &.inline {
188
+ flex-direction: row;
189
+ flex-wrap: wrap;
190
+ }
191
+
192
+ &.block {
193
+ flex-direction: column;
194
+ }
195
+
196
+ &.equal-widths {
197
+ display: grid;
198
+ grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
199
+ }
200
+ }
201
+ </style>
@@ -0,0 +1,89 @@
1
+ // https://nuxt.com/docs/getting-started/testing#unit-testing
2
+ import { describe, it, expect } from 'vitest';
3
+ import { VueWrapper } from '@vue/test-utils';
4
+ import { mountSuspended } from '@nuxt/test-utils/runtime';
5
+ import ComponentUnderTest from '../MultipleRadioButtons.vue';
6
+ import tagsData from './data/tags.json';
7
+
8
+ let initialPropsData = {
9
+ dataTestid: 'multiple-radio-buttons',
10
+ id: 'tags',
11
+ name: 'tags',
12
+ legend: 'Choose tags (as checkboxes)',
13
+ required: true,
14
+ label: 'Check between 3 and 8 tags',
15
+ placeholder: 'eg. Type something here',
16
+ isButton: true,
17
+ errorMessage: 'Please select between 3 and 8 tags',
18
+ fieldHasError: false,
19
+ fieldData: tagsData,
20
+ size: 'small',
21
+ optionsLayout: 'inline',
22
+ styleClassPassthrough: ['testClass'],
23
+ theme: 'primary',
24
+ };
25
+
26
+ const initialSlots = {
27
+ checkedIcon: () => ``,
28
+ itemIcon: () => `<Icon name="material-symbols:add-2" class="icon" />`,
29
+ };
30
+
31
+ let wrapper: VueWrapper<InstanceType<typeof ComponentUnderTest>>;
32
+ const wrapperFactory = (propsData = {}, slotsData = {}) => {
33
+ const mockPropsData = { ...initialPropsData, ...propsData };
34
+ const mockSlotsData = { ...initialSlots, ...slotsData };
35
+
36
+ return mountSuspended(ComponentUnderTest, {
37
+ attachTo: document.body,
38
+ props: mockPropsData,
39
+ slots: mockSlotsData,
40
+ });
41
+ };
42
+
43
+ describe('MultipleRadioButtons Component', () => {
44
+ it('Mounts', async () => {
45
+ wrapper = await wrapperFactory();
46
+ expect(wrapper).toBeTruthy();
47
+ });
48
+
49
+ it('renders properly', async () => {
50
+ wrapper = await wrapperFactory();
51
+ const dataTestIdElem = wrapper.attributes('data-testid');
52
+ expect(dataTestIdElem).toBe(initialPropsData.dataTestid);
53
+ expect(wrapper.find('[data-testid]').classes()).toContain('testClass');
54
+ });
55
+
56
+ it('updates radio modelValue when items clicked', async () => {
57
+ const modelValue = ref<string>('');
58
+ const propsData = {
59
+ modelValue,
60
+ };
61
+ wrapper = await wrapperFactory(propsData);
62
+
63
+ /*
64
+ * Test the first radio button
65
+ **/
66
+ const radiobuttonElements = wrapper.findAll('input[type="radio"]');
67
+ const firstRadioButton = radiobuttonElements[0];
68
+ expect(firstRadioButton.attributes('aria-checked')).toBe('false');
69
+ const firstRadioButtonTrueValue = firstRadioButton.attributes('true-value');
70
+
71
+ await firstRadioButton.trigger('click');
72
+ wrapper.vm.modelValue.value = firstRadioButtonTrueValue;
73
+ expect(firstRadioButton.attributes('aria-checked')).toBe('true');
74
+ expect(wrapper.vm.modelValue.value).toEqual(firstRadioButtonTrueValue);
75
+
76
+ /*
77
+ * Test the second radio button
78
+ **/
79
+ const secondRadioButton = radiobuttonElements[1];
80
+ expect(secondRadioButton.attributes('aria-checked')).toBe('false');
81
+ const secondRadioButtonTrueValue = secondRadioButton.attributes('true-value');
82
+
83
+ await secondRadioButton.trigger('click');
84
+ wrapper.vm.modelValue.value = secondRadioButtonTrueValue;
85
+ expect(firstRadioButton.attributes('aria-checked')).toBe('false');
86
+ expect(secondRadioButton.attributes('aria-checked')).toBe('true');
87
+ expect(wrapper.vm.modelValue.value).toEqual(secondRadioButtonTrueValue);
88
+ });
89
+ });
@@ -0,0 +1,67 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "pizza",
5
+ "name": "tags",
6
+ "value": "pizza",
7
+ "label": "Pizza"
8
+ },
9
+ {
10
+ "id": "italian",
11
+ "name": "tags",
12
+ "value": "italian",
13
+ "label": "Italian"
14
+ },
15
+ {
16
+ "id": "vegetarian",
17
+ "name": "tags",
18
+ "value": "vegetarian",
19
+ "label": "Vegetarian"
20
+ },
21
+ {
22
+ "id": "stir-fry",
23
+ "name": "tags",
24
+ "value": "stir-fry",
25
+ "label": "Stir-fry"
26
+ },
27
+ {
28
+ "id": "asian",
29
+ "name": "tags",
30
+ "value": "asian",
31
+ "label": "Asian"
32
+ },
33
+ {
34
+ "id": "cookies",
35
+ "name": "tags",
36
+ "value": "cookies",
37
+ "label": "Cookies"
38
+ },
39
+ {
40
+ "id": "dessert",
41
+ "name": "tags",
42
+ "value": "dessert",
43
+ "label": "Dessert"
44
+ },
45
+ {
46
+ "id": "baking",
47
+ "name": "tags",
48
+ "value": "baking",
49
+ "label": "Baking"
50
+ },
51
+ {
52
+ "id": "pasta",
53
+ "name": "tags",
54
+ "value": "pasta",
55
+ "label": "Pasta"
56
+ },
57
+ {
58
+ "id": "chicken",
59
+ "name": "tags",
60
+ "value": "chicken",
61
+ "label": "Chicken"
62
+ }
63
+ ],
64
+ "total": 5,
65
+ "skip": 0,
66
+ "limit": 10
67
+ }