@mozaic-ds/vue 1.0.0-beta.3 → 1.0.0-beta.5

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 (191) hide show
  1. package/LICENSE +51 -0
  2. package/README.md +224 -82
  3. package/dist/mozaic-vue.css +1 -1
  4. package/dist/mozaic-vue.d.ts +1202 -0
  5. package/dist/mozaic-vue.js +1220 -0
  6. package/dist/mozaic-vue.js.map +1 -0
  7. package/dist/mozaic-vue.umd.cjs +2 -0
  8. package/dist/mozaic-vue.umd.cjs.map +1 -0
  9. package/env.d.ts +1 -0
  10. package/package.json +81 -50
  11. package/src/components/Contributing.mdx +118 -0
  12. package/src/components/GettingStarted.mdx +50 -0
  13. package/src/components/Introduction.mdx +54 -0
  14. package/src/components/Support.mdx +18 -0
  15. package/src/components/badge/MBadge.spec.ts +16 -0
  16. package/src/components/badge/MBadge.stories.ts +50 -0
  17. package/src/components/badge/MBadge.vue +36 -34
  18. package/src/components/breadcrumb/MBreadcrumb.spec.ts +105 -0
  19. package/src/components/breadcrumb/MBreadcrumb.stories.ts +57 -0
  20. package/src/components/breadcrumb/MBreadcrumb.vue +52 -55
  21. package/src/components/button/MButton.spec.ts +191 -0
  22. package/src/components/button/MButton.stories.ts +66 -0
  23. package/src/components/button/MButton.vue +98 -154
  24. package/src/components/checkbox/MCheckbox.spec.ts +104 -0
  25. package/src/components/checkbox/MCheckbox.stories.ts +83 -0
  26. package/src/components/checkbox/MCheckbox.vue +60 -101
  27. package/src/components/checkboxgroup/MCheckboxGroup.spec.ts +78 -0
  28. package/src/components/checkboxgroup/MCheckboxGroup.stories.ts +61 -0
  29. package/src/components/checkboxgroup/MCheckboxGroup.vue +97 -0
  30. package/src/components/field/MField.spec.ts +166 -0
  31. package/src/components/field/MField.stories.ts +376 -0
  32. package/src/components/field/MField.vue +78 -61
  33. package/src/components/fieldgroup/MFieldGroup.spec.ts +165 -0
  34. package/src/components/fieldgroup/MFieldGroup.stories.ts +423 -0
  35. package/src/components/fieldgroup/MFieldGroup.vue +79 -0
  36. package/src/components/iconbutton/MIconButton.spec.ts +108 -0
  37. package/src/components/iconbutton/MIconButton.stories.ts +66 -0
  38. package/src/components/iconbutton/MIconButton.vue +73 -0
  39. package/src/components/link/MLink.spec.ts +154 -0
  40. package/src/components/link/MLink.stories.ts +98 -0
  41. package/src/components/link/MLink.vue +86 -109
  42. package/src/components/loader/MLoader.spec.ts +104 -0
  43. package/src/components/loader/MLoader.stories.ts +45 -0
  44. package/src/components/loader/MLoader.vue +65 -55
  45. package/src/components/overlay/MOverlay.spec.ts +51 -0
  46. package/src/components/overlay/MOverlay.stories.ts +40 -0
  47. package/src/components/overlay/MOverlay.vue +27 -19
  48. package/src/components/passwordinput/MPasswordInput.spec.ts +104 -0
  49. package/src/components/passwordinput/MPasswordInput.stories.ts +75 -0
  50. package/src/components/passwordinput/MPasswordInput.vue +129 -76
  51. package/src/components/quantityselector/MQuantitySelector.spec.ts +262 -0
  52. package/src/components/quantityselector/MQuantitySelector.stories.ts +89 -0
  53. package/src/components/quantityselector/MQuantitySelector.vue +160 -136
  54. package/src/components/radio/MRadio.spec.ts +104 -0
  55. package/src/components/radio/MRadio.stories.ts +68 -0
  56. package/src/components/radio/MRadio.vue +56 -39
  57. package/src/components/radiogroup/MRadioGroup.spec.ts +54 -0
  58. package/src/components/radiogroup/MRadioGroup.stories.ts +61 -0
  59. package/src/components/radiogroup/MRadioGroup.vue +79 -0
  60. package/src/components/select/MSelect.spec.ts +114 -0
  61. package/src/components/select/MSelect.stories.ts +101 -0
  62. package/src/components/select/MSelect.vue +77 -119
  63. package/src/components/statusbadge/MStatusBadge.stories.ts +45 -0
  64. package/src/components/statusbadge/MStatusBadge.vue +40 -0
  65. package/src/components/statusbadge/MstatusBadge.spec.ts +16 -0
  66. package/src/components/statusdot/MStatusDot.spec.ts +51 -0
  67. package/src/components/statusdot/MStatusDot.stories.ts +48 -0
  68. package/src/components/statusdot/MStatusDot.vue +36 -0
  69. package/src/components/statusnotification/MStatusNotification.spec.ts +99 -0
  70. package/src/components/statusnotification/MStatusNotification.stories.ts +96 -0
  71. package/src/components/statusnotification/MStatusNotification.vue +106 -0
  72. package/src/components/textarea/MTextArea.spec.ts +112 -0
  73. package/src/components/textarea/MTextArea.stories.ts +67 -0
  74. package/src/components/textarea/MTextArea.vue +81 -42
  75. package/src/components/textinput/MTextInput.spec.ts +121 -0
  76. package/src/components/textinput/MTextInput.stories.ts +114 -0
  77. package/src/components/textinput/MTextInput.vue +127 -47
  78. package/src/components/toggle/MToggle.spec.ts +99 -0
  79. package/src/components/toggle/MToggle.stories.ts +68 -0
  80. package/src/components/toggle/MToggle.vue +63 -103
  81. package/src/components/togglegroup/MToggleGroup.spec.ts +78 -0
  82. package/src/components/togglegroup/MToggleGroup.stories.ts +61 -0
  83. package/src/components/togglegroup/MToggleGroup.vue +97 -0
  84. package/src/components/usingIcons.mdx +43 -0
  85. package/src/components/usingPresets.mdx +125 -0
  86. package/src/main.ts +47 -0
  87. package/dist/demo.html +0 -1
  88. package/dist/mozaic-vue.adeo.css +0 -45
  89. package/dist/mozaic-vue.adeo.umd.js +0 -41775
  90. package/dist/mozaic-vue.common.js +0 -41765
  91. package/dist/mozaic-vue.common.js.map +0 -1
  92. package/dist/mozaic-vue.umd.js +0 -41776
  93. package/dist/mozaic-vue.umd.js.map +0 -1
  94. package/dist/mozaic-vue.umd.min.js +0 -4
  95. package/dist/mozaic-vue.umd.min.js.map +0 -1
  96. package/postinstall.js +0 -3
  97. package/src/components/accordion/MAccordion.vue +0 -128
  98. package/src/components/accordion/index.js +0 -7
  99. package/src/components/autocomplete/MAutocomplete.vue +0 -198
  100. package/src/components/autocomplete/index.js +0 -7
  101. package/src/components/badge/index.js +0 -7
  102. package/src/components/breadcrumb/index.js +0 -7
  103. package/src/components/button/index.js +0 -7
  104. package/src/components/card/MCard.vue +0 -78
  105. package/src/components/card/index.js +0 -7
  106. package/src/components/checkbox/MCheckboxGroup.vue +0 -155
  107. package/src/components/checkbox/index.js +0 -12
  108. package/src/components/container/MContainer.vue +0 -33
  109. package/src/components/container/index.js +0 -7
  110. package/src/components/datatable/MDataTable.vue +0 -651
  111. package/src/components/datatable/MDataTableHeader.vue +0 -55
  112. package/src/components/datatable/MDataTableTop.vue +0 -35
  113. package/src/components/datatable/helpers.js +0 -132
  114. package/src/components/datatable/index.js +0 -12
  115. package/src/components/field/index.js +0 -7
  116. package/src/components/fileuploader/MFileResult.vue +0 -149
  117. package/src/components/fileuploader/MFileUploader.vue +0 -142
  118. package/src/components/fileuploader/index.js +0 -7
  119. package/src/components/flag/MFlag.vue +0 -46
  120. package/src/components/flag/index.js +0 -7
  121. package/src/components/heading/MHeading.vue +0 -75
  122. package/src/components/heading/index.js +0 -7
  123. package/src/components/hero/MHero.vue +0 -93
  124. package/src/components/hero/index.js +0 -7
  125. package/src/components/icon/MIcon.vue +0 -120
  126. package/src/components/icon/index.js +0 -7
  127. package/src/components/index.js +0 -43
  128. package/src/components/layer/MLayer.vue +0 -208
  129. package/src/components/layer/index.js +0 -7
  130. package/src/components/link/index.js +0 -7
  131. package/src/components/listbox/MListBox.vue +0 -106
  132. package/src/components/listbox/index.js +0 -7
  133. package/src/components/loader/index.js +0 -7
  134. package/src/components/modal/MModal.vue +0 -179
  135. package/src/components/modal/index.js +0 -7
  136. package/src/components/notification/MNotification.vue +0 -110
  137. package/src/components/notification/index.js +0 -7
  138. package/src/components/optionbutton/MOptionButton.vue +0 -67
  139. package/src/components/optionbutton/index.js +0 -7
  140. package/src/components/optioncard/MOptionCard.vue +0 -132
  141. package/src/components/optioncard/index.js +0 -7
  142. package/src/components/optiongroup/MOptionGroup.vue +0 -18
  143. package/src/components/optiongroup/index.js +0 -7
  144. package/src/components/overlay/MOverlayLoader.vue +0 -43
  145. package/src/components/overlay/index.js +0 -12
  146. package/src/components/pagination/MPagination.vue +0 -162
  147. package/src/components/pagination/index.js +0 -7
  148. package/src/components/passwordinput/index.js +0 -7
  149. package/src/components/phonenumber/MPhoneNumber.vue +0 -390
  150. package/src/components/phonenumber/index.js +0 -7
  151. package/src/components/progressbar/MProgress.vue +0 -102
  152. package/src/components/progressbar/index.js +0 -7
  153. package/src/components/quantityselector/index.js +0 -7
  154. package/src/components/radio/MRadioGroup.vue +0 -111
  155. package/src/components/radio/index.js +0 -12
  156. package/src/components/ratingstars/MStarsInput.vue +0 -118
  157. package/src/components/ratingstars/MStarsResult.vue +0 -89
  158. package/src/components/ratingstars/index.js +0 -12
  159. package/src/components/select/index.js +0 -7
  160. package/src/components/stepper/MStepper.vue +0 -70
  161. package/src/components/stepper/index.js +0 -7
  162. package/src/components/tabs/MTab.vue +0 -184
  163. package/src/components/tabs/index.js +0 -7
  164. package/src/components/tags/MTag.vue +0 -173
  165. package/src/components/tags/index.js +0 -7
  166. package/src/components/textarea/index.js +0 -7
  167. package/src/components/textinput/MTextInputField.vue +0 -105
  168. package/src/components/textinput/MTextInputIcon.vue +0 -42
  169. package/src/components/textinput/index.js +0 -7
  170. package/src/components/toggle/index.js +0 -7
  171. package/src/components/tooltip/MTooltip.vue +0 -42
  172. package/src/components/tooltip/index.js +0 -7
  173. package/src/index.js +0 -62
  174. package/src/shims-tsx.d.ts +0 -13
  175. package/src/shims.vue.d.ts +0 -4
  176. package/src/tokens/adeo/android/colors.xml +0 -391
  177. package/src/tokens/adeo/android/font_dimens.xml +0 -18
  178. package/src/tokens/adeo/css/_variables.scss +0 -385
  179. package/src/tokens/adeo/css/root.scss +0 -387
  180. package/src/tokens/adeo/ios/StyleDictionaryColor.h +0 -399
  181. package/src/tokens/adeo/ios/StyleDictionaryColor.m +0 -411
  182. package/src/tokens/adeo/ios/StyleDictionaryColor.swift +0 -394
  183. package/src/tokens/adeo/ios/StyleDictionarySize.h +0 -69
  184. package/src/tokens/adeo/ios/StyleDictionarySize.m +0 -70
  185. package/src/tokens/adeo/ios/StyleDictionarySize.swift +0 -71
  186. package/src/tokens/adeo/js/tokens.js +0 -483
  187. package/src/tokens/adeo/js/tokensObject.js +0 -10354
  188. package/src/tokens/adeo/scss/_tokens.scss +0 -1300
  189. package/src/utils/mozaicClasses.js +0 -16
  190. package/src/utils/theme.validator.js +0 -19
  191. package/types/index.d.ts +0 -100
@@ -0,0 +1,376 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3';
2
+ import { action } from '@storybook/addon-actions';
3
+
4
+ import MField from './MField.vue';
5
+ import MTextInput from '../textinput/MTextInput.vue';
6
+ import MTextArea from '../textarea/MTextArea.vue';
7
+ import MSelect from '../select/MSelect.vue';
8
+
9
+ const meta: Meta<typeof MField> = {
10
+ title: 'Form Elements/Field',
11
+ component: MField,
12
+ parameters: {
13
+ docs: {
14
+ description: {
15
+ component:
16
+ 'A field label is a text element that identifies the purpose of an input field, providing users with clear guidance on what information to enter. It is typically placed above the input field and may include indicators for required or optional fields. Field Labels improve form usability, accessibility, and data entry accuracy by ensuring users understand the expected input.',
17
+ },
18
+ },
19
+ },
20
+ args: {
21
+ label: 'Label',
22
+ id: 'ReplaceByInputId',
23
+ default: `
24
+ <!-- All the code below must be replaced by a form element. -->
25
+ <div class="content-slot">
26
+ Insert a form element here to replace this slot.
27
+ </div>
28
+ `,
29
+ },
30
+ argTypes: {
31
+ $slots: {
32
+ table: {
33
+ disable: true,
34
+ },
35
+ },
36
+ },
37
+ render: (args) => ({
38
+ components: { MField, MTextInput },
39
+ setup() {
40
+ const handleUpdate = action('update:modelValue');
41
+
42
+ return { args, handleUpdate };
43
+ },
44
+ template: `
45
+ <MField v-bind="args">
46
+ ${args.default}
47
+ </MField>
48
+ `,
49
+ }),
50
+ };
51
+ export default meta;
52
+ type Story = StoryObj<typeof MField>;
53
+
54
+ export const Default: Story = {
55
+ render: (args) => ({
56
+ components: { MField },
57
+ setup() {
58
+ return { args };
59
+ },
60
+ template: `
61
+ <MField v-bind="args">
62
+ ${args.default}
63
+ </MField>
64
+ `,
65
+ }),
66
+ };
67
+
68
+ export const Input: Story = {
69
+ args: {
70
+ label: 'Label',
71
+ id: 'inputId',
72
+ default: `
73
+ <MTextInput
74
+ id="inputId"
75
+ placeholder="Placeholder"
76
+ @update:modelValue="handleUpdate"
77
+ />
78
+ `,
79
+ },
80
+ };
81
+
82
+ export const InputFull: Story = {
83
+ args: {
84
+ label: 'Label',
85
+ requirementText: 'optional',
86
+ helpText: 'Help text',
87
+ id: 'inputFullId',
88
+ default: `
89
+ <MTextInput
90
+ id="inputFullId"
91
+ placeholder="Placeholder"
92
+ @update:modelValue="handleUpdate"
93
+ />
94
+ `,
95
+ },
96
+ };
97
+
98
+ export const InputValid: Story = {
99
+ args: {
100
+ label: 'Label',
101
+ requirementText: 'required',
102
+ helpText: 'Help text',
103
+ id: 'inputvalidId',
104
+ isValid: true,
105
+ message: 'Validation message (Be concise and use comprehensive words).',
106
+ default: `
107
+ <MTextInput
108
+ id="inputvalidId"
109
+ placeholder="Placeholder"
110
+ @update:modelValue="handleUpdate"
111
+ />
112
+ `,
113
+ },
114
+ };
115
+
116
+ export const InputInvalid: Story = {
117
+ args: {
118
+ label: 'Label',
119
+ requirementText: 'required',
120
+ helpText: 'Help text',
121
+ id: 'inputInvalidId',
122
+ isInvalid: true,
123
+ message: 'Error message (Be concise and use comprehensive words)',
124
+ default: `
125
+ <MTextInput
126
+ id="inputInvalidId"
127
+ placeholder="Placeholder"
128
+ isInvalid
129
+ @update:modelValue="handleUpdate"
130
+ />
131
+ `,
132
+ },
133
+ };
134
+
135
+ export const Textarea: Story = {
136
+ args: {
137
+ label: 'Label',
138
+ id: 'textareaId',
139
+ default: `
140
+ <MTextArea
141
+ id="textareaId"
142
+ placeholder="Placeholder"
143
+ @update:modelValue="handleUpdate"
144
+ />
145
+ `,
146
+ },
147
+ render: (args) => ({
148
+ components: { MField, MTextArea },
149
+ setup() {
150
+ const handleUpdate = action('update:modelValue');
151
+
152
+ return { args, handleUpdate };
153
+ },
154
+ template: `
155
+ <MField v-bind="args">
156
+ ${args.default}
157
+ </MField>
158
+ `,
159
+ }),
160
+ };
161
+
162
+ export const TextareaValid: Story = {
163
+ args: {
164
+ label: 'Label',
165
+ id: 'textareaValidId',
166
+ requirementText: 'required',
167
+ helpText: 'Help text',
168
+ isValid: true,
169
+ message: 'Validation message (Be concise and use comprehensive words).',
170
+ default: `
171
+ <MTextArea
172
+ id="textareaValidId"
173
+ placeholder="Placeholder"
174
+ @update:modelValue="handleUpdate"
175
+ />
176
+ `,
177
+ },
178
+ render: (args) => ({
179
+ components: { MField, MTextArea },
180
+ setup() {
181
+ const handleUpdate = action('update:modelValue');
182
+
183
+ return { args, handleUpdate };
184
+ },
185
+ template: `
186
+ <MField v-bind="args">
187
+ ${args.default}
188
+ </MField>
189
+ `,
190
+ }),
191
+ };
192
+
193
+ export const TextareaInvalid: Story = {
194
+ args: {
195
+ label: 'Label',
196
+ id: 'textareaValidId',
197
+ requirementText: 'required',
198
+ helpText: 'Help text',
199
+ isInvalid: true,
200
+ message: 'Error message (Be concise and use comprehensive words)',
201
+ default: `
202
+ <MTextArea
203
+ id="textareaValidId"
204
+ isInvalid
205
+ placeholder="Placeholder"
206
+ @update:modelValue="handleUpdate"
207
+ />
208
+ `,
209
+ },
210
+ render: (args) => ({
211
+ components: { MField, MTextArea },
212
+ setup() {
213
+ const handleUpdate = action('update:modelValue');
214
+
215
+ return { args, handleUpdate };
216
+ },
217
+ template: `
218
+ <MField v-bind="args">
219
+ ${args.default}
220
+ </MField>
221
+ `,
222
+ }),
223
+ };
224
+
225
+ export const Select: Story = {
226
+ args: {
227
+ label: 'Label',
228
+ id: 'selectId',
229
+ default: `
230
+ <MSelect
231
+ id="selectId"
232
+ name="selectName"
233
+ placeholder="Choose an option"
234
+ :options="
235
+ [
236
+ {
237
+ text: 'Option 1',
238
+ value: 'option1',
239
+ },
240
+ {
241
+ text: 'Option 2',
242
+ value: 'option2',
243
+ },
244
+ {
245
+ text: 'Option 3',
246
+ value: 'option3',
247
+ },
248
+ {
249
+ text: 'Option 4',
250
+ value: 'option4',
251
+ },
252
+ ]
253
+ "
254
+ @update:modelValue="handleUpdate"
255
+ />
256
+ `,
257
+ },
258
+ render: (args) => ({
259
+ components: { MField, MSelect },
260
+ setup() {
261
+ const handleUpdate = action('update:modelValue');
262
+
263
+ return { args, handleUpdate };
264
+ },
265
+ template: `
266
+ <MField v-bind="args">
267
+ ${args.default}
268
+ </MField>
269
+ `,
270
+ }),
271
+ };
272
+
273
+ export const SelectValid: Story = {
274
+ args: {
275
+ label: 'Label',
276
+ id: 'selectValidId',
277
+ requirementText: 'required',
278
+ helpText: 'Help text',
279
+ isValid: true,
280
+ message: 'Validation message (Be concise and use comprehensive words).',
281
+ default: `
282
+ <MSelect
283
+ id="selectValidId"
284
+ name="selectValidName"
285
+ placeholder="Choose an option"
286
+ :options="
287
+ [
288
+ {
289
+ text: 'Option 1',
290
+ value: 'option1',
291
+ },
292
+ {
293
+ text: 'Option 2',
294
+ value: 'option2',
295
+ },
296
+ {
297
+ text: 'Option 3',
298
+ value: 'option3',
299
+ },
300
+ {
301
+ text: 'Option 4',
302
+ value: 'option4',
303
+ },
304
+ ]
305
+ "
306
+ @update:modelValue="handleUpdate"
307
+ />
308
+ `,
309
+ },
310
+ render: (args) => ({
311
+ components: { MField, MSelect },
312
+ setup() {
313
+ const handleUpdate = action('update:modelValue');
314
+
315
+ return { args, handleUpdate };
316
+ },
317
+ template: `
318
+ <MField v-bind="args">
319
+ ${args.default}
320
+ </MField>
321
+ `,
322
+ }),
323
+ };
324
+
325
+ export const SelectInvalid: Story = {
326
+ args: {
327
+ label: 'Label',
328
+ id: 'selectInvalidId',
329
+ requirementText: 'required',
330
+ helpText: 'Help text',
331
+ isInvalid: true,
332
+ message: 'Error message (Be concise and use comprehensive words)',
333
+ default: `
334
+ <MSelect
335
+ id="selectInvalidId"
336
+ name="selectInvalidName"
337
+ isInvalid
338
+ placeholder="Choose an option"
339
+ :options="
340
+ [
341
+ {
342
+ text: 'Option 1',
343
+ value: 'option1',
344
+ },
345
+ {
346
+ text: 'Option 2',
347
+ value: 'option2',
348
+ },
349
+ {
350
+ text: 'Option 3',
351
+ value: 'option3',
352
+ },
353
+ {
354
+ text: 'Option 4',
355
+ value: 'option4',
356
+ },
357
+ ]
358
+ "
359
+ @update:modelValue="handleUpdate"
360
+ />
361
+ `,
362
+ },
363
+ render: (args) => ({
364
+ components: { MField, MSelect },
365
+ setup() {
366
+ const handleUpdate = action('update:modelValue');
367
+
368
+ return { args, handleUpdate };
369
+ },
370
+ template: `
371
+ <MField v-bind="args">
372
+ ${args.default}
373
+ </MField>
374
+ `,
375
+ }),
376
+ };
@@ -1,73 +1,90 @@
1
1
  <template>
2
2
  <div class="mc-field">
3
- <label :for="id" class="mc-field__label">
3
+ <label class="mc-field__label" :for="id">
4
4
  {{ label }}
5
- <span
6
- v-if="requirementText"
7
- class="mc-field__requirement"
8
- aria-hidden="true"
5
+ <span v-if="requirementText" class="mc-field__requirement"
6
+ >({{ requirementText }})</span
9
7
  >
10
- {{ requirementText }}
11
- </span>
12
8
  </label>
13
- <span v-if="helpId && helpText" :id="helpId" class="mc-field__help">
14
- {{ helpText }}
15
- </span>
16
- <slot />
17
- <span v-if="isInvalid" :id="errorId" class="mc-field__error-message">
18
- {{ errorMessage }}
9
+
10
+ <span v-if="helpId && helpText" :id="helpId" class="mc-field__help">{{
11
+ helpText
12
+ }}</span>
13
+
14
+ <div class="mc-field__content">
15
+ <slot />
16
+ </div>
17
+
18
+ <span
19
+ v-if="(isValid || isInvalid) && message"
20
+ class="mc-field__validation-message"
21
+ :id="messageId"
22
+ :class="classObjectValidation"
23
+ >
24
+ {{ message }}
19
25
  </span>
20
26
  </div>
21
27
  </template>
22
28
 
23
- <script>
24
- export default {
25
- name: 'MField',
26
- provide: {
27
- cssFieldElementClass: 'mc-field__element',
28
- },
29
- props: {
30
- id: {
31
- type: String,
32
- required: true,
33
- },
34
- label: {
35
- type: String,
36
- required: true,
37
- },
38
- required: {
39
- type: Boolean,
40
- default: false,
41
- },
42
- requirementText: {
43
- type: String,
44
- default: null,
45
- },
46
- helpId: {
47
- type: String,
48
- default: null,
49
- },
50
- helpText: {
51
- type: String,
52
- default: null,
53
- },
54
- errorId: {
55
- type: String,
56
- default: null,
57
- },
58
- errorMessage: {
59
- type: String,
60
- default: null,
61
- },
62
- isInvalid: {
63
- type: Boolean,
64
- default: false,
65
- },
66
- },
67
- };
29
+ <script setup lang="ts">
30
+ import { computed, type VNode } from 'vue';
31
+ /**
32
+ * This component creates a structured form field with a label, optional help text, error and validation message handling.
33
+ */
34
+ const props = defineProps<{
35
+ /**
36
+ * A unique identifier for the form field, used to associate the label with the form element.
37
+ */
38
+ id: string;
39
+ /**
40
+ * The text displayed as the label for the form field.
41
+ */
42
+ label: string;
43
+ /**
44
+ * Additional text displayed alongside the label, typically used to indicate if the form field is required or optional
45
+ */
46
+ requirementText?: string;
47
+ /**
48
+ * Text shown below the form field to provide additional context or instructions for the user.
49
+ */
50
+ helpText?: string;
51
+ /**
52
+ * The value of the `id` attribute set on the **helpText** element. _This value is mandatory when using a helpText in order to guarantee the accessibility of the component._
53
+ */
54
+ helpId?: string;
55
+ /**
56
+ * If `true`, applies a valid state to the form field.
57
+ */
58
+ isValid?: boolean;
59
+ /**
60
+ * If `true`, applies an invalid state to the form field.
61
+ */
62
+ isInvalid?: boolean;
63
+ /**
64
+ * The value of the `id` attribute set on the **validationMessage** element. _This value is mandatory when using a validationMessage in order to guarantee the accessibility of the component._
65
+ */
66
+ messageId?: string;
67
+ /**
68
+ * message displayed when the form field has a valid or invalid state, usually indicating validation or errors.
69
+ */
70
+ message?: string;
71
+ }>();
72
+
73
+ defineSlots<{
74
+ /**
75
+ * Use this slot to insert the form element of your choice
76
+ */
77
+ default: VNode;
78
+ }>();
79
+
80
+ const classObjectValidation = computed(() => {
81
+ return {
82
+ 'is-valid': props.isValid,
83
+ 'is-invalid': props.isInvalid,
84
+ };
85
+ });
68
86
  </script>
69
87
 
70
- <style lang="scss">
71
- @import 'settings-tools/_all-settings';
72
- @import 'components/_c.fields';
88
+ <style lang="scss" scoped>
89
+ @use '@mozaic-ds/styles/components/field';
73
90
  </style>
@@ -0,0 +1,165 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import { describe, it, expect } from 'vitest';
3
+ import MFieldGroup from './MFieldGroup.vue';
4
+
5
+ describe('MFieldGroup component', () => {
6
+ it('should render label correctly', () => {
7
+ const wrapper = mount(MFieldGroup, {
8
+ props: {
9
+ id: 'input-id',
10
+ legend: 'Field Label',
11
+ },
12
+ });
13
+
14
+ const label = wrapper.find('legend');
15
+ expect(label.exists()).toBe(true);
16
+ expect(label.text()).toBe('Field Label');
17
+ });
18
+
19
+ it('should render requirement text if provided', () => {
20
+ const wrapper = mount(MFieldGroup, {
21
+ props: {
22
+ id: 'input-id',
23
+ legend: 'Field Label',
24
+ requirementText: 'required',
25
+ },
26
+ });
27
+
28
+ const requirementText = wrapper.find('.mc-field__requirement');
29
+ expect(requirementText.exists()).toBe(true);
30
+ expect(requirementText.text()).toBe('(required)');
31
+ });
32
+
33
+ it('should not render requirement text if not provided', () => {
34
+ const wrapper = mount(MFieldGroup, {
35
+ props: {
36
+ id: 'input-id',
37
+ legend: 'Field Label',
38
+ },
39
+ });
40
+
41
+ const requirementText = wrapper.find('.mc-field__requirement');
42
+ expect(requirementText.exists()).toBe(false);
43
+ });
44
+
45
+ it('should render help text if provided', () => {
46
+ const wrapper = mount(MFieldGroup, {
47
+ props: {
48
+ id: 'input-id',
49
+ legend: 'Field Label',
50
+ helpText: 'This is some help text.',
51
+ },
52
+ });
53
+
54
+ const helpText = wrapper.find('.mc-field__help');
55
+ expect(helpText.exists()).toBe(true);
56
+ expect(helpText.text()).toBe('This is some help text.');
57
+ });
58
+
59
+ it('should not render help text if not provided', () => {
60
+ const wrapper = mount(MFieldGroup, {
61
+ props: {
62
+ id: 'input-id',
63
+ legend: 'Field Label',
64
+ },
65
+ });
66
+
67
+ const helpText = wrapper.find('.mc-field__help');
68
+ expect(helpText.exists()).toBe(false);
69
+ });
70
+
71
+ it('should apply is-valid class when isValid prop is true', () => {
72
+ const wrapper = mount(MFieldGroup, {
73
+ props: {
74
+ id: 'input-id',
75
+ legend: 'Field Label',
76
+ isValid: true,
77
+ message: 'Valid input',
78
+ },
79
+ });
80
+
81
+ expect(wrapper.find('.mc-field__validation-message').classes()).toContain(
82
+ 'is-valid',
83
+ );
84
+ expect(wrapper.find('.mc-field__validation-message').text()).toBe(
85
+ 'Valid input',
86
+ );
87
+ });
88
+
89
+ it('should apply is-invalid class when isInvalid prop is true', () => {
90
+ const wrapper = mount(MFieldGroup, {
91
+ props: {
92
+ id: 'input-id',
93
+ legend: 'Field Label',
94
+ isInvalid: true,
95
+ message: 'Invalid input',
96
+ },
97
+ });
98
+
99
+ expect(wrapper.find('.mc-field__validation-message').classes()).toContain(
100
+ 'is-invalid',
101
+ );
102
+ expect(wrapper.find('.mc-field__validation-message').text()).toBe(
103
+ 'Invalid input',
104
+ );
105
+ });
106
+
107
+ it('should render a validation message only when isValid or isInvalid is true and message is provided', () => {
108
+ const wrapper = mount(MFieldGroup, {
109
+ props: {
110
+ id: 'input-id',
111
+ legend: 'Field Label',
112
+ isValid: true,
113
+ message: 'This is a valid input',
114
+ },
115
+ });
116
+
117
+ const validationMessage = wrapper.find('.mc-field__validation-message');
118
+ expect(validationMessage.exists()).toBe(true);
119
+ expect(validationMessage.text()).toBe('This is a valid input');
120
+ });
121
+
122
+ it('should render the form element passed in the slot', () => {
123
+ const wrapper = mount(MFieldGroup, {
124
+ props: {
125
+ id: 'input-id',
126
+ legend: 'Field Label',
127
+ },
128
+ slots: {
129
+ default: '<input type="text" />',
130
+ },
131
+ });
132
+
133
+ const input = wrapper.find('input');
134
+ expect(input.exists()).toBe(true);
135
+ expect(input.attributes('type')).toBe('text');
136
+ });
137
+
138
+ it('should render validation message when isInvalid is true and message is provided', () => {
139
+ const wrapper = mount(MFieldGroup, {
140
+ props: {
141
+ id: 'input-id',
142
+ legend: 'Field Label',
143
+ isInvalid: true,
144
+ message: 'There is an error',
145
+ },
146
+ });
147
+
148
+ const validationMessage = wrapper.find('.mc-field__validation-message');
149
+ expect(validationMessage.exists()).toBe(true);
150
+ expect(validationMessage.text()).toBe('There is an error');
151
+ });
152
+
153
+ it('should not render validation message when message is not provided', () => {
154
+ const wrapper = mount(MFieldGroup, {
155
+ props: {
156
+ id: 'input-id',
157
+ legend: 'Field Label',
158
+ isValid: true,
159
+ },
160
+ });
161
+
162
+ const validationMessage = wrapper.find('.mc-field__validation-message');
163
+ expect(validationMessage.exists()).toBe(false);
164
+ });
165
+ });