@caribeng/ui 22.2.0 → 22.4.0
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/README.md +93 -11
- package/fesm2022/caribeng-ui-accordion.mjs +2 -2
- package/fesm2022/caribeng-ui-avatar.mjs +2 -2
- package/fesm2022/caribeng-ui-badge.mjs +8 -2
- package/fesm2022/caribeng-ui-breadcrumb.mjs +13 -6
- package/fesm2022/caribeng-ui-chart.mjs +8 -5
- package/fesm2022/caribeng-ui-chat.mjs +1303 -0
- package/fesm2022/caribeng-ui-code-block.mjs +332 -0
- package/fesm2022/caribeng-ui-colorpicker.mjs +99 -5
- package/fesm2022/caribeng-ui-command-palette.mjs +476 -0
- package/fesm2022/caribeng-ui-confirmdialog.mjs +78 -13
- package/fesm2022/caribeng-ui-confirmpopup.mjs +91 -16
- package/fesm2022/caribeng-ui-contextmenu.mjs +8 -4
- package/fesm2022/caribeng-ui-copy-button.mjs +230 -0
- package/fesm2022/caribeng-ui-dataview.mjs +4 -1
- package/fesm2022/caribeng-ui-dock.mjs +52 -12
- package/fesm2022/caribeng-ui-drawer.mjs +9 -4
- package/fesm2022/caribeng-ui-editor.mjs +21 -0
- package/fesm2022/caribeng-ui-fieldset.mjs +2 -2
- package/fesm2022/caribeng-ui-file-card.mjs +134 -17
- package/fesm2022/caribeng-ui-folder-card.mjs +122 -12
- package/fesm2022/caribeng-ui-inlinemessage.mjs +2 -2
- package/fesm2022/caribeng-ui-inputmask.mjs +8 -2
- package/fesm2022/caribeng-ui-kanban.mjs +4612 -0
- package/fesm2022/caribeng-ui-kbd.mjs +122 -0
- package/fesm2022/caribeng-ui-megamenu.mjs +13 -9
- package/fesm2022/caribeng-ui-mentions.mjs +495 -0
- package/fesm2022/caribeng-ui-menu.mjs +8 -4
- package/fesm2022/caribeng-ui-menubar.mjs +9 -5
- package/fesm2022/caribeng-ui-message.mjs +6 -3
- package/fesm2022/caribeng-ui-organizationchart.mjs +6 -10
- package/fesm2022/caribeng-ui-panel.mjs +6 -6
- package/fesm2022/caribeng-ui-panelmenu.mjs +9 -6
- package/fesm2022/caribeng-ui-phone-input.mjs +688 -0
- package/fesm2022/caribeng-ui-pricing.mjs +263 -69
- package/fesm2022/caribeng-ui-qrcode.mjs +564 -0
- package/fesm2022/caribeng-ui-ripple.mjs +2 -0
- package/fesm2022/caribeng-ui-scrolltop.mjs +3 -1
- package/fesm2022/caribeng-ui-sidebar.mjs +573 -0
- package/fesm2022/caribeng-ui-stepper.mjs +10 -3
- package/fesm2022/caribeng-ui-table.mjs +10 -4
- package/fesm2022/caribeng-ui-tabmenu.mjs +8 -4
- package/fesm2022/caribeng-ui-tieredmenu.mjs +109 -19
- package/fesm2022/caribeng-ui.mjs +388 -1
- package/package.json +42 -2
- package/schematics/collection.json +5 -0
- package/schematics/migrate-from-primeng/core-icons.json +1 -0
- package/schematics/migrate-from-primeng/icons.js +269 -0
- package/schematics/migrate-from-primeng/index.js +290 -0
- package/schematics/migrate-from-primeng/mappings/button.js +93 -0
- package/schematics/migrate-from-primeng/mappings/card.js +33 -0
- package/schematics/migrate-from-primeng/mappings/checkbox.js +44 -0
- package/schematics/migrate-from-primeng/mappings/confirm.js +221 -0
- package/schematics/migrate-from-primeng/mappings/datepicker.js +121 -0
- package/schematics/migrate-from-primeng/mappings/dialog.js +84 -0
- package/schematics/migrate-from-primeng/mappings/index.js +88 -0
- package/schematics/migrate-from-primeng/mappings/inputnumber.js +62 -0
- package/schematics/migrate-from-primeng/mappings/inputtext.js +60 -0
- package/schematics/migrate-from-primeng/mappings/menu.js +468 -0
- package/schematics/migrate-from-primeng/mappings/multiselect.js +49 -0
- package/schematics/migrate-from-primeng/mappings/radiobutton.js +22 -0
- package/schematics/migrate-from-primeng/mappings/rules.js +206 -0
- package/schematics/migrate-from-primeng/mappings/select.js +97 -0
- package/schematics/migrate-from-primeng/mappings/service-calls.js +100 -0
- package/schematics/migrate-from-primeng/mappings/table.js +613 -0
- package/schematics/migrate-from-primeng/mappings/tabs.js +225 -0
- package/schematics/migrate-from-primeng/mappings/tag.js +29 -0
- package/schematics/migrate-from-primeng/mappings/textarea.js +44 -0
- package/schematics/migrate-from-primeng/mappings/toast.js +173 -0
- package/schematics/migrate-from-primeng/mappings/toggleswitch.js +37 -0
- package/schematics/migrate-from-primeng/mappings/tooltip.js +44 -0
- package/schematics/migrate-from-primeng/mappings/types.js +10 -0
- package/schematics/migrate-from-primeng/report.js +79 -0
- package/schematics/migrate-from-primeng/schema.js +2 -0
- package/schematics/migrate-from-primeng/schema.json +34 -0
- package/schematics/migrate-from-primeng/template.js +387 -0
- package/schematics/migrate-from-primeng/todo.js +5 -0
- package/schematics/migrate-from-primeng/typescript.js +442 -0
- package/schematics/migrate-from-primeng/workspace.js +117 -0
- package/schematics/ng-add/index.js +16 -1
- package/types/caribeng-ui-badge.d.ts +3 -1
- package/types/caribeng-ui-breadcrumb.d.ts +8 -0
- package/types/caribeng-ui-chart.d.ts +3 -1
- package/types/caribeng-ui-chat.d.ts +299 -0
- package/types/caribeng-ui-code-block.d.ts +65 -0
- package/types/caribeng-ui-colorpicker.d.ts +5 -1
- package/types/caribeng-ui-command-palette.d.ts +133 -0
- package/types/caribeng-ui-confirmdialog.d.ts +34 -2
- package/types/caribeng-ui-confirmpopup.d.ts +39 -2
- package/types/caribeng-ui-contextmenu.d.ts +7 -0
- package/types/caribeng-ui-copy-button.d.ts +90 -0
- package/types/caribeng-ui-dataview.d.ts +2 -0
- package/types/caribeng-ui-dock.d.ts +13 -1
- package/types/caribeng-ui-drawer.d.ts +3 -1
- package/types/caribeng-ui-file-card.d.ts +27 -2
- package/types/caribeng-ui-folder-card.d.ts +27 -5
- package/types/caribeng-ui-inputmask.d.ts +3 -1
- package/types/caribeng-ui-kanban.d.ts +783 -0
- package/types/caribeng-ui-kbd.d.ts +36 -0
- package/types/caribeng-ui-megamenu.d.ts +11 -0
- package/types/caribeng-ui-mentions.d.ts +127 -0
- package/types/caribeng-ui-menu.d.ts +7 -0
- package/types/caribeng-ui-menubar.d.ts +7 -0
- package/types/caribeng-ui-message.d.ts +2 -0
- package/types/caribeng-ui-panelmenu.d.ts +7 -0
- package/types/caribeng-ui-phone-input.d.ts +168 -0
- package/types/caribeng-ui-pricing.d.ts +41 -4
- package/types/caribeng-ui-qrcode.d.ts +88 -0
- package/types/caribeng-ui-sidebar.d.ts +167 -0
- package/types/caribeng-ui-stepper.d.ts +2 -0
- package/types/caribeng-ui-table.d.ts +1 -1
- package/types/caribeng-ui-tabmenu.d.ts +7 -0
- package/types/caribeng-ui-tieredmenu.d.ts +17 -1
- package/types/caribeng-ui.d.ts +276 -2
- package/styles/caribeng.css +0 -380
- package/styles/scss/_mixins.scss +0 -46
- package/styles/scss/_overlay.scss +0 -15
- package/styles/scss/_tokens.scss +0 -267
- package/styles/scss/_utilities.scss +0 -73
- package/styles/scss/_variables.scss +0 -33
- package/styles/scss/index.scss +0 -16
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, ViewContainerRef, Injector, viewChild, model, input, output, signal, computed, effect, untracked, afterNextRender, forwardRef, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
|
|
4
|
+
import { Overlay } from '@angular/cdk/overlay';
|
|
5
|
+
import { TemplatePortal } from '@angular/cdk/portal';
|
|
6
|
+
import { injectCbTranslation, cbFieldState } from '@caribeng/ui';
|
|
7
|
+
import { CbIcon } from '@caribeng/ui/icon';
|
|
8
|
+
|
|
9
|
+
const NANP = { dial: '1', lengths: [10], formats: { 10: '(###) ###-####' } };
|
|
10
|
+
/**
|
|
11
|
+
* Países incluidos: América Latina y el Caribe, Norteamérica, la Europa más
|
|
12
|
+
* habitual y los mayores de Asia y Oceanía. Amplíalos con `[countries]`.
|
|
13
|
+
*/
|
|
14
|
+
const CB_PHONE_COUNTRIES = [
|
|
15
|
+
// --- América Latina y el Caribe ---
|
|
16
|
+
{ iso: 'AR', dial: '54', lengths: [10, 11], formats: { 10: '## ####-####', 11: '# ## ####-####' }, trunk: '0', example: '1123456789' },
|
|
17
|
+
{ iso: 'BO', dial: '591', lengths: [8], formats: { 8: '# ### ####' }, trunk: '0', example: '71234567' },
|
|
18
|
+
{ iso: 'BR', dial: '55', lengths: [10, 11], formats: { 10: '(##) ####-####', 11: '(##) #####-####' }, trunk: '0', example: '11912345678' },
|
|
19
|
+
{ iso: 'CL', dial: '56', lengths: [9], formats: { 9: '# #### ####' }, example: '912345678' },
|
|
20
|
+
{ iso: 'CO', dial: '57', lengths: [10], formats: { 10: '### ### ####' }, example: '3001234567' },
|
|
21
|
+
{ iso: 'CR', dial: '506', lengths: [8], formats: { 8: '#### ####' }, example: '83123456' },
|
|
22
|
+
{ iso: 'CU', dial: '53', lengths: [8], formats: { 8: '# ### ####' }, trunk: '0', example: '51234567' },
|
|
23
|
+
{ iso: 'DO', ...NANP, leading: ['809', '829', '849'], example: '8092345678' },
|
|
24
|
+
{ iso: 'EC', dial: '593', lengths: [8, 9], formats: { 8: '# ### ####', 9: '## ### ####' }, trunk: '0', example: '991234567' },
|
|
25
|
+
{ iso: 'SV', dial: '503', lengths: [8], formats: { 8: '#### ####' }, example: '70123456' },
|
|
26
|
+
{ iso: 'GT', dial: '502', lengths: [8], formats: { 8: '#### ####' }, example: '51234567' },
|
|
27
|
+
{ iso: 'HN', dial: '504', lengths: [8], formats: { 8: '####-####' }, example: '91234567' },
|
|
28
|
+
{ iso: 'MX', dial: '52', lengths: [10], formats: { 10: '## #### ####' }, example: '5512345678' },
|
|
29
|
+
{ iso: 'NI', dial: '505', lengths: [8], formats: { 8: '#### ####' }, example: '81234567' },
|
|
30
|
+
{ iso: 'PA', dial: '507', lengths: [7, 8], formats: { 7: '###-####', 8: '####-####' }, example: '61234567' },
|
|
31
|
+
{ iso: 'PY', dial: '595', lengths: [9], formats: { 9: '### ######' }, trunk: '0', example: '961456789' },
|
|
32
|
+
{ iso: 'PE', dial: '51', lengths: [8, 9], formats: { 8: '# ### ####', 9: '### ### ###' }, trunk: '0', example: '912345678' },
|
|
33
|
+
{ iso: 'PR', ...NANP, leading: ['787', '939'], example: '7872345678' },
|
|
34
|
+
{ iso: 'UY', dial: '598', lengths: [8], formats: { 8: '#### ####' }, trunk: '0', example: '94231234' },
|
|
35
|
+
{ iso: 'VE', dial: '58', lengths: [10], formats: { 10: '###-#######' }, trunk: '0', example: '4121234567' },
|
|
36
|
+
{ iso: 'JM', ...NANP, leading: ['876', '658'], example: '8762101234' },
|
|
37
|
+
{ iso: 'TT', ...NANP, leading: ['868'], example: '8682911234' },
|
|
38
|
+
// --- Norteamérica ---
|
|
39
|
+
{ iso: 'US', ...NANP, example: '2015550123' },
|
|
40
|
+
{ iso: 'CA', ...NANP, leading: ['204', '226', '236', '249', '250', '263', '289', '306', '343', '354', '365', '367', '368', '382', '403', '416', '418', '428', '431', '437', '438', '450', '468', '474', '506', '514', '519', '548', '579', '581', '584', '587', '604', '613', '639', '647', '672', '683', '705', '709', '742', '753', '778', '780', '782', '807', '819', '825', '867', '873', '879', '902', '905'], example: '5062345678' },
|
|
41
|
+
// --- Europa ---
|
|
42
|
+
{ iso: 'DE', dial: '49', lengths: [7, 8, 9, 10, 11], formats: { 10: '### #######', 11: '#### #######' }, trunk: '0', example: '15123456789' },
|
|
43
|
+
{ iso: 'AT', dial: '43', lengths: [8, 9, 10, 11, 12], formats: { 10: '### #######', 11: '### ########' }, trunk: '0', example: '6641234567' },
|
|
44
|
+
{ iso: 'BE', dial: '32', lengths: [8, 9], formats: { 8: '# ### ## ##', 9: '### ## ## ##' }, trunk: '0', example: '470123456' },
|
|
45
|
+
{ iso: 'DK', dial: '45', lengths: [8], formats: { 8: '## ## ## ##' }, example: '32123456' },
|
|
46
|
+
{ iso: 'ES', dial: '34', lengths: [9], formats: { 9: '### ## ## ##' }, example: '612345678' },
|
|
47
|
+
{ iso: 'FI', dial: '358', lengths: [9, 10], formats: { 9: '## ### ####', 10: '## #### ####' }, trunk: '0', example: '412345678' },
|
|
48
|
+
{ iso: 'FR', dial: '33', lengths: [9], formats: { 9: '# ## ## ## ##' }, trunk: '0', example: '612345678' },
|
|
49
|
+
{ iso: 'GR', dial: '30', lengths: [10], formats: { 10: '### ### ####' }, example: '6912345678' },
|
|
50
|
+
{ iso: 'IE', dial: '353', lengths: [9], formats: { 9: '## ### ####' }, trunk: '0', example: '850123456' },
|
|
51
|
+
{ iso: 'IT', dial: '39', lengths: [6, 7, 8, 9, 10, 11], formats: { 9: '### ### ###', 10: '### ### ####' }, example: '3123456789' },
|
|
52
|
+
{ iso: 'NL', dial: '31', lengths: [9], formats: { 9: '# ########' }, trunk: '0', example: '612345678' },
|
|
53
|
+
{ iso: 'NO', dial: '47', lengths: [8], formats: { 8: '### ## ###' }, example: '40612345' },
|
|
54
|
+
{ iso: 'PL', dial: '48', lengths: [9], formats: { 9: '### ### ###' }, example: '512345678' },
|
|
55
|
+
{ iso: 'PT', dial: '351', lengths: [9], formats: { 9: '### ### ###' }, example: '912345678' },
|
|
56
|
+
{ iso: 'GB', dial: '44', lengths: [10], formats: { 10: '#### ######' }, trunk: '0', example: '7400123456' },
|
|
57
|
+
{ iso: 'CH', dial: '41', lengths: [9], formats: { 9: '## ### ## ##' }, trunk: '0', example: '781234567' },
|
|
58
|
+
{ iso: 'SE', dial: '46', lengths: [9], formats: { 9: '##-### ## ##' }, trunk: '0', example: '701234567' },
|
|
59
|
+
// --- Asia, Oceanía, África y Oriente Medio ---
|
|
60
|
+
{ iso: 'AU', dial: '61', lengths: [9], formats: { 9: '### ### ###' }, trunk: '0', example: '412345678' },
|
|
61
|
+
{ iso: 'CN', dial: '86', lengths: [11], formats: { 11: '### #### ####' }, trunk: '0', example: '13123456789' },
|
|
62
|
+
{ iso: 'IN', dial: '91', lengths: [10], formats: { 10: '##### #####' }, trunk: '0', example: '8123456789' },
|
|
63
|
+
{ iso: 'IL', dial: '972', lengths: [9], formats: { 9: '##-###-####' }, trunk: '0', example: '502345678' },
|
|
64
|
+
{ iso: 'JP', dial: '81', lengths: [10], formats: { 10: '##-####-####' }, trunk: '0', example: '9012345678' },
|
|
65
|
+
{ iso: 'KR', dial: '82', lengths: [9, 10], formats: { 9: '##-###-####', 10: '##-####-####' }, trunk: '0', example: '1020000000' },
|
|
66
|
+
{ iso: 'NZ', dial: '64', lengths: [8, 9, 10], formats: { 8: '## ### ###', 9: '## ### ####', 10: '## #### ####' }, trunk: '0', example: '211234567' },
|
|
67
|
+
{ iso: 'AE', dial: '971', lengths: [9], formats: { 9: '## ### ####' }, trunk: '0', example: '501234567' },
|
|
68
|
+
{ iso: 'ZA', dial: '27', lengths: [9], formats: { 9: '## ### ####' }, trunk: '0', example: '711234567' },
|
|
69
|
+
];
|
|
70
|
+
/** Emoji de bandera a partir del código ISO (indicadores regionales). */
|
|
71
|
+
function cbFlagEmoji(iso) {
|
|
72
|
+
return iso.toUpperCase().replace(/[A-Z]/g, (c) => String.fromCodePoint(0x1f1e6 + c.charCodeAt(0) - 65));
|
|
73
|
+
}
|
|
74
|
+
/** Aplica el formato del país al número nacional (solo dígitos), también a medio escribir. */
|
|
75
|
+
function cbFormatNational(country, digits) {
|
|
76
|
+
if (!digits)
|
|
77
|
+
return '';
|
|
78
|
+
const lengths = [...country.lengths].sort((a, b) => a - b);
|
|
79
|
+
// El formato de la longitud más cercana por arriba; si se pasa, el de la mayor.
|
|
80
|
+
const target = lengths.find((l) => digits.length <= l) ?? lengths[lengths.length - 1];
|
|
81
|
+
const pattern = country.formats?.[target] ?? '### ### ### ### ###';
|
|
82
|
+
let out = '';
|
|
83
|
+
let d = 0;
|
|
84
|
+
for (const ch of pattern) {
|
|
85
|
+
if (d >= digits.length)
|
|
86
|
+
break;
|
|
87
|
+
if (ch === '#')
|
|
88
|
+
out += digits[d++];
|
|
89
|
+
else
|
|
90
|
+
out += ch;
|
|
91
|
+
}
|
|
92
|
+
// Dígitos que sobran del patrón (número demasiado largo): se añaden tal cual.
|
|
93
|
+
if (d < digits.length)
|
|
94
|
+
out += (out ? ' ' : '') + digits.slice(d);
|
|
95
|
+
return out.replace(/[\s()-]+$/, '');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Interpreta lo escrito o pegado. Con `+` o `00` detecta el país por el prefijo
|
|
99
|
+
* (el más largo que coincide; entre los que comparten prefijo, por el comienzo
|
|
100
|
+
* del número o, si no, el país actual). Sin prefijo, usa `current` y quita su 0 nacional.
|
|
101
|
+
*/
|
|
102
|
+
function cbParsePhone(text, current, countries) {
|
|
103
|
+
const raw = (text ?? '').trim();
|
|
104
|
+
const international = /^(\+|00)/.test(raw);
|
|
105
|
+
let digits = raw.replace(/\D/g, '');
|
|
106
|
+
if (international) {
|
|
107
|
+
if (raw.startsWith('00'))
|
|
108
|
+
digits = digits.slice(2);
|
|
109
|
+
const candidates = countries
|
|
110
|
+
.filter((c) => digits.startsWith(c.dial))
|
|
111
|
+
.sort((a, b) => b.dial.length - a.dial.length);
|
|
112
|
+
if (!candidates.length)
|
|
113
|
+
return { country: current, national: digits };
|
|
114
|
+
const dial = candidates[0].dial;
|
|
115
|
+
const national = digits.slice(dial.length);
|
|
116
|
+
const sameDial = candidates.filter((c) => c.dial === dial);
|
|
117
|
+
const byLeading = sameDial.find((c) => c.leading?.some((p) => national.startsWith(p)));
|
|
118
|
+
const country = byLeading ??
|
|
119
|
+
(current && current.dial === dial ? current : null) ??
|
|
120
|
+
sameDial.find((c) => !c.leading) ??
|
|
121
|
+
sameDial[0];
|
|
122
|
+
return { country, national: stripTrunk(country, national) };
|
|
123
|
+
}
|
|
124
|
+
return { country: current, national: current ? stripTrunk(current, digits) : digits };
|
|
125
|
+
}
|
|
126
|
+
function stripTrunk(country, digits) {
|
|
127
|
+
return country.trunk && digits.startsWith(country.trunk) ? digits.slice(country.trunk.length) : digits;
|
|
128
|
+
}
|
|
129
|
+
/** Número completo en formato E.164 (`+573001234567`), o `''` sin dígitos. */
|
|
130
|
+
function cbToE164(country, national) {
|
|
131
|
+
if (!national)
|
|
132
|
+
return '';
|
|
133
|
+
return country ? `+${country.dial}${national}` : `+${national}`;
|
|
134
|
+
}
|
|
135
|
+
/** Si la longitud del número nacional es válida para el país. */
|
|
136
|
+
function cbIsValidPhone(country, national) {
|
|
137
|
+
return !!country && country.lengths.includes(national.length) && /^\d+$/.test(national);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let nextUid = 0;
|
|
141
|
+
const toBoolean = (value) => value !== false && value !== 'false' && value != null;
|
|
142
|
+
/**
|
|
143
|
+
* Teléfono internacional de CaribeNG: selector de país (bandera, nombre y
|
|
144
|
+
* prefijo, con buscador) y número que se formatea mientras se escribe. El
|
|
145
|
+
* valor es E.164 (`+573001234567`), listo para guardar o enviar. Al pegar un
|
|
146
|
+
* número con `+` o `00` detecta el país.
|
|
147
|
+
*
|
|
148
|
+
* Funciona con Angular Forms (`formControlName`, `ngModel`) y añade el error
|
|
149
|
+
* `{ phone: true }` si el número está incompleto o no es válido para el país.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```html
|
|
153
|
+
* <cb-phone-input label="Celular" formControlName="celular" country="CO" [preferredCountries]="['CO', 'MX', 'US']" />
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
class CbPhoneInput {
|
|
157
|
+
constructor() {
|
|
158
|
+
/** Textos de interfaz en el idioma activo (`provideCaribeNG({ locale })`). */
|
|
159
|
+
this.t = injectCbTranslation();
|
|
160
|
+
this.overlay = inject(Overlay);
|
|
161
|
+
this.vcr = inject(ViewContainerRef);
|
|
162
|
+
this.injector = inject(Injector);
|
|
163
|
+
this.triggerEl = viewChild.required('trigger');
|
|
164
|
+
this.fieldEl = viewChild.required('field');
|
|
165
|
+
this.searchEl = viewChild('search', /* @ts-ignore */
|
|
166
|
+
...(ngDevMode ? [{ debugName: "searchEl" }] : /* istanbul ignore next */ []));
|
|
167
|
+
this.panelTpl = viewChild.required('panel');
|
|
168
|
+
this.overlayRef = null;
|
|
169
|
+
this.inputId = `cb-phone-input-${++nextUid}`;
|
|
170
|
+
this.listId = `${this.inputId}-countries`;
|
|
171
|
+
/** Número en formato E.164 (`+573001234567`); `''` si está vacío. */
|
|
172
|
+
this.value = model('', /* @ts-ignore */
|
|
173
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
174
|
+
/** País seleccionado (código ISO). */
|
|
175
|
+
this.country = model('CO', /* @ts-ignore */
|
|
176
|
+
...(ngDevMode ? [{ debugName: "country" }] : /* istanbul ignore next */ []));
|
|
177
|
+
/** Países disponibles. Por defecto, `CB_PHONE_COUNTRIES`; puedes pasar otros o filtrar por código ISO. */
|
|
178
|
+
this.countries = input(CB_PHONE_COUNTRIES, /* @ts-ignore */
|
|
179
|
+
...(ngDevMode ? [{ debugName: "countries" }] : /* istanbul ignore next */ []));
|
|
180
|
+
/** Países que aparecen primero en la lista (código ISO). */
|
|
181
|
+
this.preferredCountries = input([], /* @ts-ignore */
|
|
182
|
+
...(ngDevMode ? [{ debugName: "preferredCountries" }] : /* istanbul ignore next */ []));
|
|
183
|
+
/** Bloquea el país (solo se escribe el número). */
|
|
184
|
+
this.countryLocked = input(false, { ...(ngDevMode ? { debugName: "countryLocked" } : /* istanbul ignore next */ {}), transform: toBoolean });
|
|
185
|
+
/** Muestra la bandera (emoji). En Windows algunos navegadores la muestran como letras. */
|
|
186
|
+
this.showFlag = input(true, { ...(ngDevMode ? { debugName: "showFlag" } : /* istanbul ignore next */ {}), transform: toBoolean });
|
|
187
|
+
this.label = input('', /* @ts-ignore */
|
|
188
|
+
...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
189
|
+
this.hint = input('', /* @ts-ignore */
|
|
190
|
+
...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
|
|
191
|
+
/** Error a mostrar. Por defecto, "Número de teléfono incompleto o no válido" cuando lo es. */
|
|
192
|
+
this.error = input(undefined, /* @ts-ignore */
|
|
193
|
+
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
194
|
+
this.invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: toBoolean });
|
|
195
|
+
this.required = input(false, { ...(ngDevMode ? { debugName: "required" } : /* istanbul ignore next */ {}), transform: toBoolean });
|
|
196
|
+
this.requiredIndicator = input(undefined, /* @ts-ignore */
|
|
197
|
+
...(ngDevMode ? [{ debugName: "requiredIndicator" }] : /* istanbul ignore next */ []));
|
|
198
|
+
/** Placeholder. Por defecto, un número de ejemplo del país. */
|
|
199
|
+
this.placeholder = input(undefined, /* @ts-ignore */
|
|
200
|
+
...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
|
|
201
|
+
this.size = input('md', /* @ts-ignore */
|
|
202
|
+
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
203
|
+
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: toBoolean });
|
|
204
|
+
/** Cada cambio con el número E.164, el nacional, el país y si es válido. */
|
|
205
|
+
this.phoneChange = output();
|
|
206
|
+
this.fieldState = cbFieldState({
|
|
207
|
+
invalid: () => this.invalid(),
|
|
208
|
+
required: () => this.required(),
|
|
209
|
+
requiredIndicator: () => this.requiredIndicator(),
|
|
210
|
+
});
|
|
211
|
+
/** Número nacional (solo dígitos). */
|
|
212
|
+
this.national = signal('', /* @ts-ignore */
|
|
213
|
+
...(ngDevMode ? [{ debugName: "national" }] : /* istanbul ignore next */ []));
|
|
214
|
+
this.touched = signal(false, /* @ts-ignore */
|
|
215
|
+
...(ngDevMode ? [{ debugName: "touched" }] : /* istanbul ignore next */ []));
|
|
216
|
+
this.cvaDisabled = signal(false, /* @ts-ignore */
|
|
217
|
+
...(ngDevMode ? [{ debugName: "cvaDisabled" }] : /* istanbul ignore next */ []));
|
|
218
|
+
this.isDisabled = computed(() => this.disabled() || this.cvaDisabled(), /* @ts-ignore */
|
|
219
|
+
...(ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []));
|
|
220
|
+
this.open = signal(false, /* @ts-ignore */
|
|
221
|
+
...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
|
|
222
|
+
this.query = signal('', /* @ts-ignore */
|
|
223
|
+
...(ngDevMode ? [{ debugName: "query" }] : /* istanbul ignore next */ []));
|
|
224
|
+
this.active = signal(0, /* @ts-ignore */
|
|
225
|
+
...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
226
|
+
this.displayNames = computed(() => {
|
|
227
|
+
try {
|
|
228
|
+
return new Intl.DisplayNames([this.t().intlLocale], { type: 'region' });
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}, /* @ts-ignore */
|
|
234
|
+
...(ngDevMode ? [{ debugName: "displayNames" }] : /* istanbul ignore next */ []));
|
|
235
|
+
this.list = computed(() => {
|
|
236
|
+
const byIso = new Map(CB_PHONE_COUNTRIES.map((c) => [c.iso, c]));
|
|
237
|
+
const items = this.countries()
|
|
238
|
+
.map((c) => (typeof c === 'string' ? byIso.get(c.toUpperCase()) : c))
|
|
239
|
+
.filter((c) => !!c);
|
|
240
|
+
const preferred = this.preferredCountries().map((iso) => iso.toUpperCase());
|
|
241
|
+
const rank = (c) => {
|
|
242
|
+
const i = preferred.indexOf(c.iso);
|
|
243
|
+
return i < 0 ? preferred.length : i;
|
|
244
|
+
};
|
|
245
|
+
return [...items].sort((a, b) => rank(a) - rank(b) || this.name(a).localeCompare(this.name(b), this.t().intlLocale));
|
|
246
|
+
}, /* @ts-ignore */
|
|
247
|
+
...(ngDevMode ? [{ debugName: "list" }] : /* istanbul ignore next */ []));
|
|
248
|
+
this.selected = computed(() => {
|
|
249
|
+
const iso = this.country().toUpperCase();
|
|
250
|
+
return this.list().find((c) => c.iso === iso) ?? this.list()[0] ?? null;
|
|
251
|
+
}, /* @ts-ignore */
|
|
252
|
+
...(ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []));
|
|
253
|
+
this.filtered = computed(() => {
|
|
254
|
+
const q = this.normalize(this.query().trim().replace(/^\+/, ''));
|
|
255
|
+
if (!q)
|
|
256
|
+
return this.list();
|
|
257
|
+
return this.list().filter((c) => this.normalize(this.name(c)).includes(q) || c.dial.startsWith(q) || c.iso.toLowerCase() === q);
|
|
258
|
+
}, /* @ts-ignore */
|
|
259
|
+
...(ngDevMode ? [{ debugName: "filtered" }] : /* istanbul ignore next */ []));
|
|
260
|
+
this.activeId = computed(() => {
|
|
261
|
+
const c = this.filtered()[this.active()];
|
|
262
|
+
return c ? `${this.listId}-${c.iso}` : null;
|
|
263
|
+
}, /* @ts-ignore */
|
|
264
|
+
...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
|
|
265
|
+
this.display = computed(() => {
|
|
266
|
+
const c = this.selected();
|
|
267
|
+
return c ? cbFormatNational(c, this.national()) : this.national();
|
|
268
|
+
}, /* @ts-ignore */
|
|
269
|
+
...(ngDevMode ? [{ debugName: "display" }] : /* istanbul ignore next */ []));
|
|
270
|
+
this.examplePlaceholder = computed(() => {
|
|
271
|
+
const c = this.selected();
|
|
272
|
+
return c?.example ? cbFormatNational(c, c.example) : '';
|
|
273
|
+
}, /* @ts-ignore */
|
|
274
|
+
...(ngDevMode ? [{ debugName: "examplePlaceholder" }] : /* istanbul ignore next */ []));
|
|
275
|
+
this.isValid = computed(() => !this.national() || cbIsValidPhone(this.selected(), this.national()), /* @ts-ignore */
|
|
276
|
+
...(ngDevMode ? [{ debugName: "isValid" }] : /* istanbul ignore next */ []));
|
|
277
|
+
this.showInvalid = computed(() => this.fieldState.invalid() || (this.touched() && !this.isValid()), /* @ts-ignore */
|
|
278
|
+
...(ngDevMode ? [{ debugName: "showInvalid" }] : /* istanbul ignore next */ []));
|
|
279
|
+
this.errorText = computed(() => this.error() ?? (!this.isValid() ? this.t().phoneInvalid : ''), /* @ts-ignore */
|
|
280
|
+
...(ngDevMode ? [{ debugName: "errorText" }] : /* istanbul ignore next */ []));
|
|
281
|
+
this.countryLabel = computed(() => {
|
|
282
|
+
const c = this.selected();
|
|
283
|
+
return c ? `${this.t().phoneCountry}: ${this.name(c)} (+${c.dial})` : this.t().phoneCountry;
|
|
284
|
+
}, /* @ts-ignore */
|
|
285
|
+
...(ngDevMode ? [{ debugName: "countryLabel" }] : /* istanbul ignore next */ []));
|
|
286
|
+
this.describedBy = computed(() => {
|
|
287
|
+
if (this.showInvalid() && this.errorText())
|
|
288
|
+
return `${this.inputId}-error`;
|
|
289
|
+
if (this.hint())
|
|
290
|
+
return `${this.inputId}-hint`;
|
|
291
|
+
return null;
|
|
292
|
+
}, /* @ts-ignore */
|
|
293
|
+
...(ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []));
|
|
294
|
+
this.onChange = () => { };
|
|
295
|
+
this.onTouched = () => { };
|
|
296
|
+
this.onValidatorChange = () => { };
|
|
297
|
+
// `[(value)]` fuera de Angular Forms: un valor nuevo desde fuera se interpreta.
|
|
298
|
+
effect(() => {
|
|
299
|
+
const value = this.value();
|
|
300
|
+
untracked(() => {
|
|
301
|
+
if (value !== cbToE164(this.selected(), this.national()))
|
|
302
|
+
this.applyText(value, false);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
flag(c) {
|
|
307
|
+
return cbFlagEmoji(c.iso);
|
|
308
|
+
}
|
|
309
|
+
name(c) {
|
|
310
|
+
return this.displayNames()?.of(c.iso) ?? c.iso;
|
|
311
|
+
}
|
|
312
|
+
normalize(text) {
|
|
313
|
+
return text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
|
|
314
|
+
}
|
|
315
|
+
// --- ControlValueAccessor / Validator --------------------------------------
|
|
316
|
+
writeValue(value) {
|
|
317
|
+
this.applyText(value ?? '', false);
|
|
318
|
+
}
|
|
319
|
+
registerOnChange(fn) {
|
|
320
|
+
this.onChange = fn;
|
|
321
|
+
}
|
|
322
|
+
registerOnTouched(fn) {
|
|
323
|
+
this.onTouched = fn;
|
|
324
|
+
}
|
|
325
|
+
setDisabledState(isDisabled) {
|
|
326
|
+
this.cvaDisabled.set(isDisabled);
|
|
327
|
+
}
|
|
328
|
+
validate(_control) {
|
|
329
|
+
return this.isValid() ? null : { phone: true };
|
|
330
|
+
}
|
|
331
|
+
registerOnValidatorChange(fn) {
|
|
332
|
+
this.onValidatorChange = fn;
|
|
333
|
+
}
|
|
334
|
+
// --- Número ------------------------------------------------------------------
|
|
335
|
+
onInput(event) {
|
|
336
|
+
const el = event.target;
|
|
337
|
+
// Posición del cursor contada en dígitos, para restaurarla tras reformatear.
|
|
338
|
+
const caretDigits = el.value.slice(0, el.selectionStart ?? el.value.length).replace(/\D/g, '').length;
|
|
339
|
+
this.applyText(el.value, true);
|
|
340
|
+
const formatted = this.display();
|
|
341
|
+
el.value = formatted;
|
|
342
|
+
let pos = 0;
|
|
343
|
+
for (let seen = 0; pos < formatted.length && seen < caretDigits; pos++)
|
|
344
|
+
if (/\d/.test(formatted[pos]))
|
|
345
|
+
seen++;
|
|
346
|
+
el.setSelectionRange?.(pos, pos);
|
|
347
|
+
}
|
|
348
|
+
onBlur() {
|
|
349
|
+
this.touched.set(true);
|
|
350
|
+
this.onTouched();
|
|
351
|
+
}
|
|
352
|
+
/** Interpreta texto escrito, pegado o recibido (E.164 o nacional). */
|
|
353
|
+
applyText(text, emit) {
|
|
354
|
+
const parsed = cbParsePhone(text, this.selected(), this.list());
|
|
355
|
+
if (parsed.country && parsed.country.iso !== this.selected()?.iso)
|
|
356
|
+
this.country.set(parsed.country.iso);
|
|
357
|
+
const country = parsed.country ?? this.selected();
|
|
358
|
+
const max = country ? Math.max(...country.lengths) : 15;
|
|
359
|
+
this.national.set(parsed.national.slice(0, max));
|
|
360
|
+
this.publish(emit);
|
|
361
|
+
}
|
|
362
|
+
publish(emit) {
|
|
363
|
+
const country = this.selected();
|
|
364
|
+
const national = this.national();
|
|
365
|
+
const e164 = cbToE164(country, national);
|
|
366
|
+
this.value.set(e164);
|
|
367
|
+
this.onValidatorChange();
|
|
368
|
+
if (!emit)
|
|
369
|
+
return;
|
|
370
|
+
this.onChange(e164);
|
|
371
|
+
this.phoneChange.emit({ e164, national, country: country?.iso ?? '', valid: !!national && cbIsValidPhone(country, national) });
|
|
372
|
+
}
|
|
373
|
+
// --- Selector de país ------------------------------------------------------------
|
|
374
|
+
toggle() {
|
|
375
|
+
if (this.open())
|
|
376
|
+
this.close();
|
|
377
|
+
else
|
|
378
|
+
this.openPanel();
|
|
379
|
+
}
|
|
380
|
+
openFromKeyboard(event) {
|
|
381
|
+
event.preventDefault();
|
|
382
|
+
if (!this.open())
|
|
383
|
+
this.openPanel();
|
|
384
|
+
}
|
|
385
|
+
openPanel() {
|
|
386
|
+
if (this.overlayRef || this.isDisabled() || this.countryLocked())
|
|
387
|
+
return;
|
|
388
|
+
this.query.set('');
|
|
389
|
+
const index = this.list().findIndex((c) => c.iso === this.selected()?.iso);
|
|
390
|
+
this.active.set(Math.max(0, index));
|
|
391
|
+
this.overlayRef = this.overlay.create({
|
|
392
|
+
hasBackdrop: true,
|
|
393
|
+
backdropClass: 'cdk-overlay-transparent-backdrop',
|
|
394
|
+
scrollStrategy: this.overlay.scrollStrategies.reposition(),
|
|
395
|
+
positionStrategy: this.overlay
|
|
396
|
+
.position()
|
|
397
|
+
.flexibleConnectedTo(this.triggerEl().nativeElement)
|
|
398
|
+
.withPositions([
|
|
399
|
+
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top', offsetY: 4 },
|
|
400
|
+
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -4 },
|
|
401
|
+
])
|
|
402
|
+
.withPush(true),
|
|
403
|
+
});
|
|
404
|
+
this.overlayRef.attach(new TemplatePortal(this.panelTpl(), this.vcr));
|
|
405
|
+
this.overlayRef.backdropClick().subscribe(() => this.close());
|
|
406
|
+
this.open.set(true);
|
|
407
|
+
afterNextRender(() => {
|
|
408
|
+
this.searchEl()?.nativeElement.focus();
|
|
409
|
+
this.scrollActiveIntoView();
|
|
410
|
+
}, { injector: this.injector });
|
|
411
|
+
}
|
|
412
|
+
/** Cierra la lista de países. */
|
|
413
|
+
close(focusTrigger = true) {
|
|
414
|
+
if (!this.overlayRef)
|
|
415
|
+
return;
|
|
416
|
+
this.overlayRef.dispose();
|
|
417
|
+
this.overlayRef = null;
|
|
418
|
+
this.open.set(false);
|
|
419
|
+
if (focusTrigger)
|
|
420
|
+
this.triggerEl().nativeElement.focus();
|
|
421
|
+
}
|
|
422
|
+
choose(c) {
|
|
423
|
+
this.country.set(c.iso);
|
|
424
|
+
this.national.set(this.national().slice(0, Math.max(...c.lengths)));
|
|
425
|
+
this.close(false);
|
|
426
|
+
this.publish(true);
|
|
427
|
+
this.fieldEl().nativeElement.focus();
|
|
428
|
+
}
|
|
429
|
+
onSearchKeydown(event) {
|
|
430
|
+
const count = this.filtered().length;
|
|
431
|
+
switch (event.key) {
|
|
432
|
+
case 'ArrowDown':
|
|
433
|
+
case 'ArrowUp':
|
|
434
|
+
event.preventDefault();
|
|
435
|
+
if (!count)
|
|
436
|
+
return;
|
|
437
|
+
this.active.set((this.active() + (event.key === 'ArrowDown' ? 1 : -1) + count) % count);
|
|
438
|
+
this.scrollActiveIntoView();
|
|
439
|
+
break;
|
|
440
|
+
case 'Enter': {
|
|
441
|
+
event.preventDefault();
|
|
442
|
+
const c = this.filtered()[this.active()];
|
|
443
|
+
if (c)
|
|
444
|
+
this.choose(c);
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
case 'Escape':
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
this.close();
|
|
450
|
+
break;
|
|
451
|
+
case 'Tab':
|
|
452
|
+
this.close(false);
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
scrollActiveIntoView() {
|
|
457
|
+
const id = this.activeId();
|
|
458
|
+
afterNextRender(() => (id ? this.overlayRef?.overlayElement.querySelector(`#${id}`)?.scrollIntoView?.({ block: 'nearest' }) : null), {
|
|
459
|
+
injector: this.injector,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbPhoneInput, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
463
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: CbPhoneInput, isStandalone: true, selector: "cb-phone-input", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, country: { classPropertyName: "country", publicName: "country", isSignal: true, isRequired: false, transformFunction: null }, countries: { classPropertyName: "countries", publicName: "countries", isSignal: true, isRequired: false, transformFunction: null }, preferredCountries: { classPropertyName: "preferredCountries", publicName: "preferredCountries", isSignal: true, isRequired: false, transformFunction: null }, countryLocked: { classPropertyName: "countryLocked", publicName: "countryLocked", isSignal: true, isRequired: false, transformFunction: null }, showFlag: { classPropertyName: "showFlag", publicName: "showFlag", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, requiredIndicator: { classPropertyName: "requiredIndicator", publicName: "requiredIndicator", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", country: "countryChange", phoneChange: "phoneChange" }, host: { classAttribute: "cb-phone-input" }, providers: [
|
|
464
|
+
{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CbPhoneInput), multi: true },
|
|
465
|
+
{ provide: NG_VALIDATORS, useExisting: forwardRef(() => CbPhoneInput), multi: true },
|
|
466
|
+
], viewQueries: [{ propertyName: "triggerEl", first: true, predicate: ["trigger"], descendants: true, isSignal: true }, { propertyName: "fieldEl", first: true, predicate: ["field"], descendants: true, isSignal: true }, { propertyName: "searchEl", first: true, predicate: ["search"], descendants: true, isSignal: true }, { propertyName: "panelTpl", first: true, predicate: ["panel"], descendants: true, isSignal: true }], ngImport: i0, template: `
|
|
467
|
+
@if (label()) {
|
|
468
|
+
<label class="cb-phone-input__label" [attr.for]="inputId">
|
|
469
|
+
{{ label() }}
|
|
470
|
+
@if (fieldState.indicator(); as mark) {
|
|
471
|
+
<span [class]="'cb-phone-input__required cb-phone-input__required--' + mark.kind" [attr.aria-hidden]="mark.kind === 'optional' ? null : 'true'">{{ mark.text }}</span>
|
|
472
|
+
}
|
|
473
|
+
</label>
|
|
474
|
+
}
|
|
475
|
+
<div
|
|
476
|
+
class="cb-phone-input__control"
|
|
477
|
+
[class]="'cb-phone-input__control--' + size()"
|
|
478
|
+
[class.cb-is-invalid]="showInvalid()"
|
|
479
|
+
[class.cb-is-disabled]="isDisabled()"
|
|
480
|
+
>
|
|
481
|
+
<button
|
|
482
|
+
#trigger
|
|
483
|
+
type="button"
|
|
484
|
+
class="cb-phone-input__country"
|
|
485
|
+
aria-haspopup="listbox"
|
|
486
|
+
[attr.aria-expanded]="open()"
|
|
487
|
+
[attr.aria-controls]="open() ? listId : null"
|
|
488
|
+
[attr.aria-label]="countryLabel()"
|
|
489
|
+
[disabled]="isDisabled() || countryLocked()"
|
|
490
|
+
(click)="toggle()"
|
|
491
|
+
(keydown.arrowdown)="openFromKeyboard($event)"
|
|
492
|
+
>
|
|
493
|
+
@if (selected(); as c) {
|
|
494
|
+
@if (showFlag()) {
|
|
495
|
+
<span class="cb-phone-input__flag" aria-hidden="true">{{ flag(c) }}</span>
|
|
496
|
+
}
|
|
497
|
+
<span class="cb-phone-input__dial" aria-hidden="true">+{{ c.dial }}</span>
|
|
498
|
+
}
|
|
499
|
+
@if (!countryLocked()) {
|
|
500
|
+
<cb-icon name="chevron-down" [size]="14" aria-hidden="true" />
|
|
501
|
+
}
|
|
502
|
+
</button>
|
|
503
|
+
<input
|
|
504
|
+
#field
|
|
505
|
+
class="cb-phone-input__field"
|
|
506
|
+
type="tel"
|
|
507
|
+
inputmode="tel"
|
|
508
|
+
autocomplete="tel-national"
|
|
509
|
+
[id]="inputId"
|
|
510
|
+
[value]="display()"
|
|
511
|
+
[placeholder]="placeholder() ?? examplePlaceholder()"
|
|
512
|
+
[disabled]="isDisabled()"
|
|
513
|
+
[required]="fieldState.required()"
|
|
514
|
+
[attr.aria-invalid]="showInvalid() ? 'true' : null"
|
|
515
|
+
[attr.aria-describedby]="describedBy()"
|
|
516
|
+
(input)="onInput($event)"
|
|
517
|
+
(blur)="onBlur()"
|
|
518
|
+
/>
|
|
519
|
+
</div>
|
|
520
|
+
@if (showInvalid() && errorText()) {
|
|
521
|
+
<p class="cb-phone-input__message cb-phone-input__message--error" [id]="inputId + '-error'" role="alert">{{ errorText() }}</p>
|
|
522
|
+
} @else if (hint()) {
|
|
523
|
+
<p class="cb-phone-input__message" [id]="inputId + '-hint'">{{ hint() }}</p>
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
<ng-template #panel>
|
|
527
|
+
<div class="cb-phone-input__panel">
|
|
528
|
+
<input
|
|
529
|
+
#search
|
|
530
|
+
class="cb-phone-input__search"
|
|
531
|
+
type="text"
|
|
532
|
+
role="combobox"
|
|
533
|
+
aria-autocomplete="list"
|
|
534
|
+
aria-expanded="true"
|
|
535
|
+
autocomplete="off"
|
|
536
|
+
[attr.aria-controls]="listId"
|
|
537
|
+
[attr.aria-activedescendant]="activeId()"
|
|
538
|
+
[attr.aria-label]="t().searchCountry"
|
|
539
|
+
[placeholder]="t().searchCountry"
|
|
540
|
+
[value]="query()"
|
|
541
|
+
(input)="query.set($any($event.target).value); active.set(0)"
|
|
542
|
+
(keydown)="onSearchKeydown($event)"
|
|
543
|
+
/>
|
|
544
|
+
<ul class="cb-phone-input__list" role="listbox" [id]="listId" [attr.aria-label]="t().phoneCountry">
|
|
545
|
+
@for (c of filtered(); track c.iso; let i = $index) {
|
|
546
|
+
<li
|
|
547
|
+
role="option"
|
|
548
|
+
class="cb-phone-input__option"
|
|
549
|
+
[id]="listId + '-' + c.iso"
|
|
550
|
+
[class.cb-phone-input__option--active]="i === active()"
|
|
551
|
+
[attr.aria-selected]="c.iso === selected()?.iso"
|
|
552
|
+
(mousemove)="active.set(i)"
|
|
553
|
+
(mousedown)="$event.preventDefault()"
|
|
554
|
+
(click)="choose(c)"
|
|
555
|
+
>
|
|
556
|
+
@if (showFlag()) {
|
|
557
|
+
<span class="cb-phone-input__flag" aria-hidden="true">{{ flag(c) }}</span>
|
|
558
|
+
}
|
|
559
|
+
<span class="cb-phone-input__name">{{ name(c) }}</span>
|
|
560
|
+
<span class="cb-phone-input__option-dial">+{{ c.dial }}</span>
|
|
561
|
+
</li>
|
|
562
|
+
} @empty {
|
|
563
|
+
<li class="cb-phone-input__empty" role="presentation">{{ t().noResults }}</li>
|
|
564
|
+
}
|
|
565
|
+
</ul>
|
|
566
|
+
</div>
|
|
567
|
+
</ng-template>
|
|
568
|
+
`, isInline: true, styles: [":host{display:block;font-family:var(--cb-font-sans)}.cb-phone-input__label{display:block;margin-bottom:var(--cb-space-1);font-size:var(--cb-text-sm);font-weight:var(--cb-font-weight-medium);color:var(--cb-color-text)}.cb-phone-input__required{margin-left:2px;color:var(--cb-color-danger)}.cb-phone-input__required--required,.cb-phone-input__required--optional{margin-left:.25rem;color:var(--cb-color-text-muted);font-size:.85em;font-weight:var(--cb-font-weight-normal, 400)}.cb-phone-input__control{display:flex;align-items:stretch;box-sizing:border-box;width:100%;overflow:hidden;border:var(--cb-border-width, 1px) solid var(--cb-color-border-strong);border-radius:var(--cb-radius-md);background-color:var(--cb-color-bg);transition:border-color var(--cb-duration-fast) var(--cb-ease),box-shadow var(--cb-duration-fast) var(--cb-ease)}.cb-phone-input__control:hover:not(.cb-is-disabled):not(:focus-within){border-color:var(--cb-color-text-muted)}.cb-phone-input__control:focus-within{border-color:var(--cb-color-primary-500);box-shadow:0 0 0 3px color-mix(in srgb,var(--cb-color-primary-500) 25%,transparent)}.cb-phone-input__control.cb-is-invalid{border-color:var(--cb-color-danger)}.cb-phone-input__control.cb-is-invalid:focus-within{box-shadow:0 0 0 3px color-mix(in srgb,var(--cb-color-danger) 25%,transparent)}.cb-phone-input__control.cb-is-disabled{background-color:var(--cb-color-surface);opacity:.8}.cb-phone-input__country{display:inline-flex;flex:none;align-items:center;gap:.375rem;padding:0 .625rem 0 .75rem;border:0;border-right:1px solid var(--cb-color-border);background:var(--cb-color-surface);color:var(--cb-color-text);font:inherit;cursor:pointer}.cb-phone-input__country:disabled{cursor:default}.cb-phone-input__country:focus-visible{outline:2px solid var(--cb-color-focus-ring);outline-offset:-2px}.cb-phone-input__flag{font-size:1.15em;line-height:1}.cb-phone-input__dial{font-variant-numeric:tabular-nums}.cb-phone-input__field{flex:1;min-width:0;border:0;outline:none;background:transparent;color:var(--cb-color-text);font:inherit;font-variant-numeric:tabular-nums}.cb-phone-input__field::placeholder{color:var(--cb-color-text-muted)}.cb-phone-input__field:disabled{cursor:not-allowed;color:var(--cb-color-text-muted)}.cb-phone-input__control--sm{min-height:2rem;font-size:var(--cb-text-sm)}.cb-phone-input__control--sm .cb-phone-input__field{padding:var(--cb-space-1) var(--cb-space-2)}.cb-phone-input__control--md{min-height:2.5rem;font-size:var(--cb-text-base)}.cb-phone-input__control--md .cb-phone-input__field{padding:var(--cb-space-2) var(--cb-space-3)}.cb-phone-input__control--lg{min-height:3rem;font-size:var(--cb-text-lg)}.cb-phone-input__control--lg .cb-phone-input__field{padding:var(--cb-space-3) var(--cb-space-4)}.cb-phone-input__message{margin:var(--cb-space-1) 0 0;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm)}.cb-phone-input__message--error{color:var(--cb-color-danger)}.cb-phone-input__panel{display:flex;flex-direction:column;width:20rem;max-width:calc(100vw - 2rem);max-height:20rem;overflow:hidden;border:1px solid var(--cb-color-border);border-radius:var(--cb-radius-md);background:var(--cb-color-surface-raised);box-shadow:var(--cb-shadow-lg);color:var(--cb-color-text);font-family:var(--cb-font-sans)}.cb-phone-input__search{margin:.5rem;padding:.5rem .625rem;border:1px solid var(--cb-color-border-strong);border-radius:var(--cb-radius-sm);background:var(--cb-color-bg);color:inherit;font:inherit;font-size:var(--cb-text-sm)}.cb-phone-input__search:focus-visible{outline:2px solid var(--cb-color-focus-ring);outline-offset:0}.cb-phone-input__list{flex:1;margin:0;padding:0 .375rem .375rem;overflow-y:auto;list-style:none}.cb-phone-input__option{display:flex;align-items:center;gap:.625rem;padding:.5rem;border-radius:var(--cb-radius-sm);font-size:var(--cb-text-sm);cursor:pointer}.cb-phone-input__option--active{background:var(--cb-color-surface-hover)}.cb-phone-input__option[aria-selected=true]{font-weight:var(--cb-font-weight-semibold, 600)}.cb-phone-input__name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cb-phone-input__option-dial{color:var(--cb-color-text-muted);font-variant-numeric:tabular-nums}.cb-phone-input__empty{padding:1rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm);text-align:center}\n"], dependencies: [{ kind: "component", type: CbIcon, selector: "cb-icon", inputs: ["name", "size", "spin", "ariaLabel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
569
|
+
}
|
|
570
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: CbPhoneInput, decorators: [{
|
|
571
|
+
type: Component,
|
|
572
|
+
args: [{ selector: 'cb-phone-input', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.Emulated, imports: [CbIcon], host: { class: 'cb-phone-input' }, providers: [
|
|
573
|
+
{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CbPhoneInput), multi: true },
|
|
574
|
+
{ provide: NG_VALIDATORS, useExisting: forwardRef(() => CbPhoneInput), multi: true },
|
|
575
|
+
], template: `
|
|
576
|
+
@if (label()) {
|
|
577
|
+
<label class="cb-phone-input__label" [attr.for]="inputId">
|
|
578
|
+
{{ label() }}
|
|
579
|
+
@if (fieldState.indicator(); as mark) {
|
|
580
|
+
<span [class]="'cb-phone-input__required cb-phone-input__required--' + mark.kind" [attr.aria-hidden]="mark.kind === 'optional' ? null : 'true'">{{ mark.text }}</span>
|
|
581
|
+
}
|
|
582
|
+
</label>
|
|
583
|
+
}
|
|
584
|
+
<div
|
|
585
|
+
class="cb-phone-input__control"
|
|
586
|
+
[class]="'cb-phone-input__control--' + size()"
|
|
587
|
+
[class.cb-is-invalid]="showInvalid()"
|
|
588
|
+
[class.cb-is-disabled]="isDisabled()"
|
|
589
|
+
>
|
|
590
|
+
<button
|
|
591
|
+
#trigger
|
|
592
|
+
type="button"
|
|
593
|
+
class="cb-phone-input__country"
|
|
594
|
+
aria-haspopup="listbox"
|
|
595
|
+
[attr.aria-expanded]="open()"
|
|
596
|
+
[attr.aria-controls]="open() ? listId : null"
|
|
597
|
+
[attr.aria-label]="countryLabel()"
|
|
598
|
+
[disabled]="isDisabled() || countryLocked()"
|
|
599
|
+
(click)="toggle()"
|
|
600
|
+
(keydown.arrowdown)="openFromKeyboard($event)"
|
|
601
|
+
>
|
|
602
|
+
@if (selected(); as c) {
|
|
603
|
+
@if (showFlag()) {
|
|
604
|
+
<span class="cb-phone-input__flag" aria-hidden="true">{{ flag(c) }}</span>
|
|
605
|
+
}
|
|
606
|
+
<span class="cb-phone-input__dial" aria-hidden="true">+{{ c.dial }}</span>
|
|
607
|
+
}
|
|
608
|
+
@if (!countryLocked()) {
|
|
609
|
+
<cb-icon name="chevron-down" [size]="14" aria-hidden="true" />
|
|
610
|
+
}
|
|
611
|
+
</button>
|
|
612
|
+
<input
|
|
613
|
+
#field
|
|
614
|
+
class="cb-phone-input__field"
|
|
615
|
+
type="tel"
|
|
616
|
+
inputmode="tel"
|
|
617
|
+
autocomplete="tel-national"
|
|
618
|
+
[id]="inputId"
|
|
619
|
+
[value]="display()"
|
|
620
|
+
[placeholder]="placeholder() ?? examplePlaceholder()"
|
|
621
|
+
[disabled]="isDisabled()"
|
|
622
|
+
[required]="fieldState.required()"
|
|
623
|
+
[attr.aria-invalid]="showInvalid() ? 'true' : null"
|
|
624
|
+
[attr.aria-describedby]="describedBy()"
|
|
625
|
+
(input)="onInput($event)"
|
|
626
|
+
(blur)="onBlur()"
|
|
627
|
+
/>
|
|
628
|
+
</div>
|
|
629
|
+
@if (showInvalid() && errorText()) {
|
|
630
|
+
<p class="cb-phone-input__message cb-phone-input__message--error" [id]="inputId + '-error'" role="alert">{{ errorText() }}</p>
|
|
631
|
+
} @else if (hint()) {
|
|
632
|
+
<p class="cb-phone-input__message" [id]="inputId + '-hint'">{{ hint() }}</p>
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
<ng-template #panel>
|
|
636
|
+
<div class="cb-phone-input__panel">
|
|
637
|
+
<input
|
|
638
|
+
#search
|
|
639
|
+
class="cb-phone-input__search"
|
|
640
|
+
type="text"
|
|
641
|
+
role="combobox"
|
|
642
|
+
aria-autocomplete="list"
|
|
643
|
+
aria-expanded="true"
|
|
644
|
+
autocomplete="off"
|
|
645
|
+
[attr.aria-controls]="listId"
|
|
646
|
+
[attr.aria-activedescendant]="activeId()"
|
|
647
|
+
[attr.aria-label]="t().searchCountry"
|
|
648
|
+
[placeholder]="t().searchCountry"
|
|
649
|
+
[value]="query()"
|
|
650
|
+
(input)="query.set($any($event.target).value); active.set(0)"
|
|
651
|
+
(keydown)="onSearchKeydown($event)"
|
|
652
|
+
/>
|
|
653
|
+
<ul class="cb-phone-input__list" role="listbox" [id]="listId" [attr.aria-label]="t().phoneCountry">
|
|
654
|
+
@for (c of filtered(); track c.iso; let i = $index) {
|
|
655
|
+
<li
|
|
656
|
+
role="option"
|
|
657
|
+
class="cb-phone-input__option"
|
|
658
|
+
[id]="listId + '-' + c.iso"
|
|
659
|
+
[class.cb-phone-input__option--active]="i === active()"
|
|
660
|
+
[attr.aria-selected]="c.iso === selected()?.iso"
|
|
661
|
+
(mousemove)="active.set(i)"
|
|
662
|
+
(mousedown)="$event.preventDefault()"
|
|
663
|
+
(click)="choose(c)"
|
|
664
|
+
>
|
|
665
|
+
@if (showFlag()) {
|
|
666
|
+
<span class="cb-phone-input__flag" aria-hidden="true">{{ flag(c) }}</span>
|
|
667
|
+
}
|
|
668
|
+
<span class="cb-phone-input__name">{{ name(c) }}</span>
|
|
669
|
+
<span class="cb-phone-input__option-dial">+{{ c.dial }}</span>
|
|
670
|
+
</li>
|
|
671
|
+
} @empty {
|
|
672
|
+
<li class="cb-phone-input__empty" role="presentation">{{ t().noResults }}</li>
|
|
673
|
+
}
|
|
674
|
+
</ul>
|
|
675
|
+
</div>
|
|
676
|
+
</ng-template>
|
|
677
|
+
`, styles: [":host{display:block;font-family:var(--cb-font-sans)}.cb-phone-input__label{display:block;margin-bottom:var(--cb-space-1);font-size:var(--cb-text-sm);font-weight:var(--cb-font-weight-medium);color:var(--cb-color-text)}.cb-phone-input__required{margin-left:2px;color:var(--cb-color-danger)}.cb-phone-input__required--required,.cb-phone-input__required--optional{margin-left:.25rem;color:var(--cb-color-text-muted);font-size:.85em;font-weight:var(--cb-font-weight-normal, 400)}.cb-phone-input__control{display:flex;align-items:stretch;box-sizing:border-box;width:100%;overflow:hidden;border:var(--cb-border-width, 1px) solid var(--cb-color-border-strong);border-radius:var(--cb-radius-md);background-color:var(--cb-color-bg);transition:border-color var(--cb-duration-fast) var(--cb-ease),box-shadow var(--cb-duration-fast) var(--cb-ease)}.cb-phone-input__control:hover:not(.cb-is-disabled):not(:focus-within){border-color:var(--cb-color-text-muted)}.cb-phone-input__control:focus-within{border-color:var(--cb-color-primary-500);box-shadow:0 0 0 3px color-mix(in srgb,var(--cb-color-primary-500) 25%,transparent)}.cb-phone-input__control.cb-is-invalid{border-color:var(--cb-color-danger)}.cb-phone-input__control.cb-is-invalid:focus-within{box-shadow:0 0 0 3px color-mix(in srgb,var(--cb-color-danger) 25%,transparent)}.cb-phone-input__control.cb-is-disabled{background-color:var(--cb-color-surface);opacity:.8}.cb-phone-input__country{display:inline-flex;flex:none;align-items:center;gap:.375rem;padding:0 .625rem 0 .75rem;border:0;border-right:1px solid var(--cb-color-border);background:var(--cb-color-surface);color:var(--cb-color-text);font:inherit;cursor:pointer}.cb-phone-input__country:disabled{cursor:default}.cb-phone-input__country:focus-visible{outline:2px solid var(--cb-color-focus-ring);outline-offset:-2px}.cb-phone-input__flag{font-size:1.15em;line-height:1}.cb-phone-input__dial{font-variant-numeric:tabular-nums}.cb-phone-input__field{flex:1;min-width:0;border:0;outline:none;background:transparent;color:var(--cb-color-text);font:inherit;font-variant-numeric:tabular-nums}.cb-phone-input__field::placeholder{color:var(--cb-color-text-muted)}.cb-phone-input__field:disabled{cursor:not-allowed;color:var(--cb-color-text-muted)}.cb-phone-input__control--sm{min-height:2rem;font-size:var(--cb-text-sm)}.cb-phone-input__control--sm .cb-phone-input__field{padding:var(--cb-space-1) var(--cb-space-2)}.cb-phone-input__control--md{min-height:2.5rem;font-size:var(--cb-text-base)}.cb-phone-input__control--md .cb-phone-input__field{padding:var(--cb-space-2) var(--cb-space-3)}.cb-phone-input__control--lg{min-height:3rem;font-size:var(--cb-text-lg)}.cb-phone-input__control--lg .cb-phone-input__field{padding:var(--cb-space-3) var(--cb-space-4)}.cb-phone-input__message{margin:var(--cb-space-1) 0 0;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm)}.cb-phone-input__message--error{color:var(--cb-color-danger)}.cb-phone-input__panel{display:flex;flex-direction:column;width:20rem;max-width:calc(100vw - 2rem);max-height:20rem;overflow:hidden;border:1px solid var(--cb-color-border);border-radius:var(--cb-radius-md);background:var(--cb-color-surface-raised);box-shadow:var(--cb-shadow-lg);color:var(--cb-color-text);font-family:var(--cb-font-sans)}.cb-phone-input__search{margin:.5rem;padding:.5rem .625rem;border:1px solid var(--cb-color-border-strong);border-radius:var(--cb-radius-sm);background:var(--cb-color-bg);color:inherit;font:inherit;font-size:var(--cb-text-sm)}.cb-phone-input__search:focus-visible{outline:2px solid var(--cb-color-focus-ring);outline-offset:0}.cb-phone-input__list{flex:1;margin:0;padding:0 .375rem .375rem;overflow-y:auto;list-style:none}.cb-phone-input__option{display:flex;align-items:center;gap:.625rem;padding:.5rem;border-radius:var(--cb-radius-sm);font-size:var(--cb-text-sm);cursor:pointer}.cb-phone-input__option--active{background:var(--cb-color-surface-hover)}.cb-phone-input__option[aria-selected=true]{font-weight:var(--cb-font-weight-semibold, 600)}.cb-phone-input__name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cb-phone-input__option-dial{color:var(--cb-color-text-muted);font-variant-numeric:tabular-nums}.cb-phone-input__empty{padding:1rem;color:var(--cb-color-text-muted);font-size:var(--cb-text-sm);text-align:center}\n"] }]
|
|
678
|
+
}], ctorParameters: () => [], propDecorators: { triggerEl: [{ type: i0.ViewChild, args: ['trigger', { isSignal: true }] }], fieldEl: [{ type: i0.ViewChild, args: ['field', { isSignal: true }] }], searchEl: [{ type: i0.ViewChild, args: ['search', { isSignal: true }] }], panelTpl: [{ type: i0.ViewChild, args: ['panel', { isSignal: true }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], country: [{ type: i0.Input, args: [{ isSignal: true, alias: "country", required: false }] }, { type: i0.Output, args: ["countryChange"] }], countries: [{ type: i0.Input, args: [{ isSignal: true, alias: "countries", required: false }] }], preferredCountries: [{ type: i0.Input, args: [{ isSignal: true, alias: "preferredCountries", required: false }] }], countryLocked: [{ type: i0.Input, args: [{ isSignal: true, alias: "countryLocked", required: false }] }], showFlag: [{ type: i0.Input, args: [{ isSignal: true, alias: "showFlag", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], requiredIndicator: [{ type: i0.Input, args: [{ isSignal: true, alias: "requiredIndicator", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], phoneChange: [{ type: i0.Output, args: ["phoneChange"] }] } });
|
|
679
|
+
|
|
680
|
+
/*
|
|
681
|
+
* Public API Surface de @caribeng/ui/phone-input
|
|
682
|
+
*/
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Generated bundle index. Do not edit.
|
|
686
|
+
*/
|
|
687
|
+
|
|
688
|
+
export { CB_PHONE_COUNTRIES, CbPhoneInput, cbFlagEmoji, cbFormatNational, cbIsValidPhone, cbParsePhone, cbToE164 };
|