@zap-wunschlachen/wl-shared-components 1.0.51 → 1.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-wunschlachen/wl-shared-components",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -79,6 +79,7 @@ const props = withDefaults(defineProps<{
79
79
 
80
80
  const emit = defineEmits<{
81
81
  (event: "update:modelValue", value: string | null): void;
82
+ (event: "update:valid", isValid: boolean): void;
82
83
  }>();
83
84
 
84
85
  const { t } = useI18n();
@@ -118,6 +119,11 @@ onUnmounted(() => {
118
119
 
119
120
  const isDefaultLayout = computed(() => props.layout === "default")
120
121
 
122
+ // Emit validity changes when inputState changes
123
+ watch(inputState, (newState) => {
124
+ emit('update:valid', newState === 'success');
125
+ });
126
+
121
127
  // Error messages for invalid input
122
128
  const invalidCharMessage = computed(() => t('wl.date_input.invalid_char', 'Dieses Zeichen ist nicht erlaubt'));
123
129
  const formatErrorMessage = computed(() => t('wl.date_input.format_error', 'Das Datum muss im Format TT.MM.JJJJ sein'));
@@ -323,10 +329,14 @@ function onNativeDateChange(e: Event) {
323
329
  }
324
330
  }
325
331
 
332
+ // Computed property to expose isValid
333
+ const isValid = computed(() => inputState.value === 'success');
334
+
326
335
  defineExpose({
327
336
  focus: () => inputRef.value?.focus?.(),
328
337
  blur: () => inputRef.value?.blur?.(),
329
- select: () => inputRef.value?.select?.()
338
+ select: () => inputRef.value?.select?.(),
339
+ isValid
330
340
  })
331
341
  </script>
332
342
 
@@ -19,13 +19,13 @@
19
19
  hide-details
20
20
  :aria-invalid="state === ValidationState.ERROR"
21
21
  :countryIconMode="'svg'"
22
- @update:model-value="(value) => emit('update:phone', value)"
22
+ @update:model-value="onPhoneUpdate"
23
23
  data-testid="root"
24
24
  />
25
25
  </template>
26
26
 
27
27
  <script setup lang="ts">
28
- import { defineProps, PropType, ref, nextTick, computed, inject } from 'vue';
28
+ import { PropType, ref, nextTick, computed, inject } from 'vue';
29
29
  import { VPhoneInput } from 'v-phone-input';
30
30
  import './PhoneInput.css'
31
31
  import { siteColors } from "../../utils/index";
@@ -87,10 +87,21 @@ const props = defineProps({
87
87
 
88
88
  const emit = defineEmits<{
89
89
  (e: 'update:phone', value: string): void
90
+ (e: 'update:valid', isValid: boolean): void
90
91
  }>();
91
92
 
92
93
  const inputRef = ref(null)
93
94
 
95
+ // Handle phone input updates
96
+ const onPhoneUpdate = (value: string) => {
97
+ emit('update:phone', value);
98
+ // Check validity after the VPhoneInput has processed the value
99
+ nextTick(() => {
100
+ const valid = inputRef.value?.isValid ?? false;
101
+ emit('update:valid', valid);
102
+ });
103
+ };
104
+
94
105
  const getNativeInput = () => {
95
106
  return inputRef.value?.phoneInputRef?.$el?.querySelector('input');
96
107
  }
@@ -113,10 +124,14 @@ const focus = () => {
113
124
  });
114
125
  };
115
126
 
127
+ // Computed property to expose isValid from VPhoneInput
128
+ const isValid = computed(() => inputRef.value?.isValid ?? false);
129
+
116
130
  defineExpose({
117
131
  blur,
118
132
  select,
119
- focus
133
+ focus,
134
+ isValid
120
135
  });
121
136
 
122
137
  </script>