edvoyui-component-library-test-flight 0.0.239 → 0.0.240

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.
@@ -184,10 +184,10 @@ declare const __VLS_component: import('../../../node_modules/vue').DefineCompone
184
184
  search: (...args: any[]) => void;
185
185
  "update:modelValue": (...args: any[]) => void;
186
186
  tag: (...args: any[]) => void;
187
+ open: (...args: any[]) => void;
187
188
  "update:searchString": (...args: any[]) => void;
188
189
  deselected: (...args: any[]) => void;
189
190
  selectedOption: (...args: any[]) => void;
190
- open: (...args: any[]) => void;
191
191
  }, string, import('../../../node_modules/vue').PublicProps, Readonly<import('../../../node_modules/vue').ExtractPropTypes<{
192
192
  clearable: {
193
193
  type: BooleanConstructor;
@@ -350,10 +350,10 @@ declare const __VLS_component: import('../../../node_modules/vue').DefineCompone
350
350
  onSearch?: ((...args: any[]) => any) | undefined;
351
351
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
352
352
  onTag?: ((...args: any[]) => any) | undefined;
353
+ onOpen?: ((...args: any[]) => any) | undefined;
353
354
  "onUpdate:searchString"?: ((...args: any[]) => any) | undefined;
354
355
  onDeselected?: ((...args: any[]) => any) | undefined;
355
356
  onSelectedOption?: ((...args: any[]) => any) | undefined;
356
- onOpen?: ((...args: any[]) => any) | undefined;
357
357
  }>, {
358
358
  keys: string[];
359
359
  loading: boolean;
@@ -73,9 +73,18 @@
73
73
 
74
74
  <script lang="ts" setup>
75
75
  import { computed, onUpdated, PropType, ref, toRefs, watch } from "vue";
76
- import { VueTelInput, VueTelInputCountryOption } from "vue-tel-input";
76
+ import {
77
+ VueTelInput,
78
+ type CountryObject,
79
+ type PhoneMeta,
80
+ type VueTelInputProps,
81
+ } from "vue-tel-input";
82
+ import { getExampleNumber } from "libphonenumber-js";
83
+ import mobileExamples from "libphonenumber-js/mobile/examples";
77
84
  import "vue-tel-input/vue-tel-input.css";
78
85
 
86
+ type TelephoneInputMeta = PhoneMeta & { number: string };
87
+
79
88
  const emit = defineEmits(["update:modelValue", "blur", "update:isValid"]);
80
89
 
81
90
  const props = defineProps({
@@ -160,21 +169,45 @@ const inputValue = computed(() => {
160
169
  return props.modelValue === 0 ? true : !!props.modelValue;
161
170
  });
162
171
 
163
- const mobile = ref(props.modelValue);
172
+ const mobile = ref(String(props.modelValue ?? ""));
164
173
  const isTouched = ref(false);
165
174
  const telephoneIsValid = ref(props.isValid);
175
+ const activeCountry = ref<CountryObject | null>(null);
176
+ const dynamicMaxLength = ref<number>(props.length);
177
+ const getCountryMaxLength = (
178
+ country: CountryObject | PhoneMeta["country"] | null,
179
+ ) => {
180
+ if (!country) return props.length;
181
+
182
+ const countryCode = typeof country === "string" ? country : country.iso2;
183
+ const example = getExampleNumber(countryCode, mobileExamples);
184
+ if (!example) return props.length;
185
+
186
+ return Math.max(
187
+ example.nationalNumber.length + 5,
188
+ example.formatInternational().length,
189
+ );
190
+ };
166
191
  const listener = computed(() => props.modelValue);
167
192
  watch(listener, (value) => {
168
- mobile.value = value;
193
+ mobile.value = String(value ?? "");
169
194
  });
170
195
  watch(isValid, (value) => {
171
196
  telephoneIsValid.value = value;
172
197
  });
198
+ watch(
199
+ () => props.length,
200
+ (value) => {
201
+ if (!activeCountry.value) {
202
+ dynamicMaxLength.value = value;
203
+ }
204
+ },
205
+ );
173
206
 
174
207
  // Make bindProps a reactive computed property
175
- const bindProps = computed(() => ({
208
+ const bindProps = computed<VueTelInputProps>(() => ({
176
209
  mode: "international",
177
- autoFormat: false,
210
+ autoFormat: true,
178
211
  autoDefaultCountry: true,
179
212
  styleClasses: "eui-tel",
180
213
  invalidMsg: "Required mobile number",
@@ -187,7 +220,7 @@ const bindProps = computed(() => ({
187
220
  name: props.name,
188
221
  id: id,
189
222
  placeholder: props.placeholder,
190
- maxlength: props.length,
223
+ maxlength: dynamicMaxLength.value,
191
224
  showDialCode: true,
192
225
  tabindex: 0,
193
226
  readonly: props.readonly,
@@ -203,9 +236,17 @@ const bindProps = computed(() => ({
203
236
  },
204
237
  }));
205
238
 
206
- const onInputChanged = (_formattedNumber: string, phoneObject: any) => {
239
+ const onInputChanged = (
240
+ _formattedNumber: string,
241
+ phoneObject: TelephoneInputMeta,
242
+ ) => {
207
243
  telephoneIsValid.value = Boolean(phoneObject.valid);
208
244
  hasError.value = telephoneIsValid.value;
245
+
246
+ dynamicMaxLength.value = getCountryMaxLength(
247
+ activeCountry.value ?? phoneObject.country ?? null,
248
+ );
249
+
209
250
  emit("update:modelValue", phoneObject.number);
210
251
  };
211
252
 
@@ -215,7 +256,9 @@ const onBlur = () => {
215
256
  };
216
257
 
217
258
  const firstTime = ref(true);
218
- const onCountryChanged = (_event: VueTelInputCountryOption) => {
259
+ const onCountryChanged = (country: CountryObject) => {
260
+ activeCountry.value = country;
261
+ dynamicMaxLength.value = getCountryMaxLength(country);
219
262
  if (!firstTime.value) {
220
263
  emit("update:modelValue", "");
221
264
  }
@@ -135,5 +135,5 @@ declare const _default: import('../../../node_modules/vue').DefineComponent<impo
135
135
  cols: number;
136
136
  }, {}, {}, {}, string, import('../../../node_modules/vue').ComponentProvideOptions, true, {
137
137
  inputRef: HTMLTextAreaElement;
138
- }, any>;
138
+ }, HTMLDivElement>;
139
139
  export default _default;
@@ -60,10 +60,10 @@
60
60
  >
61
61
  </textarea>
62
62
  </div>
63
- </div>
64
- <template v-if="errors && Object.keys(errors).length">
63
+ <template v-if="errors && Object.keys(errors).length">
65
64
  <EUIErrorMessage :errors="errors" :name="name" />
66
65
  </template>
66
+ </div>
67
67
  </template>
68
68
  <script setup lang="ts">
69
69
  import { PropType, ref, watch, computed } from "vue";