@zap-wunschlachen/wl-shared-components 1.0.76 → 1.0.78

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 (227) hide show
  1. package/.github/workflows/playwright.yml +229 -229
  2. package/.github/workflows/static.yml +61 -61
  3. package/.github/workflows/update-snapshots.yml +37 -37
  4. package/.prettierrc.json +8 -8
  5. package/.storybook/main.ts +18 -18
  6. package/.storybook/preview.ts +37 -37
  7. package/.storybook/storyWrapper.vue +18 -18
  8. package/.storybook/withVuetifyTheme.decorator.ts +21 -21
  9. package/App.vue +139 -139
  10. package/README.md +56 -56
  11. package/docs/assets.md +62 -62
  12. package/heroicons.ts +75 -75
  13. package/index.html +19 -19
  14. package/package.json +71 -71
  15. package/playwright.config.ts +48 -48
  16. package/public/background.svg +60 -60
  17. package/public/style.css +187 -187
  18. package/public/technologies.svg +22 -22
  19. package/scripts/check-translations.ts +352 -352
  20. package/src/assets/css/base.css +242 -242
  21. package/src/assets/css/variables.css +176 -176
  22. package/src/components/Accordion/Accordion.css +65 -65
  23. package/src/components/Accordion/AccordionGroup.vue +88 -88
  24. package/src/components/Accordion/AccordionItem.vue +272 -272
  25. package/src/components/Accordion/presets/default.css +4 -4
  26. package/src/components/Accordion/presets/elevated.css +25 -25
  27. package/src/components/Accordion/presets/filled.css +26 -26
  28. package/src/components/Accordion/presets/index.css +5 -5
  29. package/src/components/Accordion/presets/plain.css +34 -34
  30. package/src/components/Appointment/Card/Actions.css +54 -54
  31. package/src/components/Appointment/Card/Actions.vue +99 -99
  32. package/src/components/Appointment/Card/AnamneseNotification.css +20 -20
  33. package/src/components/Appointment/Card/AnamneseNotification.vue +23 -23
  34. package/src/components/Appointment/Card/Card.css +99 -99
  35. package/src/components/Appointment/Card/Card.vue +97 -97
  36. package/src/components/Appointment/Card/Details.css +62 -62
  37. package/src/components/Appointment/Card/Details.vue +44 -44
  38. package/src/components/Audio/Audio.vue +187 -187
  39. package/src/components/Audio/Waveform.vue +118 -118
  40. package/src/components/Banner/Banner.css +29 -29
  41. package/src/components/Banner/Banner.vue +89 -89
  42. package/src/components/Button/Button.vue +257 -257
  43. package/src/components/CheckBox/CheckBox.css +234 -234
  44. package/src/components/CheckBox/Checkbox.vue +184 -184
  45. package/src/components/DateInput/DateInput.css +2 -2
  46. package/src/components/DateInput/DateInput.vue +376 -370
  47. package/src/components/Dialog/Dialog.css +6 -6
  48. package/src/components/Dialog/Dialog.vue +46 -46
  49. package/src/components/EditField/EditField.css +19 -19
  50. package/src/components/EditField/EditField.vue +211 -211
  51. package/src/components/ErrorPage/ErrorPage.css +172 -172
  52. package/src/components/IconBullet/IconBullet.vue +104 -104
  53. package/src/components/IconBullet/IconBulletList.vue +55 -55
  54. package/src/components/Icons/AdvanceAppointments.vue +161 -161
  55. package/src/components/Icons/Audio/CloudFailed.vue +27 -27
  56. package/src/components/Icons/Audio/CloudSaved.vue +28 -28
  57. package/src/components/Icons/Audio/Delete.vue +22 -22
  58. package/src/components/Icons/Audio/Pause.vue +25 -25
  59. package/src/components/Icons/Audio/Play.vue +22 -22
  60. package/src/components/Icons/Calendar.vue +28 -28
  61. package/src/components/Icons/CalendarNotification.vue +137 -137
  62. package/src/components/Icons/Chair.vue +43 -43
  63. package/src/components/Icons/ChairNotification.vue +46 -46
  64. package/src/components/Icons/Circle.vue +66 -66
  65. package/src/components/Icons/FavIcon.vue +69 -69
  66. package/src/components/Icons/FilledCircle.vue +11 -11
  67. package/src/components/Icons/Group3.vue +57 -57
  68. package/src/components/Icons/Play.vue +16 -16
  69. package/src/components/Icons/RingNotification.vue +65 -65
  70. package/src/components/Icons/SolidArrowRight.vue +14 -14
  71. package/src/components/Icons/checkbox.vue +19 -19
  72. package/src/components/Icons/outlineChecked.vue +38 -38
  73. package/src/components/Input/Input.css +234 -234
  74. package/src/components/Input/Input.vue +281 -281
  75. package/src/components/Laboratory/AppointmentCard/AppointmentCard.css +7 -7
  76. package/src/components/Laboratory/AppointmentCard/AppointmentCard.vue +116 -116
  77. package/src/components/Laboratory/ChatBoxImage/ChatBoxImage.vue +81 -81
  78. package/src/components/Laboratory/ChatMessage/ChatMessage.vue +113 -113
  79. package/src/components/Laboratory/ChatMessage/ChatMessageBadge.css +4 -4
  80. package/src/components/Laboratory/ChatMessage/ChatMessageBadge.vue +99 -99
  81. package/src/components/Laboratory/ChatNotification/ChatNotification.vue +130 -130
  82. package/src/components/Laboratory/DocumentCard/DocumentCard.css +3 -3
  83. package/src/components/Laboratory/DocumentCard/DocumentCard.vue +50 -50
  84. package/src/components/Laboratory/DocumentCard/DocumentCardItem.vue +53 -53
  85. package/src/components/Laboratory/InfoCard/InfoCard.vue +162 -162
  86. package/src/components/Laboratory/MainColumnsBar/MainColumnsBar.vue +102 -102
  87. package/src/components/Laboratory/ProgressCircle/ProgressCircle.vue +152 -152
  88. package/src/components/Laboratory/ProgressLinear/ProgressLinear.css +33 -33
  89. package/src/components/Laboratory/ProgressLinear/ProgressLinear.vue +75 -75
  90. package/src/components/Laboratory/SelectionColumnBar/SelectionColumnBar.vue +92 -92
  91. package/src/components/Laboratory/StatusNotification/StatusNotification.vue +49 -49
  92. package/src/components/Laboratory/TagLabel/TagLabel.vue +126 -126
  93. package/src/components/Laboratory/TagLabelGroup/TagLabelGroup.vue +97 -97
  94. package/src/components/Laboratory/TicketCard/TicketCard.css +3 -3
  95. package/src/components/Laboratory/TicketCard/TicketCard.vue +143 -143
  96. package/src/components/Laboratory/TimeLine/TimeLineEvent.css +18 -18
  97. package/src/components/Laboratory/TimeLine/TimeLineEvent.vue +119 -119
  98. package/src/components/Laboratory/TimeLine/Timeline.css +4 -4
  99. package/src/components/Laboratory/TimeLine/Timeline.vue +30 -30
  100. package/src/components/Loader/Loader.css +78 -78
  101. package/src/components/MaintenanceBanner/MaintenanceBanner.css +353 -353
  102. package/src/components/MaintenanceBanner/MaintenanceBanner.vue +140 -140
  103. package/src/components/MaintenanceBanner/MaintenanceIllustration.vue +54 -54
  104. package/src/components/Modal/Modal.css +5 -5
  105. package/src/components/Modal/Modal.vue +29 -29
  106. package/src/components/NotificationBubble/NotificationBubble.css +4 -4
  107. package/src/components/NotificationBubble/NotificationBubble.vue +90 -90
  108. package/src/components/OtpInput/OtpInput.css +43 -43
  109. package/src/components/OtpInput/OtpInput.vue +181 -181
  110. package/src/components/PhoneInput/PhoneInput.css +151 -126
  111. package/src/components/PhoneInput/PhoneInput.vue +230 -139
  112. package/src/components/RadioGroup/RadioGroup.css +65 -0
  113. package/src/components/RadioGroup/RadioGroup.vue +134 -0
  114. package/src/components/Select/Select.css +172 -172
  115. package/src/components/Select/Select.vue +377 -377
  116. package/src/components/SelectAutocomplete/SelectAutocomplete.css +172 -172
  117. package/src/components/SelectAutocomplete/SelectAutocomplete.vue +414 -414
  118. package/src/components/TextArea/TextArea.css +269 -269
  119. package/src/components/TextArea/TextArea.vue +207 -207
  120. package/src/components/TickBox/TickBox.css +116 -116
  121. package/src/components/TickBox/TickBox.vue +172 -172
  122. package/src/components/Tile/Tile.css +106 -106
  123. package/src/components/Tile/Tile.vue +173 -173
  124. package/src/components/accessibility.css +218 -218
  125. package/src/components/index.ts +110 -109
  126. package/src/constants/iconEnums.ts +3 -3
  127. package/src/i18n/i18n.ts +15 -15
  128. package/src/i18n/locales/de.json +30 -30
  129. package/src/i18n/locales/en.json +30 -30
  130. package/src/index.ts +43 -43
  131. package/src/main.ts +11 -11
  132. package/src/pages/AccordionGroupPage.vue +873 -873
  133. package/src/pages/AllPage.vue +2483 -2365
  134. package/src/pages/SelectPage.vue +1302 -1302
  135. package/src/pages/TilePage.vue +902 -902
  136. package/src/plugins/vuetify.ts +54 -54
  137. package/src/shims-vue.d.ts +30 -30
  138. package/src/utils/index.ts +733 -733
  139. package/src/vite-env.d.ts +1 -1
  140. package/tests/unit/accessibility/component-a11y.spec.ts +657 -657
  141. package/tests/unit/components/Accordion/AccordionGroup.spec.ts +228 -228
  142. package/tests/unit/components/Accordion/AccordionItem.spec.ts +257 -257
  143. package/tests/unit/components/Appointment/AnamneseNotification.spec.ts +176 -176
  144. package/tests/unit/components/Appointment/Card/Actions.spec.ts +436 -436
  145. package/tests/unit/components/Appointment/Card/Card.spec.ts +531 -531
  146. package/tests/unit/components/Appointment/Card/Details.spec.ts +395 -395
  147. package/tests/unit/components/Audio/Audio.spec.ts +403 -403
  148. package/tests/unit/components/Audio/Waveform.spec.ts +483 -483
  149. package/tests/unit/components/Background/Background.spec.ts +177 -177
  150. package/tests/unit/components/Core/AnamneseAnswerDialog.spec.ts +344 -0
  151. package/tests/unit/components/Core/Banner.spec.ts +187 -0
  152. package/tests/unit/components/Core/Button.spec.ts +346 -346
  153. package/tests/unit/components/Core/Checkbox.spec.ts +544 -544
  154. package/tests/unit/components/Core/DateInput.spec.ts +702 -702
  155. package/tests/unit/components/Core/Dialog.spec.ts +448 -448
  156. package/tests/unit/components/Core/EditField.spec.ts +541 -541
  157. package/tests/unit/components/Core/Input.spec.ts +512 -512
  158. package/tests/unit/components/Core/List.spec.ts +163 -0
  159. package/tests/unit/components/Core/ListItem.spec.ts +205 -0
  160. package/tests/unit/components/Core/Modal.spec.ts +518 -518
  161. package/tests/unit/components/Core/NotificationBubble.spec.ts +606 -606
  162. package/tests/unit/components/Core/OtpInput.spec.ts +708 -708
  163. package/tests/unit/components/Core/PhoneInput.spec.ts +757 -619
  164. package/tests/unit/components/Core/RadioGroup.spec.ts +318 -0
  165. package/tests/unit/components/Core/Select.spec.ts +712 -712
  166. package/tests/unit/components/Core/SelectAutocomplete.spec.ts +361 -0
  167. package/tests/unit/components/Core/TextArea.spec.ts +565 -565
  168. package/tests/unit/components/Core/TickBox.spec.ts +836 -836
  169. package/tests/unit/components/Core/Tile.spec.ts +286 -0
  170. package/tests/unit/components/DateInput/DateInput.spec.ts +128 -0
  171. package/tests/unit/components/ErrorPage/ErrorPage.spec.ts +313 -313
  172. package/tests/unit/components/ErrorPage/ErrorPageLogo.spec.ts +153 -153
  173. package/tests/unit/components/IconBullet/IconBullet.spec.ts +356 -356
  174. package/tests/unit/components/IconBullet/IconBulletList.spec.ts +371 -371
  175. package/tests/unit/components/Icons/AdvanceAppointments.spec.ts +186 -186
  176. package/tests/unit/components/Icons/Audio/CloudFailed.spec.ts +108 -108
  177. package/tests/unit/components/Icons/Audio/CloudSaved.spec.ts +149 -149
  178. package/tests/unit/components/Icons/Audio/Delete.spec.ts +158 -158
  179. package/tests/unit/components/Icons/Audio/Pause.spec.ts +208 -208
  180. package/tests/unit/components/Icons/Audio/Play.spec.ts +217 -217
  181. package/tests/unit/components/Icons/CalendarNotification.spec.ts +193 -193
  182. package/tests/unit/components/Icons/Chair.spec.ts +241 -241
  183. package/tests/unit/components/Icons/ChairNotification.spec.ts +318 -318
  184. package/tests/unit/components/Icons/Circle.spec.ts +255 -255
  185. package/tests/unit/components/Icons/FavIcon.spec.ts +259 -259
  186. package/tests/unit/components/Icons/FilledCircle.spec.ts +274 -274
  187. package/tests/unit/components/Icons/Group3.spec.ts +362 -362
  188. package/tests/unit/components/Icons/Logo.spec.ts +229 -229
  189. package/tests/unit/components/Icons/MiniLogo.spec.ts +38 -38
  190. package/tests/unit/components/Icons/RingNotification.spec.ts +400 -400
  191. package/tests/unit/components/Icons/SolidArrowRight.spec.ts +49 -49
  192. package/tests/unit/components/Icons/calendar.spec.ts +293 -293
  193. package/tests/unit/components/Icons/checkbox.spec.ts +315 -315
  194. package/tests/unit/components/Icons/outlineChecked.spec.ts +441 -441
  195. package/tests/unit/components/Icons/play.spec.ts +315 -315
  196. package/tests/unit/components/Laboratory/AppointmentCard.spec.ts +167 -167
  197. package/tests/unit/components/Laboratory/ChatBoxImage.spec.ts +179 -179
  198. package/tests/unit/components/Laboratory/ChatMessage.spec.ts +263 -263
  199. package/tests/unit/components/Laboratory/ChatMessageBadge.spec.ts +282 -282
  200. package/tests/unit/components/Laboratory/ChatNotification.spec.ts +256 -256
  201. package/tests/unit/components/Laboratory/DocumentCard.spec.ts +228 -228
  202. package/tests/unit/components/Laboratory/DocumentCardItem.spec.ts +236 -236
  203. package/tests/unit/components/Laboratory/InfoCard.spec.ts +308 -308
  204. package/tests/unit/components/Laboratory/MainColumnsBar.spec.ts +251 -251
  205. package/tests/unit/components/Laboratory/ProgressCircle.spec.ts +290 -290
  206. package/tests/unit/components/Laboratory/ProgressLinear.spec.ts +275 -275
  207. package/tests/unit/components/Laboratory/SelectionColumnBar.spec.ts +288 -288
  208. package/tests/unit/components/Laboratory/StatusNotification.spec.ts +296 -296
  209. package/tests/unit/components/Laboratory/TagLabel.spec.ts +353 -353
  210. package/tests/unit/components/Laboratory/TagLabelGroup.spec.ts +377 -377
  211. package/tests/unit/components/Laboratory/TicketCard.spec.ts +351 -351
  212. package/tests/unit/components/Laboratory/TimeLineEvent.spec.ts +381 -381
  213. package/tests/unit/components/Laboratory/Timeline.spec.ts +419 -419
  214. package/tests/unit/components/Loader/Loader.spec.ts +197 -197
  215. package/tests/unit/components/MaintenanceBanner/MaintenanceBanner.spec.ts +302 -302
  216. package/tests/unit/constants/iconEnums.spec.ts +39 -39
  217. package/tests/unit/i18n/i18n.spec.ts +88 -88
  218. package/tests/unit/plugins/vuetify.spec.ts +182 -182
  219. package/tests/unit/setup.ts +237 -237
  220. package/tests/unit/src/components/index.spec.ts.skip +192 -192
  221. package/tests/unit/src/index.spec.ts.skip +182 -182
  222. package/tests/unit/src/main.spec.ts +111 -111
  223. package/tests/unit/utils/accessibility.spec.ts +318 -318
  224. package/tests/unit/utils/anamnese.spec.ts +531 -0
  225. package/tsconfig.json +26 -26
  226. package/vite.config.ts +29 -29
  227. package/vitest.config.ts +91 -91
@@ -1,371 +1,377 @@
1
- <template>
2
- <Input
3
- v-bind="$attrs"
4
- ref="inputRef"
5
- id="date-input"
6
- class="wl-date-input"
7
- :class="{
8
- 'edit-layout': layout === 'edit-field'
9
- }"
10
- :variant="variant"
11
- :placeholder="placeholder"
12
- v-model="formattedDate"
13
- :success="isDefaultLayout ? inputState === 'success' : false"
14
- :error="inputState === 'error'"
15
- @input="onDateInput"
16
- :hint="isDefaultLayout ? inputMessage : ''"
17
- :hideDetails="isDefaultLayout ? inputState !== 'error' : true"
18
- type="tel"
19
- for="date-input"
20
- data-testid="root">
21
- <template #append>
22
- <div class="date-wrapper" tabIndex="0" @keydown.enter.prevent="nativeDate?.showPicker()" >
23
- <v-icon class="date-icon" icon="heroicons:calendar" :color="colors['input_default_icon_color']" />
24
- <input
25
- ref="nativeDate"
26
- type="date"
27
- tabIndex="-1"
28
- :min="nativeMin"
29
- :max="nativeMax"
30
- class="native-date"
31
- :value="isoValue"
32
- @input.stop="onNativeDateChange"
33
- />
34
- </div>
35
- </template>
36
- </Input>
37
- </template>
38
-
39
- <script setup lang="ts">
40
- import {
41
- parse, parseISO, format, isValid, getHours,
42
- getMinutes,
43
- getSeconds,
44
- getMilliseconds,
45
- set,
46
- startOfDay
47
- } from "date-fns";
48
- import { ref, watch, defineProps, defineEmits, computed, nextTick, inject, onUnmounted } from "vue";
49
- import Input from "../Input/Input.vue";
50
- import './DateInput.css';
51
- import { useI18n } from 'vue-i18n';
52
- import { siteColors } from "../../utils/index";
53
-
54
- // Inject theme colors from ThemeProvider, fallback to global siteColors
55
- const injectedThemeColors = inject('themeColors', null);
56
- const colors = computed(() => {
57
- if (injectedThemeColors) {
58
- return (injectedThemeColors as any).value;
59
- }
60
- return siteColors;
61
- });
62
-
63
- // Define props to accept an initial date value
64
- const props = withDefaults(defineProps<{
65
- modelValue?: string | null;
66
- layout?: "default" | "edit-field";
67
- minDate?: Date | null;
68
- minDateErrorMessage?: string;
69
- maxDate?: Date | null;
70
- maxDateErrorMessage?: string;
71
- variant?: string;
72
- placeholder?: string;
73
- invalidDateErrorMessage?: string;
74
- }>(), {
75
- modelValue: null,
76
- layout: 'default',
77
- variant: 'outlined',
78
- });
79
-
80
- const emit = defineEmits<{
81
- (event: "update:modelValue", value: string | null): void;
82
- (event: "update:valid", isValid: boolean): void;
83
- }>();
84
-
85
- const { t } = useI18n();
86
-
87
- const placeholder = computed(() => props.placeholder || t('wl.date_input.placeholder', 'TT.MM.JJJJ'));
88
- const invalidDateMessage = computed(() => props.invalidDateErrorMessage || t('wl.date_input.invalid_date', 'Bitte ein gültiges Datum eingeben'));
89
- const maxDateMessage = computed(() => {
90
- if (props.maxDate && isValid(props.maxDate)) {
91
- return props.maxDateErrorMessage || t('wl.date_input.max_date_error', { date: format(props.maxDate, 'dd.MM.yyyy') });
92
- }
93
- return '';
94
- });
95
- const minDateMessage = computed(() => {
96
- if (props.minDate && isValid(props.minDate)) {
97
- return props.minDateErrorMessage || t('wl.date_input.min_date_error', { date: format(props.minDate, 'dd.MM.yyyy') });
98
- }
99
- return '';
100
- });
101
-
102
- const ISO_FORMAT = "yyyy-MM-dd";
103
- const DISPLAY_FORMAT = "dd.MM.yyyy";
104
-
105
- // Local reactive state for the input
106
- const formattedDate = ref("");
107
- const inputState = ref<"idle" | "error" | "success">("idle");
108
- const inputMessage = ref("");
109
- const nativeDate = ref<HTMLInputElement | null>(null)
110
- const inputRef = ref(null)
111
- const invalidCharTimeout = ref<ReturnType<typeof setTimeout> | null>(null)
112
-
113
- // Cleanup timeout on unmount
114
- onUnmounted(() => {
115
- if (invalidCharTimeout.value) {
116
- clearTimeout(invalidCharTimeout.value);
117
- }
118
- });
119
-
120
- const isDefaultLayout = computed(() => props.layout === "default")
121
-
122
- // Emit validity changes when inputState changes
123
- watch(inputState, (newState) => {
124
- emit('update:valid', newState === 'success');
125
- });
126
-
127
- // Error messages for invalid input
128
- const invalidCharMessage = computed(() => t('wl.date_input.invalid_char', 'Dieses Zeichen ist nicht erlaubt'));
129
- const formatErrorMessage = computed(() => t('wl.date_input.format_error', 'Das Datum muss im Format TT.MM.JJJJ sein'));
130
-
131
- const isoValue = computed(() => {
132
- const parsed = parse(formattedDate.value, DISPLAY_FORMAT, new Date());
133
- return isValid(parsed) ? format(parsed, ISO_FORMAT) : "";
134
- });
135
-
136
- watch(
137
- () => props.modelValue,
138
- (newDate) => {
139
- const parsed = parseISO(newDate ?? '');
140
- formattedDate.value = (parsed && isValid(parsed)) ? format(parsed, DISPLAY_FORMAT) : "";
141
- },
142
- { immediate: true }
143
- );
144
-
145
- const nativeMin = computed(() => {
146
- if (props.minDate && isValid(props.minDate)) {
147
- return format(props.minDate, ISO_FORMAT);
148
- }
149
- return "";
150
- });
151
-
152
- const nativeMax = computed(() => {
153
- if (props.maxDate && isValid(props.maxDate)) {
154
- return format(props.maxDate, ISO_FORMAT);
155
- }
156
- return "";
157
- });
158
-
159
- function onDateInput(e: Event) {
160
- const target = e.target as HTMLInputElement;
161
- const rawValue = target.value;
162
-
163
- // Clear any existing timeout
164
- if (invalidCharTimeout.value) {
165
- clearTimeout(invalidCharTimeout.value);
166
- invalidCharTimeout.value = null;
167
- }
168
-
169
- // Check for invalid characters (not digits or dots)
170
- const hasInvalidChars = /[^\d.]/.test(rawValue);
171
-
172
- if (hasInvalidChars) {
173
- // Show the invalid input temporarily with error message
174
- formattedDate.value = rawValue;
175
- inputState.value = "error";
176
- inputMessage.value = invalidCharMessage.value;
177
-
178
- // Remove invalid characters after 500ms
179
- invalidCharTimeout.value = setTimeout(() => {
180
- const cleanedValue = rawValue.replace(/[^\d]/g, "");
181
- formattedDate.value = formatDateValue(cleanedValue);
182
- validateAndEmit(formattedDate.value);
183
- }, 500);
184
- return;
185
- }
186
-
187
- // Check for invalid dot usage (dots are auto-inserted, so manual dots are invalid)
188
- // Valid format is: DD.MM.YYYY - dots should only appear at positions 2 and 5
189
- const dotCount = (rawValue.match(/\./g) || []).length;
190
- const hasConsecutiveDots = /\.\./.test(rawValue);
191
- const hasInvalidDots = dotCount > 0 && (
192
- hasConsecutiveDots ||
193
- dotCount > 2 ||
194
- (rawValue.indexOf('.') !== -1 && rawValue.indexOf('.') !== 2) ||
195
- (dotCount === 2 && rawValue.lastIndexOf('.') !== 5)
196
- );
197
-
198
- if (hasInvalidDots) {
199
- // Show the invalid input temporarily with error message
200
- formattedDate.value = rawValue;
201
- inputState.value = "error";
202
- inputMessage.value = invalidCharMessage.value;
203
-
204
- // Remove dots and reformat after 500ms
205
- invalidCharTimeout.value = setTimeout(() => {
206
- const cleanedValue = rawValue.replace(/\./g, "");
207
- formattedDate.value = formatDateValue(cleanedValue);
208
- validateAndEmit(formattedDate.value);
209
- }, 500);
210
- return;
211
- }
212
-
213
- // Check if input exceeds 10 characters (TT.MM.JJJJ format)
214
- if (rawValue.length > 10) {
215
- // Show the overlength input temporarily with error message
216
- formattedDate.value = rawValue;
217
- inputState.value = "error";
218
- inputMessage.value = formatErrorMessage.value;
219
-
220
- // Remove excess characters after 500ms
221
- invalidCharTimeout.value = setTimeout(() => {
222
- formattedDate.value = rawValue.slice(0, 10);
223
- validateAndEmit(formattedDate.value);
224
- }, 500);
225
- return;
226
- }
227
-
228
- // Format and validate normally
229
- const formattedValue = formatDateValue(rawValue.replace(/[^\d]/g, ""));
230
- formattedDate.value = formattedValue;
231
- validateAndEmit(formattedValue);
232
- }
233
-
234
- function formatDateValue(digitsOnly: string): string {
235
- let value = digitsOnly.replace(/\D/g, ""); // Keep only digits
236
-
237
- // Insert dot after day (2 digits)
238
- if (value.length > 2) {
239
- value = value.slice(0, 2) + "." + value.slice(2);
240
- }
241
- // Insert dot after month (next 2 digits)
242
- if (value.length > 5) {
243
- value = value.slice(0, 5) + "." + value.slice(5);
244
- }
245
- // Limit to 10 characters (DD.MM.YYYY)
246
- if (value.length > 10) {
247
- value = value.slice(0, 10);
248
- }
249
-
250
- return value;
251
- }
252
-
253
- function validateAndEmit(value: string) {
254
- // If incomplete date, reset state
255
- if (value.length < 10) {
256
- inputState.value = "idle";
257
- inputMessage.value = "";
258
- return;
259
- }
260
-
261
- // Parse the date using dots as separator
262
- const parsed = parseDateWithCurrentTime(value);
263
-
264
- if (!isValid(parsed)) {
265
- inputState.value = "error";
266
- inputMessage.value = invalidDateMessage.value;
267
- return;
268
- }
269
-
270
- if (props.minDate && isValid(props.minDate)) {
271
- if (startOfDay(parsed) < startOfDay(props.minDate)) {
272
- inputState.value = "error";
273
- inputMessage.value = minDateMessage.value;
274
- return;
275
- }
276
- }
277
-
278
- if(props.maxDate && isValid(props.maxDate)) {
279
- if (startOfDay(parsed) > startOfDay(props.maxDate)) {
280
- inputState.value = "error";
281
- inputMessage.value = maxDateMessage.value;
282
- return;
283
- }
284
- }
285
-
286
- inputState.value = "success";
287
- inputMessage.value = "";
288
-
289
- emit("update:modelValue", parsed.toISOString());
290
- }
291
-
292
- /**
293
- * Parse "dd.MM.yyyy" as a date, then apply the current local time (H:M:S.ms).
294
- * Returns a new Date object.
295
- */
296
- function parseDateWithCurrentTime(dateString: any) {
297
- const now = new Date();
298
-
299
- // 1) Parse date portion (defaults to midnight)
300
- const parsedDate = parse(dateString, DISPLAY_FORMAT, now);
301
-
302
- // 2) Overwrite the parsed date's time with the current local time
303
- const result = set(parsedDate, {
304
- hours: getHours(now),
305
- minutes: getMinutes(now),
306
- seconds: getSeconds(now),
307
- milliseconds: getMilliseconds(now)
308
- });
309
-
310
- return result;
311
- }
312
-
313
- function onNativeDateChange(e: Event) {
314
- if (!nativeDate.value) return;
315
-
316
- const [year, month, day] = nativeDate.value.value.split("-");
317
- const reformatted = `${day}.${month}.${year}`;
318
- const fakeEvent = { target: { value: reformatted } } as unknown as Event;
319
-
320
- onDateInput(fakeEvent);
321
-
322
- if (props.layout === 'edit-field') {
323
- // When DateInput is used in EditField, clicking events in the native picker removes focus from EditField.
324
- // Since saving is based on blur in EditField, we need to restore focus and then blur to trigger save.
325
- nextTick(() => {
326
- inputRef.value?.focus?.();
327
- inputRef.value?.blur?.();
328
- });
329
- }
330
- }
331
-
332
- // Computed property to expose validity status
333
- const isDateValid = computed(() => inputState.value === 'success');
334
-
335
- defineExpose({
336
- focus: () => inputRef.value?.focus?.(),
337
- blur: () => inputRef.value?.blur?.(),
338
- select: () => inputRef.value?.select?.(),
339
- isValid: isDateValid
340
- })
341
- </script>
342
-
343
- <style scoped>
344
- .native-date {
345
- position: absolute;
346
- top: 0;
347
- left: 0;
348
- width: 100%;
349
- height: 100%;
350
- opacity: 0 !important;
351
- background: transparent;
352
- color: transparent;
353
- cursor: pointer;
354
- z-index: 2;
355
- }
356
-
357
- .date-wrapper {
358
- position: relative;
359
- width: 100%;
360
- height: 100%;
361
- display: inline-flex;
362
- align-items: center;
363
- justify-content: center;
364
- }
365
-
366
- .date-icon {
367
- pointer-events: none;
368
- cursor: pointer;
369
- z-index: 1;
370
- }
1
+ <template>
2
+ <Input
3
+ v-bind="$attrs"
4
+ ref="inputRef"
5
+ id="date-input"
6
+ class="wl-date-input"
7
+ :class="{
8
+ 'edit-layout': layout === 'edit-field'
9
+ }"
10
+ :variant="variant"
11
+ :placeholder="placeholder"
12
+ v-model="formattedDate"
13
+ :success="isDefaultLayout ? inputState === 'success' && !props.error : false"
14
+ :error="inputState === 'error' || props.error"
15
+ @input="onDateInput"
16
+ :hint="isDefaultLayout ? (inputState === 'error' ? inputMessage : (props.error ? props.errorMessage : '')) : ''"
17
+ :hideDetails="isDefaultLayout ? !(inputState === 'error' || props.error) : true"
18
+ type="tel"
19
+ for="date-input"
20
+ data-testid="root">
21
+ <template #append>
22
+ <div class="date-wrapper" tabIndex="0" @keydown.enter.prevent="nativeDate?.showPicker()" >
23
+ <v-icon class="date-icon" icon="heroicons:calendar" :color="colors['input_default_icon_color']" />
24
+ <input
25
+ ref="nativeDate"
26
+ type="date"
27
+ tabIndex="-1"
28
+ :min="nativeMin"
29
+ :max="nativeMax"
30
+ class="native-date"
31
+ :value="isoValue"
32
+ @input.stop="onNativeDateChange"
33
+ />
34
+ </div>
35
+ </template>
36
+ </Input>
37
+ </template>
38
+
39
+ <script setup lang="ts">
40
+ import {
41
+ parse, parseISO, format, isValid, getHours,
42
+ getMinutes,
43
+ getSeconds,
44
+ getMilliseconds,
45
+ set,
46
+ startOfDay
47
+ } from "date-fns";
48
+ import { ref, watch, defineProps, defineEmits, computed, nextTick, inject, onUnmounted } from "vue";
49
+ import Input from "../Input/Input.vue";
50
+ import './DateInput.css';
51
+ import { useI18n } from 'vue-i18n';
52
+ import { siteColors } from "../../utils/index";
53
+
54
+ // Inject theme colors from ThemeProvider, fallback to global siteColors
55
+ const injectedThemeColors = inject('themeColors', null);
56
+ const colors = computed(() => {
57
+ if (injectedThemeColors) {
58
+ return (injectedThemeColors as any).value;
59
+ }
60
+ return siteColors;
61
+ });
62
+
63
+ // Define props to accept an initial date value
64
+ const props = withDefaults(defineProps<{
65
+ modelValue?: string | null;
66
+ layout?: "default" | "edit-field";
67
+ minDate?: Date | null;
68
+ minDateErrorMessage?: string;
69
+ maxDate?: Date | null;
70
+ maxDateErrorMessage?: string;
71
+ variant?: string;
72
+ placeholder?: string;
73
+ invalidDateErrorMessage?: string;
74
+ /** External error override (e.g. for "required" validation). Internal errors take priority. */
75
+ error?: boolean;
76
+ /** Error message shown when external error is active and no internal error exists. */
77
+ errorMessage?: string;
78
+ }>(), {
79
+ modelValue: null,
80
+ layout: 'default',
81
+ variant: 'outlined',
82
+ error: false,
83
+ errorMessage: '',
84
+ });
85
+
86
+ const emit = defineEmits<{
87
+ (event: "update:modelValue", value: string | null): void;
88
+ (event: "update:valid", isValid: boolean): void;
89
+ }>();
90
+
91
+ const { t } = useI18n();
92
+
93
+ const placeholder = computed(() => props.placeholder || t('wl.date_input.placeholder', 'TT.MM.JJJJ'));
94
+ const invalidDateMessage = computed(() => props.invalidDateErrorMessage || t('wl.date_input.invalid_date', 'Bitte ein gültiges Datum eingeben'));
95
+ const maxDateMessage = computed(() => {
96
+ if (props.maxDate && isValid(props.maxDate)) {
97
+ return props.maxDateErrorMessage || t('wl.date_input.max_date_error', { date: format(props.maxDate, 'dd.MM.yyyy') });
98
+ }
99
+ return '';
100
+ });
101
+ const minDateMessage = computed(() => {
102
+ if (props.minDate && isValid(props.minDate)) {
103
+ return props.minDateErrorMessage || t('wl.date_input.min_date_error', { date: format(props.minDate, 'dd.MM.yyyy') });
104
+ }
105
+ return '';
106
+ });
107
+
108
+ const ISO_FORMAT = "yyyy-MM-dd";
109
+ const DISPLAY_FORMAT = "dd.MM.yyyy";
110
+
111
+ // Local reactive state for the input
112
+ const formattedDate = ref("");
113
+ const inputState = ref<"idle" | "error" | "success">("idle");
114
+ const inputMessage = ref("");
115
+ const nativeDate = ref<HTMLInputElement | null>(null)
116
+ const inputRef = ref(null)
117
+ const invalidCharTimeout = ref<ReturnType<typeof setTimeout> | null>(null)
118
+
119
+ // Cleanup timeout on unmount
120
+ onUnmounted(() => {
121
+ if (invalidCharTimeout.value) {
122
+ clearTimeout(invalidCharTimeout.value);
123
+ }
124
+ });
125
+
126
+ const isDefaultLayout = computed(() => props.layout === "default")
127
+
128
+ // Emit validity changes when inputState or external error changes
129
+ watch([inputState, () => props.error], ([newState, extError]) => {
130
+ emit('update:valid', newState === 'success' && !extError);
131
+ });
132
+
133
+ // Error messages for invalid input
134
+ const invalidCharMessage = computed(() => t('wl.date_input.invalid_char', 'Dieses Zeichen ist nicht erlaubt'));
135
+ const formatErrorMessage = computed(() => t('wl.date_input.format_error', 'Das Datum muss im Format TT.MM.JJJJ sein'));
136
+
137
+ const isoValue = computed(() => {
138
+ const parsed = parse(formattedDate.value, DISPLAY_FORMAT, new Date());
139
+ return isValid(parsed) ? format(parsed, ISO_FORMAT) : "";
140
+ });
141
+
142
+ watch(
143
+ () => props.modelValue,
144
+ (newDate) => {
145
+ const parsed = parseISO(newDate ?? '');
146
+ formattedDate.value = (parsed && isValid(parsed)) ? format(parsed, DISPLAY_FORMAT) : "";
147
+ },
148
+ { immediate: true }
149
+ );
150
+
151
+ const nativeMin = computed(() => {
152
+ if (props.minDate && isValid(props.minDate)) {
153
+ return format(props.minDate, ISO_FORMAT);
154
+ }
155
+ return "";
156
+ });
157
+
158
+ const nativeMax = computed(() => {
159
+ if (props.maxDate && isValid(props.maxDate)) {
160
+ return format(props.maxDate, ISO_FORMAT);
161
+ }
162
+ return "";
163
+ });
164
+
165
+ function onDateInput(e: Event) {
166
+ const target = e.target as HTMLInputElement;
167
+ const rawValue = target.value;
168
+
169
+ // Clear any existing timeout
170
+ if (invalidCharTimeout.value) {
171
+ clearTimeout(invalidCharTimeout.value);
172
+ invalidCharTimeout.value = null;
173
+ }
174
+
175
+ // Check for invalid characters (not digits or dots)
176
+ const hasInvalidChars = /[^\d.]/.test(rawValue);
177
+
178
+ if (hasInvalidChars) {
179
+ // Show the invalid input temporarily with error message
180
+ formattedDate.value = rawValue;
181
+ inputState.value = "error";
182
+ inputMessage.value = invalidCharMessage.value;
183
+
184
+ // Remove invalid characters after 500ms
185
+ invalidCharTimeout.value = setTimeout(() => {
186
+ const cleanedValue = rawValue.replace(/[^\d]/g, "");
187
+ formattedDate.value = formatDateValue(cleanedValue);
188
+ validateAndEmit(formattedDate.value);
189
+ }, 500);
190
+ return;
191
+ }
192
+
193
+ // Check for invalid dot usage (dots are auto-inserted, so manual dots are invalid)
194
+ // Valid format is: DD.MM.YYYY - dots should only appear at positions 2 and 5
195
+ const dotCount = (rawValue.match(/\./g) || []).length;
196
+ const hasConsecutiveDots = /\.\./.test(rawValue);
197
+ const hasInvalidDots = dotCount > 0 && (
198
+ hasConsecutiveDots ||
199
+ dotCount > 2 ||
200
+ (rawValue.indexOf('.') !== -1 && rawValue.indexOf('.') !== 2) ||
201
+ (dotCount === 2 && rawValue.lastIndexOf('.') !== 5)
202
+ );
203
+
204
+ if (hasInvalidDots) {
205
+ // Show the invalid input temporarily with error message
206
+ formattedDate.value = rawValue;
207
+ inputState.value = "error";
208
+ inputMessage.value = invalidCharMessage.value;
209
+
210
+ // Remove dots and reformat after 500ms
211
+ invalidCharTimeout.value = setTimeout(() => {
212
+ const cleanedValue = rawValue.replace(/\./g, "");
213
+ formattedDate.value = formatDateValue(cleanedValue);
214
+ validateAndEmit(formattedDate.value);
215
+ }, 500);
216
+ return;
217
+ }
218
+
219
+ // Check if input exceeds 10 characters (TT.MM.JJJJ format)
220
+ if (rawValue.length > 10) {
221
+ // Show the overlength input temporarily with error message
222
+ formattedDate.value = rawValue;
223
+ inputState.value = "error";
224
+ inputMessage.value = formatErrorMessage.value;
225
+
226
+ // Remove excess characters after 500ms
227
+ invalidCharTimeout.value = setTimeout(() => {
228
+ formattedDate.value = rawValue.slice(0, 10);
229
+ validateAndEmit(formattedDate.value);
230
+ }, 500);
231
+ return;
232
+ }
233
+
234
+ // Format and validate normally
235
+ const formattedValue = formatDateValue(rawValue.replace(/[^\d]/g, ""));
236
+ formattedDate.value = formattedValue;
237
+ validateAndEmit(formattedValue);
238
+ }
239
+
240
+ function formatDateValue(digitsOnly: string): string {
241
+ let value = digitsOnly.replace(/\D/g, ""); // Keep only digits
242
+
243
+ // Insert dot after day (2 digits)
244
+ if (value.length > 2) {
245
+ value = value.slice(0, 2) + "." + value.slice(2);
246
+ }
247
+ // Insert dot after month (next 2 digits)
248
+ if (value.length > 5) {
249
+ value = value.slice(0, 5) + "." + value.slice(5);
250
+ }
251
+ // Limit to 10 characters (DD.MM.YYYY)
252
+ if (value.length > 10) {
253
+ value = value.slice(0, 10);
254
+ }
255
+
256
+ return value;
257
+ }
258
+
259
+ function validateAndEmit(value: string) {
260
+ // If incomplete date, reset state
261
+ if (value.length < 10) {
262
+ inputState.value = "idle";
263
+ inputMessage.value = "";
264
+ return;
265
+ }
266
+
267
+ // Parse the date using dots as separator
268
+ const parsed = parseDateWithCurrentTime(value);
269
+
270
+ if (!isValid(parsed)) {
271
+ inputState.value = "error";
272
+ inputMessage.value = invalidDateMessage.value;
273
+ return;
274
+ }
275
+
276
+ if (props.minDate && isValid(props.minDate)) {
277
+ if (startOfDay(parsed) < startOfDay(props.minDate)) {
278
+ inputState.value = "error";
279
+ inputMessage.value = minDateMessage.value;
280
+ return;
281
+ }
282
+ }
283
+
284
+ if(props.maxDate && isValid(props.maxDate)) {
285
+ if (startOfDay(parsed) > startOfDay(props.maxDate)) {
286
+ inputState.value = "error";
287
+ inputMessage.value = maxDateMessage.value;
288
+ return;
289
+ }
290
+ }
291
+
292
+ inputState.value = "success";
293
+ inputMessage.value = "";
294
+
295
+ emit("update:modelValue", parsed.toISOString());
296
+ }
297
+
298
+ /**
299
+ * Parse "dd.MM.yyyy" as a date, then apply the current local time (H:M:S.ms).
300
+ * Returns a new Date object.
301
+ */
302
+ function parseDateWithCurrentTime(dateString: any) {
303
+ const now = new Date();
304
+
305
+ // 1) Parse date portion (defaults to midnight)
306
+ const parsedDate = parse(dateString, DISPLAY_FORMAT, now);
307
+
308
+ // 2) Overwrite the parsed date's time with the current local time
309
+ const result = set(parsedDate, {
310
+ hours: getHours(now),
311
+ minutes: getMinutes(now),
312
+ seconds: getSeconds(now),
313
+ milliseconds: getMilliseconds(now)
314
+ });
315
+
316
+ return result;
317
+ }
318
+
319
+ function onNativeDateChange(e: Event) {
320
+ if (!nativeDate.value) return;
321
+
322
+ const [year, month, day] = nativeDate.value.value.split("-");
323
+ const reformatted = `${day}.${month}.${year}`;
324
+ const fakeEvent = { target: { value: reformatted } } as unknown as Event;
325
+
326
+ onDateInput(fakeEvent);
327
+
328
+ if (props.layout === 'edit-field') {
329
+ // When DateInput is used in EditField, clicking events in the native picker removes focus from EditField.
330
+ // Since saving is based on blur in EditField, we need to restore focus and then blur to trigger save.
331
+ nextTick(() => {
332
+ inputRef.value?.focus?.();
333
+ inputRef.value?.blur?.();
334
+ });
335
+ }
336
+ }
337
+
338
+ // Computed property to expose validity status
339
+ const isDateValid = computed(() => inputState.value === 'success');
340
+
341
+ defineExpose({
342
+ focus: () => inputRef.value?.focus?.(),
343
+ blur: () => inputRef.value?.blur?.(),
344
+ select: () => inputRef.value?.select?.(),
345
+ isValid: isDateValid
346
+ })
347
+ </script>
348
+
349
+ <style scoped>
350
+ .native-date {
351
+ position: absolute;
352
+ top: 0;
353
+ left: 0;
354
+ width: 100%;
355
+ height: 100%;
356
+ opacity: 0 !important;
357
+ background: transparent;
358
+ color: transparent;
359
+ cursor: pointer;
360
+ z-index: 2;
361
+ }
362
+
363
+ .date-wrapper {
364
+ position: relative;
365
+ width: 100%;
366
+ height: 100%;
367
+ display: inline-flex;
368
+ align-items: center;
369
+ justify-content: center;
370
+ }
371
+
372
+ .date-icon {
373
+ pointer-events: none;
374
+ cursor: pointer;
375
+ z-index: 1;
376
+ }
371
377
  </style>