@antify/ui 4.1.38 → 4.2.1
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/dist/components/inputs/AntPhoneNumberInput.vue +49 -35
- package/dist/components/inputs/__stories/AntPhoneNumberInput.stories.js +3 -0
- package/dist/components/inputs/__stories/AntPhoneNumberInput.stories.mjs +3 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +16 -0
- package/dist/constants/index.mjs +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -24,16 +24,15 @@ import {
|
|
|
24
24
|
ref, nextTick,
|
|
25
25
|
} from 'vue';
|
|
26
26
|
|
|
27
|
-
const phoneInputNativeRef = ref<HTMLInputElement | null>(null);
|
|
28
|
-
|
|
29
27
|
defineOptions({
|
|
30
28
|
inheritAttrs: false,
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
const props = withDefaults(defineProps<{
|
|
34
32
|
modelValue: string | null;
|
|
35
|
-
countryValue
|
|
33
|
+
countryValue?: string | number | null;
|
|
36
34
|
countries?: Country[];
|
|
35
|
+
inputRef?: null | HTMLInputElement;
|
|
37
36
|
|
|
38
37
|
//Common Props
|
|
39
38
|
size?: Size;
|
|
@@ -53,7 +52,6 @@ const props = withDefaults(defineProps<{
|
|
|
53
52
|
searchable?: boolean;
|
|
54
53
|
countryMaxHeight?: string;
|
|
55
54
|
countryValueKey?: CountryValueKey;
|
|
56
|
-
countryErrorMessage?: string;
|
|
57
55
|
countrySortable?: boolean;
|
|
58
56
|
|
|
59
57
|
//AntBaseInput Props
|
|
@@ -61,6 +59,7 @@ const props = withDefaults(defineProps<{
|
|
|
61
59
|
nullable?: boolean;
|
|
62
60
|
locale?: Locale;
|
|
63
61
|
}>(), {
|
|
62
|
+
inputRef: null,
|
|
64
63
|
size: Size.md,
|
|
65
64
|
state: InputState.base,
|
|
66
65
|
searchable: true,
|
|
@@ -68,7 +67,6 @@ const props = withDefaults(defineProps<{
|
|
|
68
67
|
countryPlaceholder: 'Select country',
|
|
69
68
|
placeholder: 'Enter phone number',
|
|
70
69
|
countryValueKey: CountryValueKey.dialCode,
|
|
71
|
-
countryErrorMessage: 'Please select a country code or start with "+"',
|
|
72
70
|
countrySortable: true,
|
|
73
71
|
messages: () => [],
|
|
74
72
|
nullable: true,
|
|
@@ -79,13 +77,27 @@ const props = withDefaults(defineProps<{
|
|
|
79
77
|
const emit = defineEmits([
|
|
80
78
|
'update:modelValue',
|
|
81
79
|
'update:countryValue',
|
|
80
|
+
'update:inputRef',
|
|
82
81
|
'select-country',
|
|
83
82
|
'validate',
|
|
84
83
|
'blur',
|
|
85
84
|
]);
|
|
86
85
|
|
|
87
|
-
const _countryValue = useVModel(props, 'countryValue', emit);
|
|
88
86
|
const _phoneNumber = useVModel(props, 'modelValue', emit);
|
|
87
|
+
const internalInputRef = ref<HTMLInputElement | null>(null);
|
|
88
|
+
const _inputRef = useVModel(props, 'inputRef', emit);
|
|
89
|
+
const internalCountryValue = ref<string | number | null>(null);
|
|
90
|
+
|
|
91
|
+
const _countryValue = computed({
|
|
92
|
+
get: () => {
|
|
93
|
+
return props.countryValue !== undefined ? props.countryValue : internalCountryValue.value;
|
|
94
|
+
},
|
|
95
|
+
set: (val) => {
|
|
96
|
+
emit('update:countryValue', val);
|
|
97
|
+
|
|
98
|
+
internalCountryValue.value = val;
|
|
99
|
+
},
|
|
100
|
+
});
|
|
89
101
|
|
|
90
102
|
const updateFullValue = (countryId: string | number | null, rawPhone: string | null) => {
|
|
91
103
|
if (!rawPhone) {
|
|
@@ -104,26 +116,8 @@ const updateFullValue = (countryId: string | number | null, rawPhone: string | n
|
|
|
104
116
|
}
|
|
105
117
|
};
|
|
106
118
|
|
|
107
|
-
const showCountryError = computed(() => {
|
|
108
|
-
const val = props.modelValue || '';
|
|
109
|
-
|
|
110
|
-
return props.countryValue == null && val.length > 0 && !val.startsWith('+');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const allMessages = computed(() => {
|
|
114
|
-
const msgs = [
|
|
115
|
-
...(props.messages || []),
|
|
116
|
-
];
|
|
117
|
-
|
|
118
|
-
if (showCountryError.value) {
|
|
119
|
-
msgs.push(props.countryErrorMessage);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return msgs;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
119
|
const currentCountry = computed(() => {
|
|
126
|
-
return props.countries.find(c => String(c[props.countryValueKey]) === String(
|
|
120
|
+
return props.countries.find(c => String(c[props.countryValueKey]) === String(_countryValue.value));
|
|
127
121
|
});
|
|
128
122
|
|
|
129
123
|
const sortedCountriesByDialCode = computed(() => {
|
|
@@ -213,7 +207,7 @@ function onCountrySelect(country: Country) {
|
|
|
213
207
|
emit('select-country', country);
|
|
214
208
|
|
|
215
209
|
nextTick(() => {
|
|
216
|
-
|
|
210
|
+
internalInputRef.value?.focus();
|
|
217
211
|
});
|
|
218
212
|
}
|
|
219
213
|
|
|
@@ -232,13 +226,13 @@ function onKeyPress(event: KeyboardEvent) {
|
|
|
232
226
|
return;
|
|
233
227
|
}
|
|
234
228
|
|
|
235
|
-
if (
|
|
229
|
+
if (_countryValue.value && charStr === '+') {
|
|
236
230
|
event.preventDefault();
|
|
237
231
|
|
|
238
232
|
return;
|
|
239
233
|
}
|
|
240
234
|
|
|
241
|
-
if (!
|
|
235
|
+
if (!_countryValue.value && charStr === '+' && currentRawValue.length > 0) {
|
|
242
236
|
event.preventDefault();
|
|
243
237
|
}
|
|
244
238
|
|
|
@@ -269,6 +263,11 @@ function onPaste(event: ClipboardEvent) {
|
|
|
269
263
|
}
|
|
270
264
|
}
|
|
271
265
|
|
|
266
|
+
function onBlur(e: FocusEvent) {
|
|
267
|
+
emit('blur', e);
|
|
268
|
+
emit('validate', _phoneNumber.value);
|
|
269
|
+
}
|
|
270
|
+
|
|
272
271
|
watch(_countryValue, (newCountryId, oldCountryId) => {
|
|
273
272
|
if (newCountryId === oldCountryId) {
|
|
274
273
|
return;
|
|
@@ -284,13 +283,29 @@ watch(_countryValue, (newCountryId, oldCountryId) => {
|
|
|
284
283
|
|
|
285
284
|
updateFullValue(newCountryId, body);
|
|
286
285
|
});
|
|
286
|
+
|
|
287
|
+
watch(() => props.modelValue, (newVal) => {
|
|
288
|
+
if (newVal && newVal.startsWith('+') && !_countryValue.value) {
|
|
289
|
+
const country = findCountryByPhone(newVal);
|
|
290
|
+
|
|
291
|
+
if (country) {
|
|
292
|
+
_countryValue.value = country[props.countryValueKey] as string | number;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
immediate: true,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
watch(internalInputRef, (el) => {
|
|
300
|
+
_inputRef.value = el;
|
|
301
|
+
});
|
|
287
302
|
</script>
|
|
288
303
|
|
|
289
304
|
<template>
|
|
290
305
|
<AntField
|
|
291
306
|
:label="label"
|
|
292
|
-
:messages="
|
|
293
|
-
:state="
|
|
307
|
+
:messages="messages"
|
|
308
|
+
:state="state"
|
|
294
309
|
:size="size"
|
|
295
310
|
:skeleton="skeleton"
|
|
296
311
|
:description="description"
|
|
@@ -305,7 +320,7 @@ watch(_countryValue, (newCountryId, oldCountryId) => {
|
|
|
305
320
|
:countries="countries"
|
|
306
321
|
:size="size"
|
|
307
322
|
:locale="locale"
|
|
308
|
-
:state="
|
|
323
|
+
:state="state"
|
|
309
324
|
:disabled="disabled"
|
|
310
325
|
:readonly="readonly"
|
|
311
326
|
:skeleton="skeleton"
|
|
@@ -324,10 +339,10 @@ watch(_countryValue, (newCountryId, oldCountryId) => {
|
|
|
324
339
|
|
|
325
340
|
<AntBaseInput
|
|
326
341
|
v-model="formattedNumber"
|
|
327
|
-
v-model:input-ref="
|
|
342
|
+
v-model:input-ref="internalInputRef"
|
|
328
343
|
:nullable="nullable"
|
|
329
344
|
:type="BaseInputType.text"
|
|
330
|
-
:state="
|
|
345
|
+
:state="state"
|
|
331
346
|
:size="size"
|
|
332
347
|
:skeleton="skeleton"
|
|
333
348
|
v-bind="$attrs"
|
|
@@ -337,8 +352,7 @@ watch(_countryValue, (newCountryId, oldCountryId) => {
|
|
|
337
352
|
:grouped="Grouped.right"
|
|
338
353
|
wrapper-class="flex-grow"
|
|
339
354
|
class="-ml-px"
|
|
340
|
-
@
|
|
341
|
-
@blur="e => $emit('blur', e)"
|
|
355
|
+
@blur="onBlur"
|
|
342
356
|
@keydown="onKeyPress"
|
|
343
357
|
@paste="onPaste"
|
|
344
358
|
/>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './countries';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _countries = require("./countries");
|
|
7
|
+
Object.keys(_countries).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _countries[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _countries[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./countries.mjs";
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -58,14 +58,14 @@ Object.keys(_utils).forEach(function (key) {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
-
var
|
|
62
|
-
Object.keys(
|
|
61
|
+
var _constants = require("./constants");
|
|
62
|
+
Object.keys(_constants).forEach(function (key) {
|
|
63
63
|
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] ===
|
|
64
|
+
if (key in exports && exports[key] === _constants[key]) return;
|
|
65
65
|
Object.defineProperty(exports, key, {
|
|
66
66
|
enumerable: true,
|
|
67
67
|
get: function () {
|
|
68
|
-
return
|
|
68
|
+
return _constants[key];
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
package/dist/index.mjs
CHANGED