@clyrex-digital/clyrex-controls-dev 0.8.1-dev.20260926063530 → 0.8.1-dev.20260930053845

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.
@@ -18,7 +18,7 @@ import {
18
18
  SelectWithSearchInput_default,
19
19
  Select_default,
20
20
  TimeInput_default
21
- } from "./chunk-LDS5ZLVG.mjs";
21
+ } from "./chunk-JT7G3DNR.mjs";
22
22
  import {
23
23
  Hyperlink,
24
24
  Icon_default,
@@ -351,12 +351,328 @@ var PercentageInput = (props) => {
351
351
  };
352
352
  var PercentageInput_default = PercentageInput;
353
353
 
354
+ // src/components/utilities/CountryCodes.tsx
355
+ var COUNTRY_CODES = [
356
+ { name: "Afghanistan", iso2: "AF", dialCode: "+93" },
357
+ { name: "\xC5land Islands", iso2: "AX", dialCode: "+358" },
358
+ { name: "Albania", iso2: "AL", dialCode: "+355" },
359
+ { name: "Algeria", iso2: "DZ", dialCode: "+213" },
360
+ { name: "American Samoa", iso2: "AS", dialCode: "+1684" },
361
+ { name: "Andorra", iso2: "AD", dialCode: "+376" },
362
+ { name: "Angola", iso2: "AO", dialCode: "+244" },
363
+ { name: "Anguilla", iso2: "AI", dialCode: "+1264" },
364
+ { name: "Antigua and Barbuda", iso2: "AG", dialCode: "+1268" },
365
+ { name: "Argentina", iso2: "AR", dialCode: "+54" },
366
+ { name: "Armenia", iso2: "AM", dialCode: "+374" },
367
+ { name: "Aruba", iso2: "AW", dialCode: "+297" },
368
+ { name: "Australia", iso2: "AU", dialCode: "+61" },
369
+ { name: "Austria", iso2: "AT", dialCode: "+43" },
370
+ { name: "Azerbaijan", iso2: "AZ", dialCode: "+994" },
371
+ { name: "Bahamas", iso2: "BS", dialCode: "+1242" },
372
+ { name: "Bahrain", iso2: "BH", dialCode: "+973" },
373
+ { name: "Bangladesh", iso2: "BD", dialCode: "+880" },
374
+ { name: "Barbados", iso2: "BB", dialCode: "+1246" },
375
+ { name: "Belarus", iso2: "BY", dialCode: "+375" },
376
+ { name: "Belgium", iso2: "BE", dialCode: "+32" },
377
+ { name: "Belize", iso2: "BZ", dialCode: "+501" },
378
+ { name: "Benin", iso2: "BJ", dialCode: "+229" },
379
+ { name: "Bermuda", iso2: "BM", dialCode: "+1441" },
380
+ { name: "Bhutan", iso2: "BT", dialCode: "+975" },
381
+ { name: "Bolivia", iso2: "BO", dialCode: "+591" },
382
+ { name: "Bosnia and Herzegovina", iso2: "BA", dialCode: "+387" },
383
+ { name: "Botswana", iso2: "BW", dialCode: "+267" },
384
+ { name: "Brazil", iso2: "BR", dialCode: "+55" },
385
+ { name: "British Indian Ocean Territory", iso2: "IO", dialCode: "+246" },
386
+ { name: "British Virgin Islands", iso2: "VG", dialCode: "+1284" },
387
+ { name: "Brunei", iso2: "BN", dialCode: "+673" },
388
+ { name: "Bulgaria", iso2: "BG", dialCode: "+359" },
389
+ { name: "Burkina Faso", iso2: "BF", dialCode: "+226" },
390
+ { name: "Burundi", iso2: "BI", dialCode: "+257" },
391
+ { name: "Cambodia", iso2: "KH", dialCode: "+855" },
392
+ { name: "Cameroon", iso2: "CM", dialCode: "+237" },
393
+ { name: "Canada", iso2: "CA", dialCode: "+1" },
394
+ { name: "Cape Verde", iso2: "CV", dialCode: "+238" },
395
+ { name: "Caribbean Netherlands", iso2: "BQ", dialCode: "+599" },
396
+ { name: "Cayman Islands", iso2: "KY", dialCode: "+1345" },
397
+ { name: "Central African Republic", iso2: "CF", dialCode: "+236" },
398
+ { name: "Chad", iso2: "TD", dialCode: "+235" },
399
+ { name: "Chile", iso2: "CL", dialCode: "+56" },
400
+ { name: "China", iso2: "CN", dialCode: "+86" },
401
+ { name: "Christmas Island", iso2: "CX", dialCode: "+61" },
402
+ { name: "Cocos (Keeling) Islands", iso2: "CC", dialCode: "+61" },
403
+ { name: "Colombia", iso2: "CO", dialCode: "+57" },
404
+ { name: "Comoros", iso2: "KM", dialCode: "+269" },
405
+ { name: "Congo", iso2: "CG", dialCode: "+242" },
406
+ { name: "Congo (DRC)", iso2: "CD", dialCode: "+243" },
407
+ { name: "Cook Islands", iso2: "CK", dialCode: "+682" },
408
+ { name: "Costa Rica", iso2: "CR", dialCode: "+506" },
409
+ { name: "C\xF4te d'Ivoire", iso2: "CI", dialCode: "+225" },
410
+ { name: "Croatia", iso2: "HR", dialCode: "+385" },
411
+ { name: "Cuba", iso2: "CU", dialCode: "+53" },
412
+ { name: "Cura\xE7ao", iso2: "CW", dialCode: "+599" },
413
+ { name: "Cyprus", iso2: "CY", dialCode: "+357" },
414
+ { name: "Czech Republic", iso2: "CZ", dialCode: "+420" },
415
+ { name: "Denmark", iso2: "DK", dialCode: "+45" },
416
+ { name: "Djibouti", iso2: "DJ", dialCode: "+253" },
417
+ { name: "Dominica", iso2: "DM", dialCode: "+1767" },
418
+ { name: "Dominican Republic", iso2: "DO", dialCode: "+1" },
419
+ { name: "Ecuador", iso2: "EC", dialCode: "+593" },
420
+ { name: "Egypt", iso2: "EG", dialCode: "+20" },
421
+ { name: "El Salvador", iso2: "SV", dialCode: "+503" },
422
+ { name: "Equatorial Guinea", iso2: "GQ", dialCode: "+240" },
423
+ { name: "Eritrea", iso2: "ER", dialCode: "+291" },
424
+ { name: "Estonia", iso2: "EE", dialCode: "+372" },
425
+ { name: "Eswatini", iso2: "SZ", dialCode: "+268" },
426
+ { name: "Ethiopia", iso2: "ET", dialCode: "+251" },
427
+ { name: "Falkland Islands", iso2: "FK", dialCode: "+500" },
428
+ { name: "Faroe Islands", iso2: "FO", dialCode: "+298" },
429
+ { name: "Fiji", iso2: "FJ", dialCode: "+679" },
430
+ { name: "Finland", iso2: "FI", dialCode: "+358" },
431
+ { name: "France", iso2: "FR", dialCode: "+33" },
432
+ { name: "French Guiana", iso2: "GF", dialCode: "+594" },
433
+ { name: "French Polynesia", iso2: "PF", dialCode: "+689" },
434
+ { name: "Gabon", iso2: "GA", dialCode: "+241" },
435
+ { name: "Gambia", iso2: "GM", dialCode: "+220" },
436
+ { name: "Georgia", iso2: "GE", dialCode: "+995" },
437
+ { name: "Germany", iso2: "DE", dialCode: "+49" },
438
+ { name: "Ghana", iso2: "GH", dialCode: "+233" },
439
+ { name: "Gibraltar", iso2: "GI", dialCode: "+350" },
440
+ { name: "Greece", iso2: "GR", dialCode: "+30" },
441
+ { name: "Greenland", iso2: "GL", dialCode: "+299" },
442
+ { name: "Grenada", iso2: "GD", dialCode: "+1473" },
443
+ { name: "Guadeloupe", iso2: "GP", dialCode: "+590" },
444
+ { name: "Guam", iso2: "GU", dialCode: "+1671" },
445
+ { name: "Guatemala", iso2: "GT", dialCode: "+502" },
446
+ { name: "Guernsey", iso2: "GG", dialCode: "+44" },
447
+ { name: "Guinea", iso2: "GN", dialCode: "+224" },
448
+ { name: "Guinea-Bissau", iso2: "GW", dialCode: "+245" },
449
+ { name: "Guyana", iso2: "GY", dialCode: "+592" },
450
+ { name: "Haiti", iso2: "HT", dialCode: "+509" },
451
+ { name: "Honduras", iso2: "HN", dialCode: "+504" },
452
+ { name: "Hong Kong", iso2: "HK", dialCode: "+852" },
453
+ { name: "Hungary", iso2: "HU", dialCode: "+36" },
454
+ { name: "Iceland", iso2: "IS", dialCode: "+354" },
455
+ { name: "India", iso2: "IN", dialCode: "+91" },
456
+ { name: "Indonesia", iso2: "ID", dialCode: "+62" },
457
+ { name: "Iran", iso2: "IR", dialCode: "+98" },
458
+ { name: "Iraq", iso2: "IQ", dialCode: "+964" },
459
+ { name: "Ireland", iso2: "IE", dialCode: "+353" },
460
+ { name: "Isle of Man", iso2: "IM", dialCode: "+44" },
461
+ { name: "Israel", iso2: "IL", dialCode: "+972" },
462
+ { name: "Italy", iso2: "IT", dialCode: "+39" },
463
+ { name: "Jamaica", iso2: "JM", dialCode: "+1876" },
464
+ { name: "Japan", iso2: "JP", dialCode: "+81" },
465
+ { name: "Jersey", iso2: "JE", dialCode: "+44" },
466
+ { name: "Jordan", iso2: "JO", dialCode: "+962" },
467
+ { name: "Kazakhstan", iso2: "KZ", dialCode: "+7" },
468
+ { name: "Kenya", iso2: "KE", dialCode: "+254" },
469
+ { name: "Kiribati", iso2: "KI", dialCode: "+686" },
470
+ { name: "Kosovo", iso2: "XK", dialCode: "+383" },
471
+ { name: "Kuwait", iso2: "KW", dialCode: "+965" },
472
+ { name: "Kyrgyzstan", iso2: "KG", dialCode: "+996" },
473
+ { name: "Laos", iso2: "LA", dialCode: "+856" },
474
+ { name: "Latvia", iso2: "LV", dialCode: "+371" },
475
+ { name: "Lebanon", iso2: "LB", dialCode: "+961" },
476
+ { name: "Lesotho", iso2: "LS", dialCode: "+266" },
477
+ { name: "Liberia", iso2: "LR", dialCode: "+231" },
478
+ { name: "Libya", iso2: "LY", dialCode: "+218" },
479
+ { name: "Liechtenstein", iso2: "LI", dialCode: "+423" },
480
+ { name: "Lithuania", iso2: "LT", dialCode: "+370" },
481
+ { name: "Luxembourg", iso2: "LU", dialCode: "+352" },
482
+ { name: "Macau", iso2: "MO", dialCode: "+853" },
483
+ { name: "Madagascar", iso2: "MG", dialCode: "+261" },
484
+ { name: "Malawi", iso2: "MW", dialCode: "+265" },
485
+ { name: "Malaysia", iso2: "MY", dialCode: "+60" },
486
+ { name: "Maldives", iso2: "MV", dialCode: "+960" },
487
+ { name: "Mali", iso2: "ML", dialCode: "+223" },
488
+ { name: "Malta", iso2: "MT", dialCode: "+356" },
489
+ { name: "Marshall Islands", iso2: "MH", dialCode: "+692" },
490
+ { name: "Martinique", iso2: "MQ", dialCode: "+596" },
491
+ { name: "Mauritania", iso2: "MR", dialCode: "+222" },
492
+ { name: "Mauritius", iso2: "MU", dialCode: "+230" },
493
+ { name: "Mayotte", iso2: "YT", dialCode: "+262" },
494
+ { name: "Mexico", iso2: "MX", dialCode: "+52" },
495
+ { name: "Micronesia", iso2: "FM", dialCode: "+691" },
496
+ { name: "Moldova", iso2: "MD", dialCode: "+373" },
497
+ { name: "Monaco", iso2: "MC", dialCode: "+377" },
498
+ { name: "Mongolia", iso2: "MN", dialCode: "+976" },
499
+ { name: "Montenegro", iso2: "ME", dialCode: "+382" },
500
+ { name: "Montserrat", iso2: "MS", dialCode: "+1664" },
501
+ { name: "Morocco", iso2: "MA", dialCode: "+212" },
502
+ { name: "Mozambique", iso2: "MZ", dialCode: "+258" },
503
+ { name: "Myanmar", iso2: "MM", dialCode: "+95" },
504
+ { name: "Namibia", iso2: "NA", dialCode: "+264" },
505
+ { name: "Nauru", iso2: "NR", dialCode: "+674" },
506
+ { name: "Nepal", iso2: "NP", dialCode: "+977" },
507
+ { name: "Netherlands", iso2: "NL", dialCode: "+31" },
508
+ { name: "New Caledonia", iso2: "NC", dialCode: "+687" },
509
+ { name: "New Zealand", iso2: "NZ", dialCode: "+64" },
510
+ { name: "Nicaragua", iso2: "NI", dialCode: "+505" },
511
+ { name: "Niger", iso2: "NE", dialCode: "+227" },
512
+ { name: "Nigeria", iso2: "NG", dialCode: "+234" },
513
+ { name: "Niue", iso2: "NU", dialCode: "+683" },
514
+ { name: "Norfolk Island", iso2: "NF", dialCode: "+672" },
515
+ { name: "North Korea", iso2: "KP", dialCode: "+850" },
516
+ { name: "North Macedonia", iso2: "MK", dialCode: "+389" },
517
+ { name: "Northern Mariana Islands", iso2: "MP", dialCode: "+1670" },
518
+ { name: "Norway", iso2: "NO", dialCode: "+47" },
519
+ { name: "Oman", iso2: "OM", dialCode: "+968" },
520
+ { name: "Pakistan", iso2: "PK", dialCode: "+92" },
521
+ { name: "Palau", iso2: "PW", dialCode: "+680" },
522
+ { name: "Palestine", iso2: "PS", dialCode: "+970" },
523
+ { name: "Panama", iso2: "PA", dialCode: "+507" },
524
+ { name: "Papua New Guinea", iso2: "PG", dialCode: "+675" },
525
+ { name: "Paraguay", iso2: "PY", dialCode: "+595" },
526
+ { name: "Peru", iso2: "PE", dialCode: "+51" },
527
+ { name: "Philippines", iso2: "PH", dialCode: "+63" },
528
+ { name: "Poland", iso2: "PL", dialCode: "+48" },
529
+ { name: "Portugal", iso2: "PT", dialCode: "+351" },
530
+ { name: "Puerto Rico", iso2: "PR", dialCode: "+1" },
531
+ { name: "Qatar", iso2: "QA", dialCode: "+974" },
532
+ { name: "R\xE9union", iso2: "RE", dialCode: "+262" },
533
+ { name: "Romania", iso2: "RO", dialCode: "+40" },
534
+ { name: "Russia", iso2: "RU", dialCode: "+7" },
535
+ { name: "Rwanda", iso2: "RW", dialCode: "+250" },
536
+ { name: "Saint Barth\xE9lemy", iso2: "BL", dialCode: "+590" },
537
+ { name: "Saint Helena", iso2: "SH", dialCode: "+290" },
538
+ { name: "Saint Kitts and Nevis", iso2: "KN", dialCode: "+1869" },
539
+ { name: "Saint Lucia", iso2: "LC", dialCode: "+1758" },
540
+ { name: "Saint Martin", iso2: "MF", dialCode: "+590" },
541
+ { name: "Saint Pierre and Miquelon", iso2: "PM", dialCode: "+508" },
542
+ { name: "Saint Vincent and the Grenadines", iso2: "VC", dialCode: "+1784" },
543
+ { name: "Samoa", iso2: "WS", dialCode: "+685" },
544
+ { name: "San Marino", iso2: "SM", dialCode: "+378" },
545
+ { name: "S\xE3o Tom\xE9 and Pr\xEDncipe", iso2: "ST", dialCode: "+239" },
546
+ { name: "Saudi Arabia", iso2: "SA", dialCode: "+966" },
547
+ { name: "Senegal", iso2: "SN", dialCode: "+221" },
548
+ { name: "Serbia", iso2: "RS", dialCode: "+381" },
549
+ { name: "Seychelles", iso2: "SC", dialCode: "+248" },
550
+ { name: "Sierra Leone", iso2: "SL", dialCode: "+232" },
551
+ { name: "Singapore", iso2: "SG", dialCode: "+65" },
552
+ { name: "Sint Maarten", iso2: "SX", dialCode: "+1721" },
553
+ { name: "Slovakia", iso2: "SK", dialCode: "+421" },
554
+ { name: "Slovenia", iso2: "SI", dialCode: "+386" },
555
+ { name: "Solomon Islands", iso2: "SB", dialCode: "+677" },
556
+ { name: "Somalia", iso2: "SO", dialCode: "+252" },
557
+ { name: "South Africa", iso2: "ZA", dialCode: "+27" },
558
+ { name: "South Korea", iso2: "KR", dialCode: "+82" },
559
+ { name: "South Sudan", iso2: "SS", dialCode: "+211" },
560
+ { name: "Spain", iso2: "ES", dialCode: "+34" },
561
+ { name: "Sri Lanka", iso2: "LK", dialCode: "+94" },
562
+ { name: "Sudan", iso2: "SD", dialCode: "+249" },
563
+ { name: "Suriname", iso2: "SR", dialCode: "+597" },
564
+ { name: "Svalbard and Jan Mayen", iso2: "SJ", dialCode: "+47" },
565
+ { name: "Sweden", iso2: "SE", dialCode: "+46" },
566
+ { name: "Switzerland", iso2: "CH", dialCode: "+41" },
567
+ { name: "Syria", iso2: "SY", dialCode: "+963" },
568
+ { name: "Taiwan", iso2: "TW", dialCode: "+886" },
569
+ { name: "Tajikistan", iso2: "TJ", dialCode: "+992" },
570
+ { name: "Tanzania", iso2: "TZ", dialCode: "+255" },
571
+ { name: "Thailand", iso2: "TH", dialCode: "+66" },
572
+ { name: "Timor-Leste", iso2: "TL", dialCode: "+670" },
573
+ { name: "Togo", iso2: "TG", dialCode: "+228" },
574
+ { name: "Tokelau", iso2: "TK", dialCode: "+690" },
575
+ { name: "Tonga", iso2: "TO", dialCode: "+676" },
576
+ { name: "Trinidad and Tobago", iso2: "TT", dialCode: "+1868" },
577
+ { name: "Tunisia", iso2: "TN", dialCode: "+216" },
578
+ { name: "Turkey", iso2: "TR", dialCode: "+90" },
579
+ { name: "Turkmenistan", iso2: "TM", dialCode: "+993" },
580
+ { name: "Turks and Caicos Islands", iso2: "TC", dialCode: "+1649" },
581
+ { name: "Tuvalu", iso2: "TV", dialCode: "+688" },
582
+ { name: "Uganda", iso2: "UG", dialCode: "+256" },
583
+ { name: "Ukraine", iso2: "UA", dialCode: "+380" },
584
+ { name: "United Arab Emirates", iso2: "AE", dialCode: "+971" },
585
+ { name: "United Kingdom", iso2: "GB", dialCode: "+44" },
586
+ { name: "United States", iso2: "US", dialCode: "+1" },
587
+ { name: "U.S. Virgin Islands", iso2: "VI", dialCode: "+1340" },
588
+ { name: "Uruguay", iso2: "UY", dialCode: "+598" },
589
+ { name: "Uzbekistan", iso2: "UZ", dialCode: "+998" },
590
+ { name: "Vanuatu", iso2: "VU", dialCode: "+678" },
591
+ { name: "Vatican City", iso2: "VA", dialCode: "+39" },
592
+ { name: "Venezuela", iso2: "VE", dialCode: "+58" },
593
+ { name: "Vietnam", iso2: "VN", dialCode: "+84" },
594
+ { name: "Wallis and Futuna", iso2: "WF", dialCode: "+681" },
595
+ { name: "Western Sahara", iso2: "EH", dialCode: "+212" },
596
+ { name: "Yemen", iso2: "YE", dialCode: "+967" },
597
+ { name: "Zambia", iso2: "ZM", dialCode: "+260" },
598
+ { name: "Zimbabwe", iso2: "ZW", dialCode: "+263" }
599
+ ];
600
+ var PRIMARY_COUNTRY_BY_DIAL_CODE = {
601
+ "+1": "US",
602
+ "+7": "RU",
603
+ "+39": "IT",
604
+ "+44": "GB",
605
+ "+47": "NO",
606
+ "+61": "AU",
607
+ "+212": "MA",
608
+ "+262": "RE",
609
+ "+358": "FI",
610
+ "+590": "GP",
611
+ "+599": "CW"
612
+ };
613
+ var findCountryByDialCode = (dialCode) => {
614
+ const primaryIso2 = PRIMARY_COUNTRY_BY_DIAL_CODE[dialCode];
615
+ return primaryIso2 && COUNTRY_CODES.find((c) => c.iso2 === primaryIso2) || COUNTRY_CODES.find((c) => c.dialCode === dialCode);
616
+ };
617
+ var findCountryByIso2 = (iso2) => {
618
+ if (!iso2) return void 0;
619
+ const normalized = iso2.trim().toUpperCase();
620
+ return COUNTRY_CODES.find((c) => c.iso2 === normalized);
621
+ };
622
+ var getDialCodeByCountryCode = (iso2) => findCountryByIso2(iso2)?.dialCode;
623
+ var resolveCountry = (codeOrDialCode) => {
624
+ const value = codeOrDialCode?.trim();
625
+ if (!value) return void 0;
626
+ return value.startsWith("+") ? findCountryByDialCode(value) : findCountryByIso2(value);
627
+ };
628
+ var getCountryFlag = (iso2) => iso2.toUpperCase().replace(/./g, (char) => String.fromCodePoint(127397 + char.charCodeAt(0)));
629
+ var splitPhoneNumber = (value) => {
630
+ const trimmed = (value ?? "").trim();
631
+ if (!trimmed.startsWith("+")) {
632
+ return { number: trimmed };
633
+ }
634
+ const [head, ...rest] = trimmed.split(/\s+/);
635
+ const digits = trimmed.replace(/[^\d+]/g, "");
636
+ const prefixMatch = [...COUNTRY_CODES].sort((a, b) => b.dialCode.length - a.dialCode.length).find((c) => digits.startsWith(c.dialCode));
637
+ const country = (rest.length > 0 ? findCountryByDialCode(head) : void 0) ?? (prefixMatch ? findCountryByDialCode(prefixMatch.dialCode) : void 0);
638
+ if (!country) {
639
+ return { number: trimmed };
640
+ }
641
+ const number = rest.length > 0 && head === country.dialCode ? rest.join(" ") : digits.slice(country.dialCode.length);
642
+ return { country, number };
643
+ };
644
+
354
645
  // src/components/controls/edit/PhoneInput.tsx
355
- import React6 from "react";
646
+ import React6, { useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
356
647
  import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
648
+ var DEFAULT_DIAL_CODE = "+91";
357
649
  var PhoneInput = (props) => {
358
- const textChangeHandler = (event) => {
359
- const text = event.target.value;
650
+ const hasFixedPrefix = props.prefix !== void 0 && props.prefix !== null;
651
+ let value = "";
652
+ if (props.value !== void 0 && props.value !== null) {
653
+ value = props.value;
654
+ }
655
+ const parsed = useMemo(
656
+ () => hasFixedPrefix ? { number: value } : splitPhoneNumber(String(value)),
657
+ [hasFixedPrefix, value]
658
+ );
659
+ const defaultCountry = resolveCountry(props?.attributes?.defaultCountryCode) ?? findCountryByDialCode(DEFAULT_DIAL_CODE);
660
+ const hasUserPickedCountry = useRef(false);
661
+ const [selectedIso2, setSelectedIso2] = useState2(
662
+ parsed.country?.iso2 ?? defaultCountry.iso2
663
+ );
664
+ const selectedCountry = COUNTRY_CODES.find((c) => c.iso2 === selectedIso2) ?? defaultCountry;
665
+ useEffect2(() => {
666
+ if (parsed.country && parsed.country.dialCode !== selectedCountry.dialCode) {
667
+ setSelectedIso2(parsed.country.iso2);
668
+ }
669
+ }, [parsed.country, selectedCountry.dialCode]);
670
+ useEffect2(() => {
671
+ if (!parsed.country && !parsed.number && !hasUserPickedCountry.current) {
672
+ setSelectedIso2(defaultCountry.iso2);
673
+ }
674
+ }, [defaultCountry.iso2, parsed.country, parsed.number]);
675
+ const emit = (text) => {
360
676
  if (props.callback !== void 0) {
361
677
  props.callback(
362
678
  {
@@ -368,31 +684,69 @@ var PhoneInput = (props) => {
368
684
  );
369
685
  }
370
686
  };
371
- let value = "";
372
- if (props.value !== void 0 && props.value !== null) {
373
- value = props.value;
374
- }
687
+ const combine = (dialCode, number) => number ? `${dialCode} ${number}` : "";
688
+ const textChangeHandler = (event) => {
689
+ const text = event.target.value;
690
+ if (hasFixedPrefix) {
691
+ emit(text);
692
+ return;
693
+ }
694
+ emit(combine(selectedCountry.dialCode, text.replace(/\D/g, "")));
695
+ };
696
+ const countryChangeHandler = (event) => {
697
+ const country = COUNTRY_CODES.find((c) => c.iso2 === event.target.value);
698
+ if (!country) return;
699
+ hasUserPickedCountry.current = true;
700
+ setSelectedIso2(country.iso2);
701
+ if (parsed.number) {
702
+ emit(combine(country.dialCode, parsed.number));
703
+ }
704
+ };
705
+ const isReadOnly = props?.attributes?.readOnly;
375
706
  return /* @__PURE__ */ jsx6(React6.Fragment, { children: /* @__PURE__ */ jsxs6("label", { className: "block mb-1", children: [
376
707
  /* @__PURE__ */ jsx6("span", { className: "text-sm font-medium ", children: props?.attributes?.label }),
377
708
  " ",
378
709
  props?.attributes?.label && props?.attributes?.required && /* @__PURE__ */ jsx6("span", { className: "bg-error-weak", children: "*" }),
379
710
  /* @__PURE__ */ jsxs6("div", { className: "flex items-center rounded border ", children: [
380
- /* @__PURE__ */ jsx6("span", { className: "px-3", children: props.prefix }),
711
+ hasFixedPrefix ? /* @__PURE__ */ jsx6("span", { className: "px-3", children: props.prefix }) : /* @__PURE__ */ jsxs6("span", { className: "relative flex items-center gap-1 self-stretch px-3 border-r whitespace-nowrap", children: [
712
+ /* @__PURE__ */ jsx6("span", { "aria-hidden": "true", children: getCountryFlag(selectedCountry.iso2) }),
713
+ /* @__PURE__ */ jsx6("span", { children: selectedCountry.dialCode }),
714
+ /* @__PURE__ */ jsx6("svg", { "aria-hidden": "true", className: "w-3 h-3 opacity-60", viewBox: "0 0 20 20", fill: "currentColor", children: /* @__PURE__ */ jsx6("path", { fillRule: "evenodd", d: "M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z", clipRule: "evenodd" }) }),
715
+ /* @__PURE__ */ jsx6(
716
+ "select",
717
+ {
718
+ "aria-label": "Country code",
719
+ value: selectedCountry.iso2,
720
+ onChange: countryChangeHandler,
721
+ disabled: isReadOnly,
722
+ className: "absolute inset-0 w-full h-full opacity-0 cursor-pointer disabled:cursor-not-allowed",
723
+ children: COUNTRY_CODES.map((country) => /* @__PURE__ */ jsxs6("option", { value: country.iso2, children: [
724
+ getCountryFlag(country.iso2),
725
+ " ",
726
+ country.name,
727
+ " (",
728
+ country.dialCode,
729
+ ")"
730
+ ] }, country.iso2))
731
+ }
732
+ )
733
+ ] }),
381
734
  /* @__PURE__ */ jsx6(
382
735
  "input",
383
736
  {
384
- type: "text",
737
+ type: hasFixedPrefix ? "text" : "tel",
738
+ inputMode: hasFixedPrefix ? void 0 : "numeric",
385
739
  name: props.name,
386
740
  id: props.name,
387
- value,
741
+ value: parsed.number,
388
742
  onChange: textChangeHandler,
389
743
  required: props?.attributes?.required,
390
744
  placeholder: props?.attributes?.placeholder,
391
745
  maxLength: props?.attributes?.maxLength,
392
746
  pattern: props?.attributes?.pattern,
393
- disabled: props?.attributes?.readOnly,
747
+ disabled: isReadOnly,
394
748
  minLength: props?.attributes?.minLength,
395
- className: "py-1.5 block w-full outline-none border-0 mr-0.5"
749
+ className: `py-1.5 block w-full outline-none border-0 mr-0.5 ${hasFixedPrefix ? "" : "pl-3"}`
396
750
  }
397
751
  )
398
752
  ] }),
@@ -641,7 +995,7 @@ var DateTimeInput = (props) => {
641
995
  var DateTimeInput_default = DateTimeInput;
642
996
 
643
997
  // src/components/controls/edit/ColorInput.tsx
644
- import React11, { useEffect as useEffect2 } from "react";
998
+ import React11, { useEffect as useEffect3 } from "react";
645
999
  import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
646
1000
  var DEFAULT_COLOR = "#3b82f6";
647
1001
  var isValidHex = (val) => typeof val === "string" && /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(val.trim());
@@ -656,7 +1010,7 @@ var ColorInput = (props) => {
656
1010
  const [color, setColor] = React11.useState(
657
1011
  () => normalizeColor(props.value)
658
1012
  );
659
- useEffect2(() => {
1013
+ useEffect3(() => {
660
1014
  const hasValue = props.value !== void 0 && props.value !== null && props.value !== "";
661
1015
  if (!hasValue && props.callback && !isReadOnly) {
662
1016
  props.callback({
@@ -667,7 +1021,7 @@ var ColorInput = (props) => {
667
1021
  });
668
1022
  }
669
1023
  }, [isReadOnly]);
670
- useEffect2(() => {
1024
+ useEffect3(() => {
671
1025
  if (props.value !== void 0 && props.value !== null && props.value !== "") {
672
1026
  if (typeof props.value === "string") {
673
1027
  setColor(normalizeColor(props.value));
@@ -735,16 +1089,16 @@ var ColorInput = (props) => {
735
1089
  var ColorInput_default = ColorInput;
736
1090
 
737
1091
  // src/components/controls/edit/SelectWithSearchInput.tsx
738
- import React12, { useEffect as useEffect3, useRef, useState as useState2 } from "react";
1092
+ import React12, { useEffect as useEffect4, useRef as useRef2, useState as useState3 } from "react";
739
1093
  import { jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
740
1094
  var SelectWithSearchInput = (props) => {
741
- const [isOpen, setIsOpen] = useState2(false);
742
- const [searchTerm, setSearchTerm] = useState2("");
743
- const [highlightedIndex, setHighlightedIndex] = useState2(-1);
744
- const [selectedItem, setSelectedItem] = useState2(
1095
+ const [isOpen, setIsOpen] = useState3(false);
1096
+ const [searchTerm, setSearchTerm] = useState3("");
1097
+ const [highlightedIndex, setHighlightedIndex] = useState3(-1);
1098
+ const [selectedItem, setSelectedItem] = useState3(
745
1099
  null
746
1100
  );
747
- const [list, setList] = useState2([]);
1101
+ const [list, setList] = useState3([]);
748
1102
  const loadData = React12.useCallback(async () => {
749
1103
  if (props.dataset) {
750
1104
  setList(props.dataset);
@@ -770,10 +1124,10 @@ var SelectWithSearchInput = (props) => {
770
1124
  props.dataSourceDependsOn,
771
1125
  props.dependentValue
772
1126
  ]);
773
- useEffect3(() => {
1127
+ useEffect4(() => {
774
1128
  loadData();
775
1129
  }, [loadData]);
776
- useEffect3(() => {
1130
+ useEffect4(() => {
777
1131
  if (props.value && list.length && props.dataKeyFieldName && props.dataTextFieldName) {
778
1132
  const selected = list.find(
779
1133
  (x) => String(x[props.dataKeyFieldName]) === String(props.value)
@@ -820,8 +1174,8 @@ var SelectWithSearchInput = (props) => {
820
1174
  handleSelect(e, filteredItems[highlightedIndex]);
821
1175
  }
822
1176
  };
823
- const dropdownRef = useRef(null);
824
- useEffect3(() => {
1177
+ const dropdownRef = useRef2(null);
1178
+ useEffect4(() => {
825
1179
  if (highlightedIndex >= 0 && dropdownRef.current) {
826
1180
  const highlightedItem = dropdownRef.current.children[highlightedIndex];
827
1181
  highlightedItem?.scrollIntoView({
@@ -1026,7 +1380,7 @@ var TimeInput = (props) => {
1026
1380
  var TimeInput_default = TimeInput;
1027
1381
 
1028
1382
  // src/components/controls/edit/DateInput.tsx
1029
- import { useMemo } from "react";
1383
+ import { useMemo as useMemo2 } from "react";
1030
1384
 
1031
1385
  // src/components/utilities/DateTimeUtility.tsx
1032
1386
  var DateTimeUtility = class {
@@ -1107,7 +1461,7 @@ var DateTimeUtility_default = DateTimeUtility;
1107
1461
  // src/components/controls/edit/DateInput.tsx
1108
1462
  import { jsx as jsx15, jsxs as jsxs15 } from "react/jsx-runtime";
1109
1463
  var DateInput = (props) => {
1110
- const value = useMemo(() => {
1464
+ const value = useMemo2(() => {
1111
1465
  if (props.value === void 0 || props.value === null || props.value === "") {
1112
1466
  return "";
1113
1467
  }
@@ -1163,11 +1517,11 @@ var DateInput = (props) => {
1163
1517
  var DateInput_default = DateInput;
1164
1518
 
1165
1519
  // src/components/controls/edit/RadioInput.tsx
1166
- import { useEffect as useEffect4, useState as useState3 } from "react";
1520
+ import { useEffect as useEffect5, useState as useState4 } from "react";
1167
1521
  import { jsx as jsx16, jsxs as jsxs16 } from "react/jsx-runtime";
1168
1522
  var RadioInput = (props) => {
1169
- const [list, setList] = useState3([]);
1170
- useEffect4(() => {
1523
+ const [list, setList] = useState4([]);
1524
+ useEffect5(() => {
1171
1525
  async function loadData() {
1172
1526
  if (props.dataset) {
1173
1527
  setList(props.dataset);
@@ -1257,6 +1611,13 @@ export {
1257
1611
  MoneyInput_default,
1258
1612
  Select_default,
1259
1613
  PercentageInput_default,
1614
+ COUNTRY_CODES,
1615
+ findCountryByDialCode,
1616
+ findCountryByIso2,
1617
+ getDialCodeByCountryCode,
1618
+ resolveCountry,
1619
+ getCountryFlag,
1620
+ splitPhoneNumber,
1260
1621
  PhoneInput_default,
1261
1622
  NumberInput_default,
1262
1623
  CheckboxInput_default,
package/dist/index.d.mts CHANGED
@@ -174,6 +174,7 @@ interface InputControlProps {
174
174
  helpText?: string;
175
175
  autoFocus?: boolean;
176
176
  heading?: string;
177
+ defaultCountryCode?: string;
177
178
  };
178
179
  }
179
180
 
@@ -260,6 +261,35 @@ declare const PercentageInput: React__default.FC<InputControlProps>;
260
261
 
261
262
  declare const PhoneInput: React__default.FC<InputControlProps>;
262
263
 
264
+ interface CountryCode {
265
+ name: string;
266
+ iso2: string;
267
+ dialCode: string;
268
+ }
269
+ declare const COUNTRY_CODES: CountryCode[];
270
+ /** Returns the country for a dial code, preferring the primary country for shared codes. */
271
+ declare const findCountryByDialCode: (dialCode: string) => CountryCode | undefined;
272
+ /** Returns the country for an ISO 3166-1 alpha-2 code such as "IN" (as returned by the Geo API). */
273
+ declare const findCountryByIso2: (iso2?: string | null) => CountryCode | undefined;
274
+ /** Maps an ISO alpha-2 country code to its dial code: "IN" → "+91". */
275
+ declare const getDialCodeByCountryCode: (iso2?: string | null) => string | undefined;
276
+ /**
277
+ * Resolves either a dial code ("+91") or an ISO alpha-2 country code ("IN") to a country,
278
+ * so callers can pass the Geo API's countryCode straight through.
279
+ */
280
+ declare const resolveCountry: (codeOrDialCode?: string | null) => CountryCode | undefined;
281
+ /** Converts an ISO 3166-1 alpha-2 code into its flag emoji. */
282
+ declare const getCountryFlag: (iso2: string) => string;
283
+ /**
284
+ * Splits a stored phone value like "+91 9534822376" into its country and number.
285
+ * Picks the longest matching dial code, so "+1684..." resolves to American Samoa, not "+1".
286
+ * Values without a leading "+" are treated as a bare number.
287
+ */
288
+ declare const splitPhoneNumber: (value: string) => {
289
+ country?: CountryCode;
290
+ number: string;
291
+ };
292
+
263
293
  declare const NumberInput: React__default.FC<InputControlProps>;
264
294
 
265
295
  declare const CheckboxInput: React__default.FC<InputControlProps>;
@@ -479,4 +509,4 @@ interface DataFormRendererProps {
479
509
  }
480
510
  declare const DataFormRenderer: ({ formDefinition, dataItem, params, tabs, apiBaseUrl, session, widgetProps, onSave, onDelete, onCancelAdd, isAddPage, entityId, }: DataFormRendererProps) => React.JSX.Element | null;
481
511
 
482
- export { type ActionResponse$1 as ActionResponse, Button, CheckboxInput, ColorInput, DataFormRenderer, DataList, DataListRenderer, DateInput, DateTimeInput, EmailInput, EnterAnimationHydrator, InputControl, type InputControlProps, InputControlType, LineTextInput, MoneyInput, MultilineTextInput, NavigationTabsV2, NumberInput, OtpInput, PageBodyRenderer, PercentageInput, PhoneInput, RadioInput, Select, StyleTypes, TimeInput, Toast, ToastService, ViewControl, type ViewControlProps, ViewControlTypes };
512
+ export { type ActionResponse$1 as ActionResponse, Button, COUNTRY_CODES, CheckboxInput, ColorInput, type CountryCode, DataFormRenderer, DataList, DataListRenderer, DateInput, DateTimeInput, EmailInput, EnterAnimationHydrator, InputControl, type InputControlProps, InputControlType, LineTextInput, MoneyInput, MultilineTextInput, NavigationTabsV2, NumberInput, OtpInput, PageBodyRenderer, PercentageInput, PhoneInput, RadioInput, Select, StyleTypes, TimeInput, Toast, ToastService, ViewControl, type ViewControlProps, ViewControlTypes, findCountryByDialCode, findCountryByIso2, getCountryFlag, getDialCodeByCountryCode, resolveCountry, splitPhoneNumber };
package/dist/index.d.ts CHANGED
@@ -174,6 +174,7 @@ interface InputControlProps {
174
174
  helpText?: string;
175
175
  autoFocus?: boolean;
176
176
  heading?: string;
177
+ defaultCountryCode?: string;
177
178
  };
178
179
  }
179
180
 
@@ -260,6 +261,35 @@ declare const PercentageInput: React__default.FC<InputControlProps>;
260
261
 
261
262
  declare const PhoneInput: React__default.FC<InputControlProps>;
262
263
 
264
+ interface CountryCode {
265
+ name: string;
266
+ iso2: string;
267
+ dialCode: string;
268
+ }
269
+ declare const COUNTRY_CODES: CountryCode[];
270
+ /** Returns the country for a dial code, preferring the primary country for shared codes. */
271
+ declare const findCountryByDialCode: (dialCode: string) => CountryCode | undefined;
272
+ /** Returns the country for an ISO 3166-1 alpha-2 code such as "IN" (as returned by the Geo API). */
273
+ declare const findCountryByIso2: (iso2?: string | null) => CountryCode | undefined;
274
+ /** Maps an ISO alpha-2 country code to its dial code: "IN" → "+91". */
275
+ declare const getDialCodeByCountryCode: (iso2?: string | null) => string | undefined;
276
+ /**
277
+ * Resolves either a dial code ("+91") or an ISO alpha-2 country code ("IN") to a country,
278
+ * so callers can pass the Geo API's countryCode straight through.
279
+ */
280
+ declare const resolveCountry: (codeOrDialCode?: string | null) => CountryCode | undefined;
281
+ /** Converts an ISO 3166-1 alpha-2 code into its flag emoji. */
282
+ declare const getCountryFlag: (iso2: string) => string;
283
+ /**
284
+ * Splits a stored phone value like "+91 9534822376" into its country and number.
285
+ * Picks the longest matching dial code, so "+1684..." resolves to American Samoa, not "+1".
286
+ * Values without a leading "+" are treated as a bare number.
287
+ */
288
+ declare const splitPhoneNumber: (value: string) => {
289
+ country?: CountryCode;
290
+ number: string;
291
+ };
292
+
263
293
  declare const NumberInput: React__default.FC<InputControlProps>;
264
294
 
265
295
  declare const CheckboxInput: React__default.FC<InputControlProps>;
@@ -479,4 +509,4 @@ interface DataFormRendererProps {
479
509
  }
480
510
  declare const DataFormRenderer: ({ formDefinition, dataItem, params, tabs, apiBaseUrl, session, widgetProps, onSave, onDelete, onCancelAdd, isAddPage, entityId, }: DataFormRendererProps) => React.JSX.Element | null;
481
511
 
482
- export { type ActionResponse$1 as ActionResponse, Button, CheckboxInput, ColorInput, DataFormRenderer, DataList, DataListRenderer, DateInput, DateTimeInput, EmailInput, EnterAnimationHydrator, InputControl, type InputControlProps, InputControlType, LineTextInput, MoneyInput, MultilineTextInput, NavigationTabsV2, NumberInput, OtpInput, PageBodyRenderer, PercentageInput, PhoneInput, RadioInput, Select, StyleTypes, TimeInput, Toast, ToastService, ViewControl, type ViewControlProps, ViewControlTypes };
512
+ export { type ActionResponse$1 as ActionResponse, Button, COUNTRY_CODES, CheckboxInput, ColorInput, type CountryCode, DataFormRenderer, DataList, DataListRenderer, DateInput, DateTimeInput, EmailInput, EnterAnimationHydrator, InputControl, type InputControlProps, InputControlType, LineTextInput, MoneyInput, MultilineTextInput, NavigationTabsV2, NumberInput, OtpInput, PageBodyRenderer, PercentageInput, PhoneInput, RadioInput, Select, StyleTypes, TimeInput, Toast, ToastService, ViewControl, type ViewControlProps, ViewControlTypes, findCountryByDialCode, findCountryByIso2, getCountryFlag, getDialCodeByCountryCode, resolveCountry, splitPhoneNumber };