@antify/ui 4.1.37 → 4.1.38

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.
@@ -0,0 +1,305 @@
1
+ import AntPhoneNumberInput from "../AntPhoneNumberInput.vue";
2
+ import {
3
+ Size,
4
+ InputState
5
+ } from "../../../enums/index.mjs";
6
+ import {
7
+ ref
8
+ } from "vue";
9
+ import {
10
+ COUNTRIES,
11
+ CountryValueKey,
12
+ Locale
13
+ } from "../../../constants/countries.mjs";
14
+ const meta = {
15
+ title: "Inputs/Phone Number Input",
16
+ component: AntPhoneNumberInput,
17
+ parameters: {
18
+ docs: {
19
+ description: {
20
+ component: "Komponente zur Eingabe der Telefonnummer mit Auswahl von Land und L\xE4ndervorwahl."
21
+ }
22
+ }
23
+ },
24
+ argTypes: {
25
+ size: {
26
+ control: {
27
+ type: "select"
28
+ },
29
+ options: Object.values(Size)
30
+ },
31
+ state: {
32
+ control: {
33
+ type: "select"
34
+ },
35
+ options: Object.values(InputState)
36
+ },
37
+ onValidate: {
38
+ action: "validate"
39
+ },
40
+ nullable: {
41
+ control: "boolean",
42
+ description: "Shows the clear icon in the input field."
43
+ },
44
+ locale: {
45
+ control: {
46
+ type: "select"
47
+ },
48
+ options: Object.values(Locale),
49
+ description: "Language for country names translation"
50
+ },
51
+ countryValueKey: {
52
+ control: {
53
+ type: "select"
54
+ },
55
+ options: Object.values(CountryValueKey)
56
+ },
57
+ countries: {
58
+ table: {
59
+ disable: true
60
+ }
61
+ }
62
+ }
63
+ };
64
+ export default meta;
65
+ export const Default = {
66
+ render: (args) => ({
67
+ components: {
68
+ AntPhoneNumberInput
69
+ },
70
+ setup() {
71
+ const phoneDefault = ref(null);
72
+ const countryDefault = ref("DE");
73
+ const phoneNumericDefault = ref(null);
74
+ const countryNumericDefault = ref(49);
75
+ const phone1 = ref(null);
76
+ const country1 = ref(null);
77
+ const phone2 = ref(null);
78
+ const country2 = ref(null);
79
+ const phone3 = ref(null);
80
+ const country3 = ref(null);
81
+ const phone4 = ref("123456");
82
+ const country4 = ref("DE");
83
+ const phonePaste = ref(null);
84
+ const countryPaste = ref(null);
85
+ const copyToClipboard = async (text) => {
86
+ await navigator.clipboard?.writeText(text).catch((err) => {
87
+ console.warn("Copy failed", err);
88
+ });
89
+ };
90
+ return {
91
+ args,
92
+ phoneDefault,
93
+ countryDefault,
94
+ phoneNumericDefault,
95
+ countryNumericDefault,
96
+ phone1,
97
+ country1,
98
+ phone2,
99
+ country2,
100
+ phone3,
101
+ country3,
102
+ phone4,
103
+ country4,
104
+ phonePaste,
105
+ countryPaste,
106
+ copyToClipboard
107
+ };
108
+ },
109
+ template: `
110
+ <div class="grid grid-cols-2 gap-x-12 gap-y-12">
111
+ <div>
112
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">Default Country Prop</h3>
113
+ <p class="mb-2 text-xs text-base-400 italic text-wrap">
114
+ Initial values are null. Component selects Germany via <b>default-country-value="DE"</b> using the default "value" key.
115
+ </p>
116
+ <AntPhoneNumberInput
117
+ v-bind="args"
118
+ v-model="phoneDefault"
119
+ :locale="args.locale"
120
+ country-value-key="value"
121
+ v-model:country-value="countryDefault"
122
+ placeholder="Initialized with DE"
123
+ />
124
+ <div class="mt-2 text-md text-for-white-bg-font">
125
+ Data: {{ countryDefault || 'null' }} | {{ phoneDefault || 'null' }}
126
+ </div>
127
+ </div>
128
+
129
+ <div>
130
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">Default by Numeric Code (49)</h3>
131
+ <p class="mb-2 text-xs text-base-400 italic text-wrap">
132
+ Initial values are null. Component selects Germany via <b>numericCode: 49</b>. We tell the component to use "numericCode" as the value key.
133
+ </p>
134
+ <AntPhoneNumberInput
135
+ v-bind="args"
136
+ v-model="phoneNumericDefault"
137
+ v-model:country-value="countryNumericDefault"
138
+ country-value-key="numericCode"
139
+ placeholder="Initialized with 49"
140
+ />
141
+ <div class="mt-2 text-md text-for-white-bg-font">
142
+ Data: {{ countryNumericDefault || 'null' }} | {{ phoneNumericDefault || 'null' }}
143
+ </div>
144
+ </div>
145
+
146
+ <div>
147
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">Auto-detect Country on Paste</h3>
148
+ <p class="mb-2 text-xs text-base-400 italic text-wrap">
149
+ Click a number to copy, then paste it (Ctrl+V) into the input to see auto-detection in action.
150
+ </p>
151
+
152
+ <div class="flex gap-2 mb-4">
153
+ <button
154
+ v-for="num in ['+4915211111111', '+3715211111111', '+3725211111111']"
155
+ @click="copyToClipboard(num)"
156
+ class="px-2 py-1 text-xs bg-white border border-base-300 rounded hover:bg-base-100 transition-colors text-for-white-bg-font"
157
+ title="Click to copy"
158
+ >
159
+ {{ num }}
160
+ </button>
161
+ </div>
162
+
163
+ <AntPhoneNumberInput
164
+ v-bind="args"
165
+ v-model="phonePaste"
166
+ v-model:country-value="countryPaste"
167
+ placeholder="Paste a number starting with +..."
168
+ />
169
+
170
+ <div class="mt-2 text-md text-for-white-bg-font">
171
+ Data: {{ countryPaste || 'null' }} | {{ phonePaste || 'null' }}
172
+ </div>
173
+ </div>
174
+
175
+ <div>
176
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">Keep Country on Clear</h3>
177
+ <p class="mb-2 text-xs text-base-400 italic text-wrap">
178
+ Try clicking the "X" icon. The phone number will be null, but the country (DE) will remain selected.
179
+ </p>
180
+ <AntPhoneNumberInput
181
+ v-bind="args"
182
+ v-model="phone4"
183
+ v-model:country-value="country4"
184
+ :nullable="true"
185
+ country-value-key="value"
186
+ />
187
+ <div class="mt-2 text-md text-for-white-bg-font">
188
+ Data: {{ country4 || 'null' }} | {{ phone4 || 'null' }}
189
+ </div>
190
+ </div>
191
+
192
+ <div>
193
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">With Search (Default)</h3>
194
+ <AntPhoneNumberInput
195
+ v-bind="args"
196
+ v-model="phone1"
197
+ v-model:country-value="country1"
198
+ />
199
+ <div class="mt-2 text-md text-for-white-bg-font">
200
+ Data: {{ country1 || 'null' }} | {{ phone1 || 'null' }}
201
+ </div>
202
+ </div>
203
+
204
+ <div>
205
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">Without Search</h3>
206
+ <AntPhoneNumberInput
207
+ v-bind="args"
208
+ v-model="phone2"
209
+ v-model:country-value="country2"
210
+ :searchable="false"
211
+ />
212
+ <div class="mt-2 text-md text-for-white-bg-font">
213
+ Data: {{ country2 || 'null' }} | {{ phone2 || 'null' }}
214
+ </div>
215
+ </div>
216
+
217
+ <div>
218
+ <h3 class="mb-2 text-sm font-bold text-for-white-bg-font uppercase tracking-wider">Numeric Code Output</h3>
219
+ <AntPhoneNumberInput
220
+ v-bind="args"
221
+ v-model="phone3"
222
+ v-model:country-value="country3"
223
+ country-value-key="numericCode"
224
+ country-placeholder="Select for numeric output"
225
+ />
226
+ <div class="mt-2 text-md text-for-white-bg-font">
227
+ Data: {{ country3 || 'null' }} | {{ phone3 || 'null' }}
228
+ </div>
229
+ </div>
230
+ </div>
231
+ `
232
+ }),
233
+ args: {
234
+ label: "Phone Number",
235
+ description: "Enter your mobile phone number",
236
+ placeholder: "Enter digits",
237
+ countryPlaceholder: "Select your country",
238
+ countries: COUNTRIES,
239
+ size: Size.md,
240
+ state: InputState.base,
241
+ nullable: true,
242
+ locale: Locale.de
243
+ }
244
+ };
245
+ export const summary = {
246
+ parameters: {
247
+ chromatic: {
248
+ disableSnapshot: false
249
+ }
250
+ },
251
+ render: (args) => ({
252
+ components: {
253
+ AntPhoneNumberInput
254
+ },
255
+ setup() {
256
+ const phone = ref(null);
257
+ const country = ref("+49");
258
+ return {
259
+ args,
260
+ phone,
261
+ country,
262
+ InputState,
263
+ Size,
264
+ COUNTRIES
265
+ };
266
+ },
267
+ template: `
268
+ <div class="flex flex-col gap-4">
269
+ <div class="flex flex-col gap-4">
270
+ <h2 class="text-xl font-bold border-b pb-2 text-base-700">Phone Number Input States</h2>
271
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
272
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :state="InputState.base" label="Base State" />
273
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :state="InputState.info" label="Info State" :messages="['Bitte geben Sie Ihre Mobilnummer ein']" />
274
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :state="InputState.success" label="Success State" />
275
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :state="InputState.warning" label="Warning State" :messages="['Pr\xFCfen Sie die Vorwahl']" />
276
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :state="InputState.danger" label="Danger State" :messages="['Ung\xFCltige Telefonnummer']" />
277
+ </div>
278
+ </div>
279
+
280
+ <div class="flex flex-col gap-4">
281
+ <h2 class="text-xl font-bold border-b pb-2 text-base-700">Sizes</h2>
282
+ <div class="flex flex-col gap-4">
283
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :size="Size.sm" label="Small (sm)" />
284
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :size="Size.md" label="Medium (md)" />
285
+ <AntPhoneNumberInput v-bind="args" v-model="phone" v-model:country-value="country" :size="Size.lg" label="Large (lg)" />
286
+ </div>
287
+ </div>
288
+
289
+ <div class="flex flex-col gap-4">
290
+ <h2 class="text-xl font-bold border-b pb-2 text-base-700">Special Modes</h2>
291
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
292
+ <AntPhoneNumberInput v-bind="args" v-model="phone" country-value="DE" model-value="1512345678" disabled label="Disabled" />
293
+ <AntPhoneNumberInput v-bind="args" v-model="phone" country-value="DE" model-value="1512345678" readonly label="Readonly" />
294
+ <AntPhoneNumberInput v-bind="args" v-model="phone" country-value="DE" skeleton label="Skeleton" />
295
+ </div>
296
+ </div>
297
+ </div>
298
+ `
299
+ }),
300
+ args: {
301
+ countries: COUNTRIES,
302
+ countryPlaceholder: "Land w\xE4hlen",
303
+ searchPlaceholder: "Suchen..."
304
+ }
305
+ };
@@ -0,0 +1,11 @@
1
+ export interface Country {
2
+ value: string;
3
+ isoCode: string;
4
+ label: Record<string, string>;
5
+ dialCode: string;
6
+ numericCode: number;
7
+ flag?: string;
8
+ phoneLength?: number | number[];
9
+ mask?: string;
10
+ isDefault?: boolean;
11
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,4 +1,5 @@
1
1
  export * from './AntCheckbox.types';
2
+ export * from './AntCountryInput.types';
2
3
  export * from './AntDateInput.types';
3
4
  export * from './AntRadio.types';
4
5
  export * from './AntSelect.types';
@@ -14,6 +14,17 @@ Object.keys(_AntCheckbox).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _AntCountryInput = require("./AntCountryInput.types");
18
+ Object.keys(_AntCountryInput).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _AntCountryInput[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _AntCountryInput[key];
25
+ }
26
+ });
27
+ });
17
28
  var _AntDateInput = require("./AntDateInput.types");
18
29
  Object.keys(_AntDateInput).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
@@ -1,4 +1,5 @@
1
1
  export * from "./AntCheckbox.types.mjs";
2
+ export * from "./AntCountryInput.types.mjs";
2
3
  export * from "./AntDateInput.types.mjs";
3
4
  export * from "./AntRadio.types.mjs";
4
5
  export * from "./AntSelect.types.mjs";
@@ -0,0 +1,22 @@
1
+ import type { Country } from '../types';
2
+ export declare enum CountryValueKey {
3
+ value = "value",
4
+ dialCode = "dialCode",
5
+ numericCode = "numericCode"
6
+ }
7
+ export declare enum Locale {
8
+ en = "en",
9
+ de = "de"
10
+ }
11
+ /**
12
+ * TODO: Detailed verification and data enrichment required.
13
+ * * ATTENTION:
14
+ * 1. The physical order of this array is pre-sorted by English labels (label.en).
15
+ * 2. Country ISO codes (isoCode) are NOT the same as phone dial codes (dialCode).
16
+ * Verify each dialCode and numericCode against official ITU-T standards.
17
+ * 3. Some territories share the same dialCode (e.g., US, CA, and various islands use +1),
18
+ * ensure the 'findCountryByPhone' logic in components handles these overlaps.
19
+ * 4. Phone masks need to be validated for each region to ensure correct formatting.
20
+ * 5. Kazakhstan was removed because he had the same dialCode of number as Russia
21
+ */
22
+ export declare const COUNTRIES: Country[];