@input-kit/phone 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -10
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var react=require('react'),libphonenumberJs=require('libphonenumber-js'),be=require('libphonenumber-js/mobile/examples'),xe=require('world-countries'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var be__default=/*#__PURE__*/_interopDefault(be);var xe__default=/*#__PURE__*/_interopDefault(xe);var Ie=["US","GB","CA","AU","DE","FR","IT","ES","JP","CN","IN","BR","MX","KR","NL","CH","SE","AE","SG","ZA","NG","SA","TR","ID","PH","TH","VN","MY","NZ","AR"],De=new Set(libphonenumberJs.getCountries());function Ne(e,t){let o=e.startsWith("+")?e:`+${e}`,n=t.replace(/\D/g,"");return `${o}${n}`}function we(e){let t=e.idd?.root;if(!t)return [];let n=(e.idd?.suffixes?.length?e.idd.suffixes:[""]).map(u=>Ne(t,u)).filter(u=>/^\+\d+$/.test(u));return Array.from(new Set(n))}function Re(e){let t=libphonenumberJs.getExampleNumber(e,be__default.default);return t?t.formatNational().replace(/\d/g,"#"):void 0}function ce(e){let t=Ie.indexOf(e);return t===-1?Number.MAX_SAFE_INTEGER:t}var Be=xe__default.default.filter(e=>De.has(e.cca2)).map(e=>{let t=e.cca2,o=we(e),n=`+${libphonenumberJs.getCountryCallingCode(t)}`;return !e.flag||o.length===0?null:{code:t,name:e.name.common,dialCode:n,dialCodes:o,flag:e.flag,format:Re(t)}}).filter(e=>e!==null).sort((e,t)=>{let o=ce(e.code)-ce(t.code);return o!==0?o:e.name.localeCompare(t.name)}),B=Be,ke=new Map(B.map(e=>[e.code,e])),Se=B.reduce((e,t)=>{for(let o of t.dialCodes){let n=e.get(o)??[];n.push(t),e.set(o,n);}return e},new Map),Ee=B.flatMap(e=>e.dialCodes.map(t=>({dialCode:t,country:e}))).sort((e,t)=>t.dialCode.length-e.dialCode.length);function Le(e){let t=e.replace(/\D/g,"");return t?`+${t}`:""}function k(e){return ke.get(e.toUpperCase())}function pe(e){return Se.get(Le(e))??[]}function $e(e){return pe(e)[0]}function re(e){let t=e.trim();if(!t)return;let o=t.startsWith("+")?`+${t.replace(/\D/g,"")}`:t.startsWith("00")?`+${t.slice(2).replace(/\D/g,"")}`:"";if(!o)return;let n=libphonenumberJs.parsePhoneNumberFromString(o);return n?.country?k(n.country):Ee.find(u=>o.startsWith(u.dialCode))?.country}function S(e){let t=e.trim(),o=R(t);return o?t.startsWith("+")?`+${o}`:o:""}function ie(e){return e?.code}function R(e){return e.replace(/\D/g,"")}function se(e,t){return e&&new libphonenumberJs.AsYouType(ie(t)).input(S(e))}function Q(e){return S(e)}function Ae(e,t){return !e||!t?false:e.trim().startsWith("+")?libphonenumberJs.validatePhoneNumberLength(S(e))===void 0:libphonenumberJs.validatePhoneNumberLength(R(e),ie(t))===void 0}function ae(e,t,o){if(!e)return false;if(o)return o(e,t);let n=S(e),u=ie(t);return u?n.startsWith("+")?libphonenumberJs.isValidPhoneNumber(n):libphonenumberJs.isValidPhoneNumber(R(n),u):libphonenumberJs.isPossiblePhoneNumber(n.startsWith("+")?n:`+${R(n)}`)}function E(e,t){if(!t)return e;let o=S(e);if(!o)return "";if(o.startsWith("+"))return o;let n=R(o);return t.dialCodes.find(c=>n.startsWith(c.replace("+","")))?`+${n}`:`${t.dialCode}${n}`}function G(e,t){if(!t)return e;let o=S(e),n=R(o);for(let u of t.dialCodes){let c=u.replace("+","");if(n.startsWith(c))return n.slice(c.length)}return n}function ue(e,t,o){let n=t.toLowerCase().trim();return n?e.filter(u=>u.name.toLowerCase().includes(n)||u.code.toLowerCase().includes(n)||u.dialCodes.some(c=>c.includes(n))):o?.length?[...e].sort((u,c)=>{let m=o.indexOf(u.code),P=o.indexOf(c.code);return m!==-1&&P!==-1?m-P:m!==-1?-1:P!==-1?1:u.name.localeCompare(c.name)}):e}function le(e){return e?.format?e.format.replace(/#/g,"0"):e?.dialCode?`${e.dialCode} 000 000 0000`:"Phone number"}function de(e={}){let{value:t,defaultValue:o="",onChange:n,onBlur:u,onFocus:c,defaultCountry:m="US",preferredCountries:P,excludeCountries:$,onlyCountries:W,autoDetect:z=true,formatOnType:U=true,includeDialCode:d=false,validator:H}=e,I=t!==void 0,g=react.useMemo(()=>{let i=B;return W?.length&&(i=i.filter(r=>W.includes(r.code))),$?.length&&(i=i.filter(r=>!$.includes(r.code))),i},[W,$]),_=k(m)||g[0],[X,V]=react.useState(o),[a,v]=react.useState(_),[f,p]=react.useState(false),[D,N]=react.useState(""),s=I?t:X;react.useEffect(()=>{let i=k(m)||g[0];i&&i.code!==a?.code&&v(i);},[m,g,a?.code]),react.useEffect(()=>{if(z&&s){let i=re(s);i&&g.some(r=>r.code===i.code)&&i.code!==a?.code&&v(i);}},[g,z,s,a?.code]);let b=react.useMemo(()=>U?se(d&&s.startsWith("+")?G(s,a):s,a):d&&s.startsWith("+")?G(s,a):s,[U,d,s,a]),C=react.useMemo(()=>d&&a?E(s,a):s,[s,a,d]),O=react.useMemo(()=>ae(s,a,H),[s,a,H]),Z=react.useMemo(()=>ue(g,D,P),[g,D,P]),A=react.useCallback(i=>{let r=Q(i);I||V(r),n?.(d?E(r,a):r,a);},[I,n,a,d]),j=react.useCallback(i=>{let r=k(i);r&&(v(r),n?.(d?E(s,r):s,r));},[s,n,d]),J=react.useCallback(i=>{v(i),p(false),N(""),n?.(d?E(s,i):s,i);},[s,n,d]),w=react.useCallback(()=>{p(i=>!i),f&&N("");},[f]),q=react.useCallback(()=>{p(true);},[]),ee=react.useCallback(()=>{p(false),N("");},[]),M=react.useCallback(()=>{I||V(""),n?.("",a);},[I,n,a]),te=react.useCallback(i=>{let r=i.target.value,y=r.trim().startsWith("+")?`+${r.replace(/\D/g,"")}`:Q(r);A(y);},[A]),ne=react.useCallback(()=>{c?.();},[c]),oe=react.useCallback(()=>{u?.();},[u]);return {phone:s,fullPhone:C,country:a,isValid:O,isOpen:f,searchQuery:D,setPhone:A,setCountry:j,toggleDropdown:w,openDropdown:q,closeDropdown:ee,setSearchQuery:N,clear:M,inputProps:{value:b,onChange:te,onFocus:ne,onBlur:oe,type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:le(a),"aria-invalid":s?!O:void 0},countryButtonProps:{onClick:w,"aria-expanded":f,"aria-haspopup":"listbox"},filteredCountries:Z,selectCountry:J}}var He=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"18 15 12 9 6 15"})}),Ve=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})}),Qe=react.forwardRef(function(t,o){let{value:n,defaultValue:u,onChange:c,onBlur:m,onFocus:P,inputClassName:$,selectorClassName:W,containerClassName:z,placeholder:U,disabled:d,readOnly:H,name:I,id:g,"aria-label":_,"aria-labelledby":X,...V}=t,a=react.useRef(null),v=react.useRef([]),[f,p]=react.useState(0),D=react.useId(),{inputProps:N,countryButtonProps:s,country:b,filteredCountries:C,isOpen:O,isValid:Z,searchQuery:A,setSearchQuery:j,setCountry:J,selectCountry:w,clear:q,openDropdown:ee,closeDropdown:M}=de({value:n,defaultValue:u,onChange:c,onBlur:m,onFocus:P,...V}),te=react.useCallback(()=>{a.current?.focus();},[]),ne=react.useCallback(()=>{a.current?.blur();},[]),oe=react.useCallback(r=>{w(r),p(0);},[w]),i=react.useCallback((r,y,x)=>{switch(r.key){case "Enter":case " ":r.preventDefault(),w(y),p(0);break;case "ArrowDown":if(r.preventDefault(),x<C.length-1){let F=x+1;p(F),v.current[F]?.focus();}break;case "ArrowUp":if(r.preventDefault(),x>0){let F=x-1;p(F),v.current[F]?.focus();}break;case "Escape":r.preventDefault(),M();break}},[w,C.length,M]);return react.useEffect(()=>{if(C.length===0){f!==0&&p(0);return}f>=C.length&&p(C.length-1);},[C.length,f]),react.useImperativeHandle(o,()=>({focus:te,blur:ne,clear:q,setCountry:J,getCountry:()=>b,open:ee,close:M})),jsxRuntime.jsxs("div",{className:z,"data-valid":Z,children:[jsxRuntime.jsxs("button",{...s,type:"button",className:W,disabled:d,tabIndex:d?-1:0,"aria-controls":D,children:[b?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:b.flag}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:b.dialCode})]}):jsxRuntime.jsx("span",{className:"phone-input-placeholder",children:"Select"}),jsxRuntime.jsx("span",{className:"phone-input-arrow","aria-hidden":"true",children:O?jsxRuntime.jsx(He,{size:12}):jsxRuntime.jsx(Ve,{size:12})})]}),jsxRuntime.jsx("input",{...N,ref:a,id:g,name:I,className:$,placeholder:U||N.placeholder,disabled:d,readOnly:H,"aria-label":_,"aria-labelledby":X}),O&&jsxRuntime.jsxs("div",{className:"phone-input-dropdown",children:[jsxRuntime.jsx("div",{className:"phone-input-search",children:jsxRuntime.jsx("input",{type:"text",value:A,onChange:r=>j(r.target.value),placeholder:"Search countries...",autoFocus:true,"aria-controls":D,"aria-label":"Search countries"})}),jsxRuntime.jsxs("ul",{className:"phone-input-country-list",id:D,role:"listbox","aria-label":"Country options",children:[C.map((r,y)=>jsxRuntime.jsxs("li",{ref:x=>{v.current[y]=x;},role:"option","aria-selected":r.code===b?.code,className:`phone-input-country-option ${r.code===b?.code?"selected":""} ${y===f?"highlighted":""}`,onClick:()=>oe(r),onKeyDown:x=>i(x,r,y),onMouseEnter:()=>p(y),tabIndex:y===f?0:-1,children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:r.flag}),jsxRuntime.jsx("span",{className:"phone-input-country-name",children:r.name}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:r.dialCode})]},r.code)),C.length===0&&jsxRuntime.jsx("li",{className:"phone-input-no-results",children:"No countries found"})]})]})]})});exports.PhoneInput=Qe;exports.addDialCode=E;exports.cleanPhone=R;exports.countries=B;exports.detectCountryFromPhone=re;exports.filterCountries=ue;exports.formatPhone=se;exports.getCountriesByDialCode=pe;exports.getCountryByCode=k;exports.getCountryByDialCode=$e;exports.getPlaceholder=le;exports.removeDialCode=G;exports.unformatPhone=Q;exports.usePhoneInput=de;exports.validatePhone=ae;exports.validatePhoneLength=Ae;//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var react=require('react'),libphonenumberJs=require('libphonenumber-js'),ke=require('libphonenumber-js/mobile/examples'),Me=require('world-countries'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ke__default=/*#__PURE__*/_interopDefault(ke);var Me__default=/*#__PURE__*/_interopDefault(Me);var Te=["US","GB","CA","AU","DE","FR","IT","ES","JP","CN","IN","BR","MX","KR","NL","CH","SE","AE","SG","ZA","NG","SA","TR","ID","PH","TH","VN","MY","NZ","AR"],We=new Set(libphonenumberJs.getCountries());function $e(e,n){let t=e.startsWith("+")?e:`+${e}`,o=n.replace(/\D/g,"");return `${t}${o}`}function Ue(e){let n=e.idd?.root;if(!n)return [];let o=(e.idd?.suffixes?.length?e.idd.suffixes:[""]).map(a=>$e(n,a)).filter(a=>/^\+\d+$/.test(a));return Array.from(new Set(o))}function He(e){let n=libphonenumberJs.getExampleNumber(e,ke__default.default);return n?n.formatNational().replace(/\d/g,"#"):void 0}function Ie(e){let n=Te.indexOf(e);return n===-1?Number.MAX_SAFE_INTEGER:n}var _e=Me__default.default.filter(e=>We.has(e.cca2)).map(e=>{let n=e.cca2,t=Ue(e),o=`+${libphonenumberJs.getCountryCallingCode(n)}`;return !e.flag||t.length===0?null:{code:n,name:e.name.common,dialCode:o,dialCodes:t,flag:e.flag,format:He(n)}}).filter(e=>e!==null).sort((e,n)=>{let t=Ie(e.code)-Ie(n.code);return t!==0?t:e.name.localeCompare(n.name)}),T=_e,Ve=new Map(T.map(e=>[e.code,e])),Ge=T.reduce((e,n)=>{for(let t of n.dialCodes){let o=e.get(t)??[];o.push(n),e.set(t,o);}return e},new Map),Ke=T.flatMap(e=>e.dialCodes.map(n=>({dialCode:n,country:e}))).sort((e,n)=>n.dialCode.length-e.dialCode.length),Ae=new Map;function je(e){return Array.isArray(e)?[...e]:e?[e]:[]}function Qe(e){let n=je(e);if(n.length===0||typeof Intl>"u"||typeof Intl.DisplayNames>"u")return;let t=n.join("|"),o=Ae.get(t);if(o)return o;try{let a=new Intl.DisplayNames(n,{type:"region"});return Ae.set(t,a),a}catch{return}}function Ye(e){let n=e.replace(/\D/g,"");return n?`+${n}`:""}function K(e){return Ve.get(e.toUpperCase())}function Ne(e,n){return e?Qe(n)?.of(e.code)??e.displayName??e.name:void 0}function j(e,n){if(!e)return;let t=Ne(e,n);return t?{...e,displayName:t}:e}function de(e,n){return n?e.map(t=>j(t,n)??t):e}function xe(e){return Ge.get(Ye(e))??[]}function qe(e){return xe(e)[0]}function pe(e){let n=e.trim();if(!n)return;let t=n.startsWith("+")?`+${n.replace(/\D/g,"")}`:n.startsWith("00")?`+${n.slice(2).replace(/\D/g,"")}`:"";if(!t)return;let o=libphonenumberJs.parsePhoneNumberFromString(t);return o?.country?K(o.country):Ke.find(a=>t.startsWith(a.dialCode))?.country}var fe={selectCountry:"Select country",countrySearchPlaceholder:"Search countries...",noCountriesFound:"No countries found",searchCountriesAriaLabel:"Search countries",countryOptionsAriaLabel:"Country options",countryButtonAriaLabel:"Open country selector"},Xe={en:fe,fr:{selectCountry:"Choisir un pays",countrySearchPlaceholder:"Rechercher un pays...",noCountriesFound:"Aucun pays trouv\xE9",searchCountriesAriaLabel:"Rechercher des pays",countryOptionsAriaLabel:"Options de pays",countryButtonAriaLabel:"Ouvrir le s\xE9lecteur de pays"},de:{selectCountry:"Land ausw\xE4hlen",countrySearchPlaceholder:"Land suchen...",noCountriesFound:"Keine L\xE4nder gefunden",searchCountriesAriaLabel:"L\xE4nder suchen",countryOptionsAriaLabel:"L\xE4nderoptionen",countryButtonAriaLabel:"L\xE4nderauswahl \xF6ffnen"},es:{selectCountry:"Seleccionar pa\xEDs",countrySearchPlaceholder:"Buscar pa\xEDs...",noCountriesFound:"No se encontraron pa\xEDses",searchCountriesAriaLabel:"Buscar pa\xEDses",countryOptionsAriaLabel:"Opciones de pa\xEDs",countryButtonAriaLabel:"Abrir selector de pa\xEDs"},pt:{selectCountry:"Selecionar pa\xEDs",countrySearchPlaceholder:"Pesquisar pa\xEDs...",noCountriesFound:"Nenhum pa\xEDs encontrado",searchCountriesAriaLabel:"Pesquisar pa\xEDses",countryOptionsAriaLabel:"Op\xE7\xF5es de pa\xEDs",countryButtonAriaLabel:"Abrir seletor de pa\xEDs"},it:{selectCountry:"Seleziona paese",countrySearchPlaceholder:"Cerca paese...",noCountriesFound:"Nessun paese trovato",searchCountriesAriaLabel:"Cerca paesi",countryOptionsAriaLabel:"Opzioni paese",countryButtonAriaLabel:"Apri selettore paese"},ja:{selectCountry:"\u56FD\u3092\u9078\u629E",countrySearchPlaceholder:"\u56FD\u3092\u691C\u7D22...",noCountriesFound:"\u56FD\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",searchCountriesAriaLabel:"\u56FD\u3092\u691C\u7D22",countryOptionsAriaLabel:"\u56FD\u306E\u5019\u88DC",countryButtonAriaLabel:"\u56FD\u306E\u30BB\u30EC\u30AF\u30BF\u30FC\u3092\u958B\u304F"},ko:{selectCountry:"\uAD6D\uAC00 \uC120\uD0DD",countrySearchPlaceholder:"\uAD6D\uAC00 \uAC80\uC0C9...",noCountriesFound:"\uAD6D\uAC00\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",searchCountriesAriaLabel:"\uAD6D\uAC00 \uAC80\uC0C9",countryOptionsAriaLabel:"\uAD6D\uAC00 \uC635\uC158",countryButtonAriaLabel:"\uAD6D\uAC00 \uC120\uD0DD\uAE30 \uC5F4\uAE30"},zh:{selectCountry:"\u9009\u62E9\u56FD\u5BB6",countrySearchPlaceholder:"\u641C\u7D22\u56FD\u5BB6...",noCountriesFound:"\u672A\u627E\u5230\u56FD\u5BB6",searchCountriesAriaLabel:"\u641C\u7D22\u56FD\u5BB6",countryOptionsAriaLabel:"\u56FD\u5BB6\u9009\u9879",countryButtonAriaLabel:"\u6253\u5F00\u56FD\u5BB6\u9009\u62E9\u5668"},ar:{selectCountry:"\u0627\u062E\u062A\u0631 \u0627\u0644\u062F\u0648\u0644\u0629",countrySearchPlaceholder:"\u0627\u0628\u062D\u062B \u0639\u0646 \u062F\u0648\u0644\u0629...",noCountriesFound:"\u0644\u0645 \u064A\u062A\u0645 \u0627\u0644\u0639\u062B\u0648\u0631 \u0639\u0644\u0649 \u062F\u0648\u0644",searchCountriesAriaLabel:"\u0627\u0628\u062D\u062B \u0639\u0646 \u0627\u0644\u062F\u0648\u0644",countryOptionsAriaLabel:"\u062E\u064A\u0627\u0631\u0627\u062A \u0627\u0644\u062F\u0648\u0644",countryButtonAriaLabel:"\u0627\u0641\u062A\u062D \u0645\u062D\u062F\u062F \u0627\u0644\u062F\u0648\u0644\u0629"},hi:{selectCountry:"\u0926\u0947\u0936 \u091A\u0941\u0928\u0947\u0902",countrySearchPlaceholder:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902...",noCountriesFound:"\u0915\u094B\u0908 \u0926\u0947\u0936 \u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E",searchCountriesAriaLabel:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902",countryOptionsAriaLabel:"\u0926\u0947\u0936 \u0935\u093F\u0915\u0932\u094D\u092A",countryButtonAriaLabel:"\u0926\u0947\u0936 \u091A\u092F\u0928 \u0916\u094B\u0932\u0947\u0902"}};function Ze(e){let t=(Array.isArray(e)?e:e?[e]:[]).find(Boolean);return t?t.toLowerCase().split("-")[0]:void 0}function Ce(e,n){let t=Ze(e),o=t?Xe[t]:void 0;return {...fe,...o,...n}}function W(e){let n=e.trim(),t=w(n);return n.startsWith("+")&&!t?"+":t?n.startsWith("+")?`+${t}`:t:""}function ye(e){return e?.code}function w(e){return e.replace(/\D/g,"")}function he(e,n){return e&&new libphonenumberJs.AsYouType(ye(n)).input(W(e))}function ne(e){return W(e)}function nn(e,n){return !e||!n?false:e.trim().startsWith("+")?libphonenumberJs.validatePhoneNumberLength(W(e))===void 0:libphonenumberJs.validatePhoneNumberLength(w(e),ye(n))===void 0}function ge(e,n,t){if(!e)return false;if(t)return t(e,n);let o=W(e),a=ye(n);return a?o.startsWith("+")?libphonenumberJs.isValidPhoneNumber(o):libphonenumberJs.isValidPhoneNumber(w(o),a):libphonenumberJs.isPossiblePhoneNumber(o.startsWith("+")?o:`+${w(o)}`)}function $(e,n){if(!n)return e;let t=W(e);if(!t||t==="+")return "";if(t.startsWith("+"))return t;let o=w(t);return n.dialCodes.find(d=>o.startsWith(d.replace("+","")))?`+${o}`:`${n.dialCode}${o}`}function te(e,n){if(!n)return e;let t=W(e),o=w(t);for(let a of n.dialCodes){let d=a.replace("+","");if(o.startsWith(d))return o.slice(d.length)}return o}function me(e,n,t){let o=n.toLowerCase().trim();return o?e.filter(a=>a.name.toLowerCase().includes(o)||(a.displayName??"").toLowerCase().includes(o)||a.code.toLowerCase().includes(o)||a.dialCodes.some(d=>d.includes(o))):t?.length?[...e].sort((a,d)=>{let P=t.indexOf(a.code),N=t.indexOf(d.code);return P!==-1&&N!==-1?P-N:P!==-1?-1:N!==-1?1:(a.displayName??a.name).localeCompare(d.displayName??d.name)}):e}function be(e){return e?.displayName??e?.name??""}function Pe(e){return e?.format?e.format.replace(/#/g,"0"):e?.dialCode?`${e.dialCode} 000 000 0000`:"Phone number"}function on(e,n){return e.slice(0,n).replace(/\D/g,"").length}function rn(e,n){if(n<=0)return e.startsWith("+")?1:0;let t=0;for(let o=0;o<e.length;o+=1)if(/\d/.test(e[o])&&(t+=1,t===n))return o+1;return e.length}function Le(e={}){let{value:n,defaultValue:t="",onChange:o,onBlur:a,onFocus:d,defaultCountry:P="US",preferredCountries:N,excludeCountries:H,onlyCountries:_,autoDetect:Y=true,formatOnType:q=true,includeDialCode:p=false,validator:O,locale:m,labels:X}=e,v=n!==void 0,Z=react.useRef(null),V=react.useRef(null),y=react.useMemo(()=>{let r=T;return _?.length&&(r=r.filter(i=>_.includes(i.code))),H?.length&&(r=r.filter(i=>!H.includes(i.code))),r},[_,H]),R=react.useMemo(()=>de(y,m),[y,m]),E=react.useMemo(()=>Ce(m,X),[m,X]),B=y.find(r=>r.code===P)||y[0],[L,F]=react.useState(t),[s,z]=react.useState(B),[h,f]=react.useState(false),[k,M]=react.useState(""),u=v?n:L;react.useEffect(()=>{let r=y.find(i=>i.code===P)||y[0];r&&r.code!==s?.code&&z(r);},[P,y,s?.code]),react.useEffect(()=>{if(Y&&u){let r=pe(u);r&&y.some(i=>i.code===r.code)&&r.code!==s?.code&&z(r);}},[y,Y,u,s?.code]);let G=react.useMemo(()=>q?he(p&&u.startsWith("+")?te(u,s):u,s):p&&u.startsWith("+")?te(u,s):u,[q,p,u,s]),re=react.useMemo(()=>p&&s?$(u,s):u,[u,s,p]),S=react.useMemo(()=>ge(u,s,O),[u,s,O]),ie=react.useMemo(()=>j(s,m),[s,m]),ae=react.useMemo(()=>me(R,k,N),[R,k,N]),C=react.useCallback(r=>j(r,m),[m]);react.useLayoutEffect(()=>{let r=V.current,i=Z.current;if(r===null||!i||typeof i.setSelectionRange!="function"||typeof document<"u"&&document.activeElement!==i)return;let ee=rn(G,r);i.setSelectionRange(ee,ee),V.current=null;},[G]);let I=react.useCallback(r=>{let i=ne(r);v||F(i),o?.(p?$(i,s):i,C(s));},[v,o,s,p,C]),x=react.useCallback(r=>{let i=K(r);i&&(z(i),o?.(p?$(u,i):u,C(i)));},[u,o,p,C]),se=react.useCallback(r=>{let i=K(r.code)??r;z(i),f(false),M(""),o?.(p?$(u,i):u,C(i));},[u,o,p,C]),J=react.useCallback(()=>{f(r=>!r),h&&M("");},[h]),ue=react.useCallback(()=>{f(true);},[]),le=react.useCallback(()=>{f(false),M("");},[]),ce=react.useCallback(()=>{v||F(""),o?.("",C(s));},[v,o,s,C]),l=react.useCallback(r=>{let i=r.target.value,ee=r.target.selectionStart??i.length,Oe=i.trim().startsWith("+")?`+${i.replace(/\D/g,"")}`:ne(i);V.current=on(i,ee),I(Oe);},[I]),A=react.useCallback(()=>{d?.();},[d]),b=react.useCallback(()=>{a?.();},[a]);return {phone:u,fullPhone:re,country:ie,isValid:S,isOpen:h,searchQuery:k,labels:E,setPhone:I,setCountry:x,toggleDropdown:J,openDropdown:ue,closeDropdown:le,setSearchQuery:M,clear:ce,inputProps:{ref:Z,value:G,onChange:l,onFocus:A,onBlur:b,type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:Pe(s),"aria-invalid":u?!S:void 0},countryButtonProps:{onClick:J,"aria-expanded":h,"aria-haspopup":"listbox","aria-label":E.countryButtonAriaLabel},filteredCountries:ae,selectCountry:se}}var dn=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"18 15 12 9 6 15"})}),pn=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})}),fn=react.forwardRef(function(n,t){let{value:o,defaultValue:a,onChange:d,onBlur:P,onFocus:N,inputClassName:H,selectorClassName:_,containerClassName:Y,searchable:q=true,placeholder:p,disabled:O,readOnly:m,name:X,id:v,"aria-label":Z,"aria-labelledby":V,...y}=n,R=react.useRef(null),E=react.useRef([]),[B,L]=react.useState(0),F=react.useId(),{inputProps:s,countryButtonProps:z,country:h,filteredCountries:f,isOpen:k,isValid:M,searchQuery:u,setSearchQuery:G,setCountry:re,selectCountry:S,clear:ie,openDropdown:ae,closeDropdown:C,labels:I}=Le({value:o,defaultValue:a,onChange:d,onBlur:P,onFocus:N,...y}),x=s.ref,se=react.useCallback(l=>{R.current=l,typeof x=="function"?x(l):x&&"current"in x&&(x.current=l);},[x]),J=react.useCallback(()=>{R.current?.focus();},[]),ue=react.useCallback(()=>{R.current?.blur();},[]),le=react.useCallback(l=>{S(l),L(0);},[S]),ce=react.useCallback((l,A,b)=>{switch(l.key){case "Enter":case " ":l.preventDefault(),S(A),L(0);break;case "ArrowDown":if(l.preventDefault(),b<f.length-1){let r=b+1;L(r),E.current[r]?.focus();}break;case "ArrowUp":if(l.preventDefault(),b>0){let r=b-1;L(r),E.current[r]?.focus();}break;case "Escape":l.preventDefault(),C();break}},[S,f.length,C]);return react.useEffect(()=>{if(f.length===0){B!==0&&L(0);return}B>=f.length&&L(f.length-1);},[f.length,B]),react.useImperativeHandle(t,()=>({focus:J,blur:ue,clear:ie,setCountry:re,getCountry:()=>h,open:ae,close:C})),jsxRuntime.jsxs("div",{className:Y,"data-valid":M,children:[jsxRuntime.jsxs("button",{...z,type:"button",className:_,disabled:O,tabIndex:O?-1:0,"aria-controls":F,children:[h?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:h.flag}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:h.dialCode})]}):jsxRuntime.jsx("span",{className:"phone-input-placeholder",children:I.selectCountry}),jsxRuntime.jsx("span",{className:"phone-input-arrow","aria-hidden":"true",children:k?jsxRuntime.jsx(dn,{size:12}):jsxRuntime.jsx(pn,{size:12})})]}),jsxRuntime.jsx("input",{...s,ref:se,id:v,name:X,className:H,placeholder:p||s.placeholder,disabled:O,readOnly:m,"aria-label":Z,"aria-labelledby":V}),k&&jsxRuntime.jsxs("div",{className:"phone-input-dropdown",children:[q&&jsxRuntime.jsx("div",{className:"phone-input-search",children:jsxRuntime.jsx("input",{type:"text",value:u,onChange:l=>G(l.target.value),placeholder:I.countrySearchPlaceholder,autoFocus:true,"aria-controls":F,"aria-label":I.searchCountriesAriaLabel})}),jsxRuntime.jsxs("ul",{className:"phone-input-country-list",id:F,role:"listbox","aria-label":I.countryOptionsAriaLabel,children:[f.map((l,A)=>jsxRuntime.jsxs("li",{ref:b=>{E.current[A]=b;},role:"option","aria-selected":l.code===h?.code,className:`phone-input-country-option ${l.code===h?.code?"selected":""} ${A===B?"highlighted":""}`,onClick:()=>le(l),onKeyDown:b=>ce(b,l,A),onMouseEnter:()=>L(A),tabIndex:A===B?0:-1,children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:l.flag}),jsxRuntime.jsx("span",{className:"phone-input-country-name",children:be(l)}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:l.dialCode})]},l.code)),f.length===0&&jsxRuntime.jsx("li",{className:"phone-input-no-results",children:I.noCountriesFound})]})]})]})});exports.DEFAULT_PHONE_INPUT_LABELS=fe;exports.PhoneInput=fn;exports.addDialCode=$;exports.cleanPhone=w;exports.countries=T;exports.detectCountryFromPhone=pe;exports.filterCountries=me;exports.formatPhone=he;exports.getCountriesByDialCode=xe;exports.getCountryByCode=K;exports.getCountryByDialCode=qe;exports.getCountryDisplayName=be;exports.getLocalizedCountryName=Ne;exports.getPlaceholder=Pe;exports.localizeCountries=de;exports.localizeCountry=j;exports.removeDialCode=te;exports.resolvePhoneInputLabels=Ce;exports.unformatPhone=ne;exports.usePhoneInput=Le;exports.validatePhone=ge;exports.validatePhoneLength=nn;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countries.ts","../src/utils.ts","../src/usePhoneInput.ts","../src/PhoneInput.tsx"],"names":["PRIORITY_COUNTRIES","supportedCountries","getCountries","normalizeDialCode","root","suffix","normalizedRoot","digitsOnlySuffix","buildDialCodes","country","dialCodes","dialCode","getCountryFormat","code","example","getExampleNumber","examples","getCountryPriority","index","generatedCountries","worldCountries","getCountryCallingCode","left","right","priorityDelta","countries","countryMap","countriesByDialCode","map","matches","dialCodeMatchers","normalizeLookupDialCode","digits","getCountryByCode","getCountriesByDialCode","getCountryByDialCode","detectCountryFromPhone","phone","trimmed","normalized","parsedPhone","parsePhoneNumberFromString","entry","normalizePhoneInput","cleanPhone","getCountryCode","formatPhone","AsYouType","unformatPhone","formattedPhone","validatePhoneLength","validateLength","validatePhone","customValidator","countryCode","isValidPhoneNumber","isPossiblePhoneNumber","addDialCode","removeDialCode","dialDigits","filterCountries","query","preferredCountries","lowerQuery","a","b","aPreferred","bPreferred","getPlaceholder","usePhoneInput","options","controlledValue","defaultValue","onChange","onBlur","onFocus","defaultCountry","excludeCountries","onlyCountries","autoDetect","formatOnType","includeDialCode","validator","isControlled","availableCountries","useMemo","filtered","c","initialCountry","internalPhone","setInternalPhone","useState","setCountry","isOpen","setIsOpen","searchQuery","setSearchQuery","useEffect","nextCountry","detected","candidate","fullPhone","isValid","filteredCountries","setPhone","useCallback","newPhone","unformatted","setCountryByCode","newCountry","selectCountry","selectedCountry","toggleDropdown","prev","openDropdown","closeDropdown","clear","handleInputChange","event","rawValue","handleFocus","handleBlur","ChevronUpIcon","size","jsx","ChevronDownIcon","PhoneInput","forwardRef","props","ref","value","inputClassName","selectorClassName","containerClassName","placeholder","disabled","readOnly","name","id","ariaLabel","ariaLabelledBy","inputRef","useRef","optionRefs","highlightedIndex","setHighlightedIndex","listboxId","useId","inputProps","countryButtonProps","focus","blur","handleCountryClick","handleCountryKeyDown","e","nextIndex","useImperativeHandle","jsxs","Fragment","element"],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AhB/CA,CAAAA,CAAE,IAiBT,CACD,CAAA,CACAgB,CAAAA,CAAkB,MAAA,GAAW,CAAA,EAC5BqB,cAAAA,CAAC,IAAA,CAAA,CAAG,SAAA,CAAU,wBAAA,CAAyB,QAAA,CAAA,oBAAA,CAAkB,CAAA,CAAA,CAE7D,CAAA,CAAA,CACF,CAAA,CAAA,CAEJ,CAEJ,CACF","file":"index.cjs","sourcesContent":["import { getCountries, getCountryCallingCode, getExampleNumber, parsePhoneNumberFromString, type CountryCode } from 'libphonenumber-js';\r\nimport examples from 'libphonenumber-js/mobile/examples';\r\nimport worldCountries from 'world-countries';\r\n\r\nexport interface Country {\r\n code: string;\r\n name: string;\r\n dialCode: string;\r\n dialCodes: string[];\r\n flag: string;\r\n format?: string;\r\n}\r\n\r\nconst PRIORITY_COUNTRIES = [\r\n 'US', 'GB', 'CA', 'AU', 'DE', 'FR', 'IT', 'ES', 'JP', 'CN', 'IN', 'BR', 'MX', 'KR', 'NL',\r\n 'CH', 'SE', 'AE', 'SG', 'ZA', 'NG', 'SA', 'TR', 'ID', 'PH', 'TH', 'VN', 'MY', 'NZ', 'AR'\r\n];\r\n\r\nconst supportedCountries = new Set(getCountries());\r\n\r\nfunction normalizeDialCode(root: string, suffix: string) {\r\n const normalizedRoot = root.startsWith('+') ? root : `+${root}`;\r\n const digitsOnlySuffix = suffix.replace(/\\D/g, '');\r\n return `${normalizedRoot}${digitsOnlySuffix}`;\r\n}\r\n\r\nfunction buildDialCodes(country: (typeof worldCountries)[number]) {\r\n const root = country.idd?.root;\r\n if (!root) {\r\n return [];\r\n }\r\n\r\n const suffixes = country.idd?.suffixes?.length ? country.idd.suffixes : [''];\r\n const dialCodes = suffixes\r\n .map((suffix) => normalizeDialCode(root, suffix))\r\n .filter((dialCode) => /^\\+\\d+$/.test(dialCode));\r\n\r\n return Array.from(new Set(dialCodes));\r\n}\r\n\r\nfunction getCountryFormat(code: CountryCode) {\r\n const example = getExampleNumber(code, examples);\r\n return example ? example.formatNational().replace(/\\d/g, '#') : undefined;\r\n}\r\n\r\nfunction getCountryPriority(code: string) {\r\n const index = PRIORITY_COUNTRIES.indexOf(code);\r\n return index === -1 ? Number.MAX_SAFE_INTEGER : index;\r\n}\r\n\r\nconst generatedCountries = worldCountries\r\n .filter((country) => supportedCountries.has(country.cca2 as CountryCode))\r\n .map<Country | null>((country) => {\r\n const code = country.cca2 as CountryCode;\r\n const dialCodes = buildDialCodes(country);\r\n const dialCode = `+${getCountryCallingCode(code)}`;\r\n\r\n if (!country.flag || dialCodes.length === 0) {\r\n return null;\r\n }\r\n\r\n return {\r\n code,\r\n name: country.name.common,\r\n dialCode,\r\n dialCodes,\r\n flag: country.flag,\r\n format: getCountryFormat(code),\r\n } satisfies Country;\r\n })\r\n .filter((country): country is Country => country !== null)\r\n .sort((left, right) => {\r\n const priorityDelta = getCountryPriority(left.code) - getCountryPriority(right.code);\r\n return priorityDelta !== 0 ? priorityDelta : left.name.localeCompare(right.name);\r\n });\r\n\r\nexport const countries: Country[] = generatedCountries;\r\n\r\nexport const countryMap = new Map(countries.map((country) => [country.code, country]));\r\n\r\nconst countriesByDialCode = countries.reduce((map, country) => {\r\n for (const dialCode of country.dialCodes) {\r\n const matches = map.get(dialCode) ?? [];\r\n matches.push(country);\r\n map.set(dialCode, matches);\r\n }\r\n\r\n return map;\r\n}, new Map<string, Country[]>());\r\n\r\nconst dialCodeMatchers = countries\r\n .flatMap((country) => country.dialCodes.map((dialCode) => ({ dialCode, country })))\r\n .sort((left, right) => right.dialCode.length - left.dialCode.length);\r\n\r\nfunction normalizeLookupDialCode(dialCode: string) {\r\n const digits = dialCode.replace(/\\D/g, '');\r\n return digits ? `+${digits}` : '';\r\n}\r\n\r\nexport function getCountryByCode(code: string): Country | undefined {\r\n return countryMap.get(code.toUpperCase());\r\n}\r\n\r\nexport function getCountriesByDialCode(dialCode: string): Country[] {\r\n return countriesByDialCode.get(normalizeLookupDialCode(dialCode)) ?? [];\r\n}\r\n\r\nexport function getCountryByDialCode(dialCode: string): Country | undefined {\r\n return getCountriesByDialCode(dialCode)[0];\r\n}\r\n\r\nexport function detectCountryFromPhone(phone: string): Country | undefined {\r\n const trimmed = phone.trim();\r\n\r\n if (!trimmed) {\r\n return undefined;\r\n }\r\n\r\n const normalized = trimmed.startsWith('+')\r\n ? `+${trimmed.replace(/\\D/g, '')}`\r\n : trimmed.startsWith('00')\r\n ? `+${trimmed.slice(2).replace(/\\D/g, '')}`\r\n : '';\r\n\r\n if (!normalized) {\r\n return undefined;\r\n }\r\n\r\n const parsedPhone = parsePhoneNumberFromString(normalized);\r\n if (parsedPhone?.country) {\r\n return getCountryByCode(parsedPhone.country);\r\n }\r\n\r\n return dialCodeMatchers.find((entry) => normalized.startsWith(entry.dialCode))?.country;\r\n}\r\n","import type { Country } from './countries';\r\nimport { AsYouType, isPossiblePhoneNumber, isValidPhoneNumber, validatePhoneNumberLength as validateLength, type CountryCode } from 'libphonenumber-js';\r\n\r\nfunction normalizePhoneInput(phone: string): string {\r\n const trimmed = phone.trim();\r\n const digits = cleanPhone(trimmed);\r\n\r\n if (!digits) {\r\n return '';\r\n }\r\n\r\n return trimmed.startsWith('+') ? `+${digits}` : digits;\r\n}\r\n\r\nfunction getCountryCode(country: Country | undefined): CountryCode | undefined {\r\n return country?.code as CountryCode | undefined;\r\n}\r\n\r\n/**\r\n * Remove all non-digit characters from phone number\r\n */\r\nexport function cleanPhone(phone: string): string {\r\n return phone.replace(/\\D/g, '');\r\n}\r\n\r\n/**\r\n * Format phone number according to country format\r\n */\r\nexport function formatPhone(phone: string, country: Country | undefined): string {\r\n if (!phone) return phone;\r\n\r\n const formatter = new AsYouType(getCountryCode(country));\r\n return formatter.input(normalizePhoneInput(phone));\r\n}\r\n\r\n/**\r\n * Get raw phone number without formatting\r\n */\r\nexport function unformatPhone(formattedPhone: string): string {\r\n return normalizePhoneInput(formattedPhone);\r\n}\r\n\r\n/**\r\n * Validate phone number length based on country\r\n */\r\nexport function validatePhoneLength(phone: string, country: Country | undefined): boolean {\r\n if (!phone || !country) return false;\r\n\r\n if (phone.trim().startsWith('+')) {\r\n return validateLength(normalizePhoneInput(phone)) === undefined;\r\n }\r\n\r\n return validateLength(cleanPhone(phone), getCountryCode(country)) === undefined;\r\n}\r\n\r\n/**\r\n * Validate phone number format\r\n */\r\nexport function validatePhone(\r\n phone: string,\r\n country: Country | undefined,\r\n customValidator?: (phone: string, country: Country | undefined) => boolean\r\n): boolean {\r\n if (!phone) return false;\r\n \r\n if (customValidator) {\r\n return customValidator(phone, country);\r\n }\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const countryCode = getCountryCode(country);\r\n\r\n if (!countryCode) {\r\n return isPossiblePhoneNumber(normalized.startsWith('+') ? normalized : `+${cleanPhone(normalized)}`);\r\n }\r\n\r\n if (normalized.startsWith('+')) {\r\n return isValidPhoneNumber(normalized);\r\n }\r\n\r\n return isValidPhoneNumber(cleanPhone(normalized), countryCode);\r\n}\r\n\r\n/**\r\n * Add dial code to phone number\r\n */\r\nexport function addDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n if (!normalized) return '';\r\n if (normalized.startsWith('+')) return normalized;\r\n\r\n const digits = cleanPhone(normalized);\r\n const matchingDialCode = country.dialCodes.find((dialCode) => digits.startsWith(dialCode.replace('+', '')));\r\n return matchingDialCode ? `+${digits}` : `${country.dialCode}${digits}`;\r\n}\r\n\r\n/**\r\n * Remove dial code from phone number\r\n */\r\nexport function removeDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const digits = cleanPhone(normalized);\r\n\r\n for (const dialCode of country.dialCodes) {\r\n const dialDigits = dialCode.replace('+', '');\r\n if (digits.startsWith(dialDigits)) {\r\n return digits.slice(dialDigits.length);\r\n }\r\n }\r\n\r\n return digits;\r\n}\r\n\r\n/**\r\n * Filter countries by search query\r\n */\r\nexport function filterCountries(\r\n countries: Country[],\r\n query: string,\r\n preferredCountries?: string[]\r\n): Country[] {\r\n const lowerQuery = query.toLowerCase().trim();\r\n \r\n if (!lowerQuery) {\r\n // Sort by preferred countries first\r\n if (preferredCountries?.length) {\r\n return [...countries].sort((a, b) => {\r\n const aPreferred = preferredCountries.indexOf(a.code);\r\n const bPreferred = preferredCountries.indexOf(b.code);\r\n if (aPreferred !== -1 && bPreferred !== -1) return aPreferred - bPreferred;\r\n if (aPreferred !== -1) return -1;\r\n if (bPreferred !== -1) return 1;\r\n return a.name.localeCompare(b.name);\r\n });\r\n }\r\n return countries;\r\n }\r\n \r\n return countries.filter(\r\n country =>\r\n country.name.toLowerCase().includes(lowerQuery) ||\r\n country.code.toLowerCase().includes(lowerQuery) ||\r\n country.dialCodes.some((dialCode) => dialCode.includes(lowerQuery))\r\n );\r\n}\r\n\r\n/**\r\n * Get placeholder based on country format\r\n */\r\nexport function getPlaceholder(country: Country | undefined): string {\r\n if (!country?.format) return country?.dialCode ? `${country.dialCode} 000 000 0000` : 'Phone number';\r\n return country.format.replace(/#/g, '0');\r\n}\r\n","import { useCallback, useMemo, useState, useEffect } from 'react';\r\nimport type { PhoneInputOptions, UsePhoneInputReturn } from './types';\r\nimport type { Country } from './countries';\r\nimport { countries, getCountryByCode, detectCountryFromPhone } from './countries';\r\nimport {\r\n formatPhone,\r\n unformatPhone,\r\n validatePhone,\r\n addDialCode,\r\n removeDialCode,\r\n filterCountries,\r\n getPlaceholder,\r\n} from './utils';\r\n\r\nexport function usePhoneInput(\r\n options: PhoneInputOptions & {\r\n value?: string;\r\n defaultValue?: string;\r\n onChange?: (phone: string, country: Country | undefined) => void;\r\n onBlur?: () => void;\r\n onFocus?: () => void;\r\n } = {}\r\n): UsePhoneInputReturn {\r\n const {\r\n value: controlledValue,\r\n defaultValue = '',\r\n onChange,\r\n onBlur,\r\n onFocus,\r\n defaultCountry = 'US',\r\n preferredCountries,\r\n excludeCountries,\r\n onlyCountries,\r\n autoDetect = true,\r\n formatOnType = true,\r\n includeDialCode = false,\r\n validator,\r\n } = options;\r\n\r\n const isControlled = controlledValue !== undefined;\r\n\r\n // Filter available countries\r\n const availableCountries = useMemo(() => {\r\n let filtered = countries;\r\n \r\n if (onlyCountries?.length) {\r\n filtered = filtered.filter(c => onlyCountries.includes(c.code));\r\n }\r\n \r\n if (excludeCountries?.length) {\r\n filtered = filtered.filter(c => !excludeCountries.includes(c.code));\r\n }\r\n \r\n return filtered;\r\n }, [onlyCountries, excludeCountries]);\r\n\r\n // Initialize state\r\n const initialCountry = getCountryByCode(defaultCountry) || availableCountries[0];\r\n const [internalPhone, setInternalPhone] = useState(defaultValue);\r\n const [country, setCountry] = useState<Country | undefined>(initialCountry);\r\n const [isOpen, setIsOpen] = useState(false);\r\n const [searchQuery, setSearchQuery] = useState('');\r\n\r\n // Current phone value\r\n const phone = isControlled ? controlledValue : internalPhone;\r\n\r\n useEffect(() => {\r\n const nextCountry = getCountryByCode(defaultCountry) || availableCountries[0];\r\n if (nextCountry && nextCountry.code !== country?.code) {\r\n setCountry(nextCountry);\r\n }\r\n }, [defaultCountry, availableCountries, country?.code]);\r\n\r\n // Auto-detect country from phone\r\n useEffect(() => {\r\n if (autoDetect && phone) {\r\n const detected = detectCountryFromPhone(phone);\r\n if (detected && availableCountries.some((candidate) => candidate.code === detected.code) && detected.code !== country?.code) {\r\n setCountry(detected);\r\n }\r\n }\r\n }, [availableCountries, autoDetect, phone, country?.code]);\r\n\r\n // Format phone number\r\n const formattedPhone = useMemo(() => {\r\n if (formatOnType) {\r\n return formatPhone(includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone, country);\r\n }\r\n return includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone;\r\n }, [formatOnType, includeDialCode, phone, country]);\r\n\r\n // Full phone with dial code\r\n const fullPhone = useMemo(() => {\r\n if (includeDialCode && country) {\r\n return addDialCode(phone, country);\r\n }\r\n return phone;\r\n }, [phone, country, includeDialCode]);\r\n\r\n // Validation\r\n const isValid = useMemo(\r\n () => validatePhone(phone, country, validator),\r\n [phone, country, validator]\r\n );\r\n\r\n // Filtered countries for dropdown\r\n const filteredCountries = useMemo(\r\n () => filterCountries(availableCountries, searchQuery, preferredCountries),\r\n [availableCountries, searchQuery, preferredCountries]\r\n );\r\n\r\n // Set phone handler\r\n const setPhone = useCallback(\r\n (newPhone: string) => {\r\n const unformatted = unformatPhone(newPhone);\r\n if (!isControlled) {\r\n setInternalPhone(unformatted);\r\n }\r\n onChange?.(includeDialCode ? addDialCode(unformatted, country) : unformatted, country);\r\n },\r\n [isControlled, onChange, country, includeDialCode]\r\n );\r\n\r\n // Set country handler\r\n const setCountryByCode = useCallback(\r\n (code: string) => {\r\n const newCountry = getCountryByCode(code);\r\n if (newCountry) {\r\n setCountry(newCountry);\r\n onChange?.(includeDialCode ? addDialCode(phone, newCountry) : phone, newCountry);\r\n }\r\n },\r\n [phone, onChange, includeDialCode]\r\n );\r\n\r\n // Select country from dropdown\r\n const selectCountry = useCallback(\r\n (selectedCountry: Country) => {\r\n setCountry(selectedCountry);\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n onChange?.(\r\n includeDialCode ? addDialCode(phone, selectedCountry) : phone,\r\n selectedCountry\r\n );\r\n },\r\n [phone, onChange, includeDialCode]\r\n );\r\n\r\n // Toggle dropdown\r\n const toggleDropdown = useCallback(() => {\r\n setIsOpen(prev => !prev);\r\n if (isOpen) {\r\n setSearchQuery('');\r\n }\r\n }, [isOpen]);\r\n\r\n // Open dropdown\r\n const openDropdown = useCallback(() => {\r\n setIsOpen(true);\r\n }, []);\r\n\r\n // Close dropdown\r\n const closeDropdown = useCallback(() => {\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n }, []);\r\n\r\n // Clear input\r\n const clear = useCallback(() => {\r\n if (!isControlled) {\r\n setInternalPhone('');\r\n }\r\n onChange?.('', country);\r\n }, [isControlled, onChange, country]);\r\n\r\n // Handle input change\r\n const handleInputChange = useCallback(\r\n (event: React.ChangeEvent<HTMLInputElement>) => {\r\n const rawValue = event.target.value;\r\n const unformatted = rawValue.trim().startsWith('+') ? `+${rawValue.replace(/\\D/g, '')}` : unformatPhone(rawValue);\r\n setPhone(unformatted);\r\n },\r\n [setPhone]\r\n );\r\n\r\n // Handle focus\r\n const handleFocus = useCallback(() => {\r\n onFocus?.();\r\n }, [onFocus]);\r\n\r\n // Handle blur\r\n const handleBlur = useCallback(() => {\r\n onBlur?.();\r\n }, [onBlur]);\r\n\r\n return {\r\n // State\r\n phone,\r\n fullPhone,\r\n country,\r\n isValid,\r\n isOpen,\r\n searchQuery,\r\n // Actions\r\n setPhone,\r\n setCountry: setCountryByCode,\r\n toggleDropdown,\r\n openDropdown,\r\n closeDropdown,\r\n setSearchQuery,\r\n clear,\r\n // Props\r\n inputProps: {\r\n value: formattedPhone,\r\n onChange: handleInputChange,\r\n onFocus: handleFocus,\r\n onBlur: handleBlur,\r\n type: 'tel',\r\n inputMode: 'tel',\r\n autoComplete: 'tel',\r\n placeholder: getPlaceholder(country),\r\n 'aria-invalid': phone ? !isValid : undefined,\r\n },\r\n countryButtonProps: {\r\n onClick: toggleDropdown,\r\n 'aria-expanded': isOpen,\r\n 'aria-haspopup': 'listbox',\r\n },\r\n filteredCountries,\r\n selectCountry,\r\n };\r\n}\r\n","import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useRef, useState } from 'react';\nimport { usePhoneInput } from './usePhoneInput';\nimport type { PhoneInputProps } from './types';\nimport type { Country } from './countries';\n\n// SVG Icon Components (Lucide-style)\nconst ChevronUpIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"18 15 12 9 6 15\" />\n </svg>\n);\n\nconst ChevronDownIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"6 9 12 15 18 9\" />\n </svg>\n);\n\nexport interface PhoneInputRef {\n /** Focus the input */\n focus: () => void;\n /** Blur the input */\n blur: () => void;\n /** Clear the input */\n clear: () => void;\n /** Set country */\n setCountry: (countryCode: string) => void;\n /** Get current country */\n getCountry: () => Country | undefined;\n /** Open country selector */\n open: () => void;\n /** Close country selector */\n close: () => void;\n}\n\n/**\n * PhoneInput component - headless phone input with country selection\n * \n * @example\n * ```tsx\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"US\"\n * />\n * ```\n * \n * @example\n * ```tsx\n * // With custom styling\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"GB\"\n * containerClassName=\"phone-input-container\"\n * inputClassName=\"phone-input\"\n * selectorClassName=\"country-selector\"\n * />\n * ```\n */\nexport const PhoneInput = forwardRef<PhoneInputRef, PhoneInputProps>(\n function PhoneInput(props, ref) {\n const {\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n inputClassName,\n selectorClassName,\n containerClassName,\n placeholder,\n disabled,\n readOnly,\n name,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n ...options\n } = props;\n\n const inputRef = useRef<HTMLInputElement>(null);\n const optionRefs = useRef<Array<HTMLLIElement | null>>([]);\n const [highlightedIndex, setHighlightedIndex] = useState(0);\n const listboxId = useId();\n\n const {\n inputProps,\n countryButtonProps,\n country,\n filteredCountries,\n isOpen,\n isValid,\n searchQuery,\n setSearchQuery,\n setCountry,\n selectCountry,\n clear,\n openDropdown,\n closeDropdown,\n } = usePhoneInput({\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n ...options,\n });\n\n // Focus the input\n const focus = useCallback(() => {\n inputRef.current?.focus();\n }, []);\n\n // Blur the input\n const blur = useCallback(() => {\n inputRef.current?.blur();\n }, []);\n\n // Handle country option click\n const handleCountryClick = useCallback((c: Country) => {\n selectCountry(c);\n setHighlightedIndex(0);\n }, [selectCountry]);\n\n // Handle country option keyboard navigation\n const handleCountryKeyDown = useCallback((e: React.KeyboardEvent, c: Country, index: number) => {\n switch (e.key) {\n case 'Enter':\n case ' ':\n e.preventDefault();\n selectCountry(c);\n setHighlightedIndex(0);\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (index < filteredCountries.length - 1) {\n const nextIndex = index + 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n if (index > 0) {\n const nextIndex = index - 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'Escape':\n e.preventDefault();\n closeDropdown();\n break;\n }\n }, [selectCountry, filteredCountries.length, closeDropdown]);\n\n useEffect(() => {\n if (filteredCountries.length === 0) {\n if (highlightedIndex !== 0) {\n setHighlightedIndex(0);\n }\n return;\n }\n\n if (highlightedIndex >= filteredCountries.length) {\n setHighlightedIndex(filteredCountries.length - 1);\n }\n }, [filteredCountries.length, highlightedIndex]);\n\n // Expose imperative methods\n useImperativeHandle(ref, () => ({\n focus,\n blur,\n clear,\n setCountry,\n getCountry: () => country,\n open: openDropdown,\n close: closeDropdown,\n }));\n\n // Render default UI\n return (\n <div className={containerClassName} data-valid={isValid}>\n {/* Country Selector Button */}\n <button\n {...countryButtonProps}\n type=\"button\"\n className={selectorClassName}\n disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n aria-controls={listboxId}\n >\n {country ? (\n <>\n <span className=\"phone-input-flag\">{country.flag}</span>\n <span className=\"phone-input-dial-code\">{country.dialCode}</span>\n </>\n ) : (\n <span className=\"phone-input-placeholder\">Select</span>\n )}\n <span className=\"phone-input-arrow\" aria-hidden=\"true\">\n {isOpen ? <ChevronUpIcon size={12} /> : <ChevronDownIcon size={12} />}\n </span>\n </button>\n\n {/* Phone Input */}\n <input\n {...inputProps}\n ref={inputRef}\n id={id}\n name={name}\n className={inputClassName}\n placeholder={placeholder || inputProps.placeholder}\n disabled={disabled}\n readOnly={readOnly}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n />\n\n {/* Country Dropdown */}\n {isOpen && (\n <div className=\"phone-input-dropdown\">\n {/* Search Input */}\n <div className=\"phone-input-search\">\n <input\n type=\"text\"\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n placeholder=\"Search countries...\"\n autoFocus\n aria-controls={listboxId}\n aria-label=\"Search countries\"\n />\n </div>\n\n {/* Country List */}\n <ul className=\"phone-input-country-list\" id={listboxId} role=\"listbox\" aria-label=\"Country options\">\n {filteredCountries.map((c, index) => (\n <li\n key={c.code}\n ref={(element) => {\n optionRefs.current[index] = element;\n }}\n role=\"option\"\n aria-selected={c.code === country?.code}\n className={`phone-input-country-option ${\n c.code === country?.code ? 'selected' : ''\n } ${index === highlightedIndex ? 'highlighted' : ''}`}\n onClick={() => handleCountryClick(c)}\n onKeyDown={(e) => handleCountryKeyDown(e, c, index)}\n onMouseEnter={() => setHighlightedIndex(index)}\n tabIndex={index === highlightedIndex ? 0 : -1}\n >\n <span className=\"phone-input-flag\">{c.flag}</span>\n <span className=\"phone-input-country-name\">{c.name}</span>\n <span className=\"phone-input-dial-code\">{c.dialCode}</span>\n </li>\n ))}\n {filteredCountries.length === 0 && (\n <li className=\"phone-input-no-results\">No countries found</li>\n )}\n </ul>\n </div>\n )}\n </div>\n );\n }\n);\n\nexport default PhoneInput;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/countries.ts","../src/labels.ts","../src/utils.ts","../src/usePhoneInput.ts","../src/PhoneInput.tsx"],"names":["PRIORITY_COUNTRIES","supportedCountries","getCountries","normalizeDialCode","root","suffix","normalizedRoot","digitsOnlySuffix","buildDialCodes","country","dialCodes","dialCode","getCountryFormat","code","example","getExampleNumber","examples","getCountryPriority","index","generatedCountries","worldCountries","getCountryCallingCode","left","right","priorityDelta","countries","countryMap","countriesByDialCode","map","matches","dialCodeMatchers","displayNameCache","normalizeLocales","locale","getDisplayNames","locales","cacheKey","cached","displayNames","normalizeLookupDialCode","digits","getCountryByCode","getLocalizedCountryName","localizeCountry","displayName","localizeCountries","list","getCountriesByDialCode","getCountryByDialCode","detectCountryFromPhone","phone","trimmed","normalized","parsedPhone","parsePhoneNumberFromString","entry","DEFAULT_PHONE_INPUT_LABELS","LABELS_BY_LANGUAGE","getPrimaryLanguage","firstLocale","resolvePhoneInputLabels","overrides","language","localizedDefaults","normalizePhoneInput","cleanPhone","getCountryCode","formatPhone","AsYouType","unformatPhone","formattedPhone","validatePhoneLength","validateLength","validatePhone","customValidator","countryCode","isValidPhoneNumber","isPossiblePhoneNumber","addDialCode","removeDialCode","dialDigits","filterCountries","query","preferredCountries","lowerQuery","b","aPreferred","bPreferred","getCountryDisplayName","getPlaceholder","countDigitsBeforePosition","value","position","getCaretPositionFromDigitCount","digitCount","seenDigits","usePhoneInput","options","controlledValue","defaultValue","onChange","onBlur","onFocus","defaultCountry","excludeCountries","onlyCountries","autoDetect","formatOnType","includeDialCode","validator","labels","isControlled","inputRef","useRef","pendingCaretDigitIndexRef","availableCountries","useMemo","filtered","c","localizedCountries","resolvedLabels","initialCountry","candidate","internalPhone","setInternalPhone","useState","setCountry","isOpen","setIsOpen","searchQuery","setSearchQuery","useEffect","nextCountry","detected","fullPhone","isValid","localizedCountry","filteredCountries","getOutputCountry","useCallback","useLayoutEffect","nextDigitIndex","input","caretPosition","setPhone","newPhone","unformatted","setCountryByCode","newCountry","selectCountry","selectedCountry","rawCountry","toggleDropdown","prev","openDropdown","closeDropdown","clear","handleInputChange","event","rawValue","handleFocus","handleBlur","ChevronUpIcon","size","jsx","ChevronDownIcon","PhoneInput","forwardRef","props","ref","inputClassName","selectorClassName","containerClassName","searchable","placeholder","disabled","readOnly","name","id","ariaLabel","ariaLabelledBy","optionRefs","highlightedIndex","setHighlightedIndex","listboxId","useId","inputProps","countryButtonProps","hookInputRef","mergedInputRef","element","focus","blur","handleCountryClick","handleCountryKeyDown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AhB/CA,CAAAA,CAAE,IAiBT,CACD,CAAA,CACAmB,CAAAA,CAAkB,MAAA,GAAW,GAC5B2B,cAAAA,CAAC,IAAA,CAAA,CAAG,SAAA,CAAU,wBAAA,CAA0B,SAAAtD,CAAAA,CAAO,gBAAA,CAAiB,GAEpE,CAAA,CAAA,CACF,CAAA,CAAA,CAEJ,CAEJ,CACF","file":"index.cjs","sourcesContent":["import { getCountries, getCountryCallingCode, getExampleNumber, parsePhoneNumberFromString, type CountryCode } from 'libphonenumber-js';\r\nimport examples from 'libphonenumber-js/mobile/examples';\r\nimport worldCountries from 'world-countries';\r\n\r\nexport interface Country {\r\n code: string;\r\n name: string;\r\n dialCode: string;\r\n dialCodes: string[];\r\n flag: string;\r\n format?: string;\r\n displayName?: string;\r\n}\r\n\r\nconst PRIORITY_COUNTRIES = [\r\n 'US', 'GB', 'CA', 'AU', 'DE', 'FR', 'IT', 'ES', 'JP', 'CN', 'IN', 'BR', 'MX', 'KR', 'NL',\r\n 'CH', 'SE', 'AE', 'SG', 'ZA', 'NG', 'SA', 'TR', 'ID', 'PH', 'TH', 'VN', 'MY', 'NZ', 'AR'\r\n];\r\n\r\nconst supportedCountries = new Set(getCountries());\r\n\r\nfunction normalizeDialCode(root: string, suffix: string) {\r\n const normalizedRoot = root.startsWith('+') ? root : `+${root}`;\r\n const digitsOnlySuffix = suffix.replace(/\\D/g, '');\r\n return `${normalizedRoot}${digitsOnlySuffix}`;\r\n}\r\n\r\nfunction buildDialCodes(country: (typeof worldCountries)[number]) {\r\n const root = country.idd?.root;\r\n if (!root) {\r\n return [];\r\n }\r\n\r\n const suffixes = country.idd?.suffixes?.length ? country.idd.suffixes : [''];\r\n const dialCodes = suffixes\r\n .map((suffix) => normalizeDialCode(root, suffix))\r\n .filter((dialCode) => /^\\+\\d+$/.test(dialCode));\r\n\r\n return Array.from(new Set(dialCodes));\r\n}\r\n\r\nfunction getCountryFormat(code: CountryCode) {\r\n const example = getExampleNumber(code, examples);\r\n return example ? example.formatNational().replace(/\\d/g, '#') : undefined;\r\n}\r\n\r\nfunction getCountryPriority(code: string) {\r\n const index = PRIORITY_COUNTRIES.indexOf(code);\r\n return index === -1 ? Number.MAX_SAFE_INTEGER : index;\r\n}\r\n\r\nconst generatedCountries = worldCountries\r\n .filter((country) => supportedCountries.has(country.cca2 as CountryCode))\r\n .map<Country | null>((country) => {\r\n const code = country.cca2 as CountryCode;\r\n const dialCodes = buildDialCodes(country);\r\n const dialCode = `+${getCountryCallingCode(code)}`;\r\n\r\n if (!country.flag || dialCodes.length === 0) {\r\n return null;\r\n }\r\n\r\n return {\r\n code,\r\n name: country.name.common,\r\n dialCode,\r\n dialCodes,\r\n flag: country.flag,\r\n format: getCountryFormat(code),\r\n } satisfies Country;\r\n })\r\n .filter((country): country is Country => country !== null)\r\n .sort((left, right) => {\r\n const priorityDelta = getCountryPriority(left.code) - getCountryPriority(right.code);\r\n return priorityDelta !== 0 ? priorityDelta : left.name.localeCompare(right.name);\r\n });\r\n\r\nexport const countries: Country[] = generatedCountries;\r\n\r\nexport const countryMap = new Map(countries.map((country) => [country.code, country]));\r\n\r\nconst countriesByDialCode = countries.reduce((map, country) => {\r\n for (const dialCode of country.dialCodes) {\r\n const matches = map.get(dialCode) ?? [];\r\n matches.push(country);\r\n map.set(dialCode, matches);\r\n }\r\n\r\n return map;\r\n}, new Map<string, Country[]>());\r\n\r\nconst dialCodeMatchers = countries\r\n .flatMap((country) => country.dialCodes.map((dialCode) => ({ dialCode, country })))\r\n .sort((left, right) => right.dialCode.length - left.dialCode.length);\r\n\r\nconst displayNameCache = new Map<string, Intl.DisplayNames>();\r\n\r\nfunction normalizeLocales(locale?: string | readonly string[]) {\r\n return Array.isArray(locale) ? [...locale] : locale ? [locale] : [];\r\n}\r\n\r\nfunction getDisplayNames(locale?: string | readonly string[]) {\r\n const locales = normalizeLocales(locale);\r\n if (locales.length === 0 || typeof Intl === 'undefined' || typeof Intl.DisplayNames === 'undefined') {\r\n return undefined;\r\n }\r\n\r\n const cacheKey = locales.join('|');\r\n const cached = displayNameCache.get(cacheKey);\r\n if (cached) {\r\n return cached;\r\n }\r\n\r\n try {\r\n const displayNames = new Intl.DisplayNames(locales, { type: 'region' });\r\n displayNameCache.set(cacheKey, displayNames);\r\n return displayNames;\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n\r\nfunction normalizeLookupDialCode(dialCode: string) {\r\n const digits = dialCode.replace(/\\D/g, '');\r\n return digits ? `+${digits}` : '';\r\n}\r\n\r\nexport function getCountryByCode(code: string): Country | undefined {\r\n return countryMap.get(code.toUpperCase());\r\n}\r\n\r\nexport function getLocalizedCountryName(\r\n country: Country | undefined,\r\n locale?: string | readonly string[]\r\n): string | undefined {\r\n if (!country) {\r\n return undefined;\r\n }\r\n\r\n const displayNames = getDisplayNames(locale);\r\n return displayNames?.of(country.code) ?? country.displayName ?? country.name;\r\n}\r\n\r\nexport function localizeCountry(\r\n country: Country | undefined,\r\n locale?: string | readonly string[]\r\n): Country | undefined {\r\n if (!country) {\r\n return undefined;\r\n }\r\n\r\n const displayName = getLocalizedCountryName(country, locale);\r\n return displayName ? { ...country, displayName } : country;\r\n}\r\n\r\nexport function localizeCountries(\r\n list: Country[],\r\n locale?: string | readonly string[]\r\n): Country[] {\r\n if (!locale) {\r\n return list;\r\n }\r\n\r\n return list.map((country) => localizeCountry(country, locale) ?? country);\r\n}\r\n\r\nexport function getCountriesByDialCode(dialCode: string): Country[] {\r\n return countriesByDialCode.get(normalizeLookupDialCode(dialCode)) ?? [];\r\n}\r\n\r\nexport function getCountryByDialCode(dialCode: string): Country | undefined {\r\n return getCountriesByDialCode(dialCode)[0];\r\n}\r\n\r\nexport function detectCountryFromPhone(phone: string): Country | undefined {\r\n const trimmed = phone.trim();\r\n\r\n if (!trimmed) {\r\n return undefined;\r\n }\r\n\r\n const normalized = trimmed.startsWith('+')\r\n ? `+${trimmed.replace(/\\D/g, '')}`\r\n : trimmed.startsWith('00')\r\n ? `+${trimmed.slice(2).replace(/\\D/g, '')}`\r\n : '';\r\n\r\n if (!normalized) {\r\n return undefined;\r\n }\r\n\r\n const parsedPhone = parsePhoneNumberFromString(normalized);\r\n if (parsedPhone?.country) {\r\n return getCountryByCode(parsedPhone.country);\r\n }\r\n\r\n return dialCodeMatchers.find((entry) => normalized.startsWith(entry.dialCode))?.country;\r\n}\r\n","import type { PhoneInputLabels } from './types';\r\n\r\nexport const DEFAULT_PHONE_INPUT_LABELS: PhoneInputLabels = {\r\n selectCountry: 'Select country',\r\n countrySearchPlaceholder: 'Search countries...',\r\n noCountriesFound: 'No countries found',\r\n searchCountriesAriaLabel: 'Search countries',\r\n countryOptionsAriaLabel: 'Country options',\r\n countryButtonAriaLabel: 'Open country selector',\r\n};\r\n\r\nconst LABELS_BY_LANGUAGE: Record<string, Partial<PhoneInputLabels>> = {\r\n en: DEFAULT_PHONE_INPUT_LABELS,\r\n fr: {\r\n selectCountry: 'Choisir un pays',\r\n countrySearchPlaceholder: 'Rechercher un pays...',\r\n noCountriesFound: 'Aucun pays trouvé',\r\n searchCountriesAriaLabel: 'Rechercher des pays',\r\n countryOptionsAriaLabel: 'Options de pays',\r\n countryButtonAriaLabel: 'Ouvrir le sélecteur de pays',\r\n },\r\n de: {\r\n selectCountry: 'Land auswählen',\r\n countrySearchPlaceholder: 'Land suchen...',\r\n noCountriesFound: 'Keine Länder gefunden',\r\n searchCountriesAriaLabel: 'Länder suchen',\r\n countryOptionsAriaLabel: 'Länderoptionen',\r\n countryButtonAriaLabel: 'Länderauswahl öffnen',\r\n },\r\n es: {\r\n selectCountry: 'Seleccionar país',\r\n countrySearchPlaceholder: 'Buscar país...',\r\n noCountriesFound: 'No se encontraron países',\r\n searchCountriesAriaLabel: 'Buscar países',\r\n countryOptionsAriaLabel: 'Opciones de país',\r\n countryButtonAriaLabel: 'Abrir selector de país',\r\n },\r\n pt: {\r\n selectCountry: 'Selecionar país',\r\n countrySearchPlaceholder: 'Pesquisar país...',\r\n noCountriesFound: 'Nenhum país encontrado',\r\n searchCountriesAriaLabel: 'Pesquisar países',\r\n countryOptionsAriaLabel: 'Opções de país',\r\n countryButtonAriaLabel: 'Abrir seletor de país',\r\n },\r\n it: {\r\n selectCountry: 'Seleziona paese',\r\n countrySearchPlaceholder: 'Cerca paese...',\r\n noCountriesFound: 'Nessun paese trovato',\r\n searchCountriesAriaLabel: 'Cerca paesi',\r\n countryOptionsAriaLabel: 'Opzioni paese',\r\n countryButtonAriaLabel: 'Apri selettore paese',\r\n },\r\n ja: {\r\n selectCountry: '国を選択',\r\n countrySearchPlaceholder: '国を検索...',\r\n noCountriesFound: '国が見つかりません',\r\n searchCountriesAriaLabel: '国を検索',\r\n countryOptionsAriaLabel: '国の候補',\r\n countryButtonAriaLabel: '国のセレクターを開く',\r\n },\r\n ko: {\r\n selectCountry: '국가 선택',\r\n countrySearchPlaceholder: '국가 검색...',\r\n noCountriesFound: '국가를 찾을 수 없습니다',\r\n searchCountriesAriaLabel: '국가 검색',\r\n countryOptionsAriaLabel: '국가 옵션',\r\n countryButtonAriaLabel: '국가 선택기 열기',\r\n },\r\n zh: {\r\n selectCountry: '选择国家',\r\n countrySearchPlaceholder: '搜索国家...',\r\n noCountriesFound: '未找到国家',\r\n searchCountriesAriaLabel: '搜索国家',\r\n countryOptionsAriaLabel: '国家选项',\r\n countryButtonAriaLabel: '打开国家选择器',\r\n },\r\n ar: {\r\n selectCountry: 'اختر الدولة',\r\n countrySearchPlaceholder: 'ابحث عن دولة...',\r\n noCountriesFound: 'لم يتم العثور على دول',\r\n searchCountriesAriaLabel: 'ابحث عن الدول',\r\n countryOptionsAriaLabel: 'خيارات الدول',\r\n countryButtonAriaLabel: 'افتح محدد الدولة',\r\n },\r\n hi: {\r\n selectCountry: 'देश चुनें',\r\n countrySearchPlaceholder: 'देश खोजें...',\r\n noCountriesFound: 'कोई देश नहीं मिला',\r\n searchCountriesAriaLabel: 'देश खोजें',\r\n countryOptionsAriaLabel: 'देश विकल्प',\r\n countryButtonAriaLabel: 'देश चयन खोलें',\r\n },\r\n};\r\n\r\nfunction getPrimaryLanguage(locale?: string | readonly string[]): string | undefined {\r\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : [];\r\n const firstLocale = locales.find(Boolean);\r\n return firstLocale ? firstLocale.toLowerCase().split('-')[0] : undefined;\r\n}\r\n\r\nexport function resolvePhoneInputLabels(\r\n locale?: string | readonly string[],\r\n overrides?: Partial<PhoneInputLabels>\r\n): PhoneInputLabels {\r\n const language = getPrimaryLanguage(locale);\r\n const localizedDefaults = language ? LABELS_BY_LANGUAGE[language] : undefined;\r\n\r\n return {\r\n ...DEFAULT_PHONE_INPUT_LABELS,\r\n ...localizedDefaults,\r\n ...overrides,\r\n };\r\n}","import type { Country } from './countries';\r\nimport { AsYouType, isPossiblePhoneNumber, isValidPhoneNumber, validatePhoneNumberLength as validateLength, type CountryCode } from 'libphonenumber-js';\r\n\r\nfunction normalizePhoneInput(phone: string): string {\r\n const trimmed = phone.trim();\r\n const digits = cleanPhone(trimmed);\r\n\r\n if (trimmed.startsWith('+') && !digits) {\r\n return '+';\r\n }\r\n\r\n if (!digits) {\r\n return '';\r\n }\r\n\r\n return trimmed.startsWith('+') ? `+${digits}` : digits;\r\n}\r\n\r\nfunction getCountryCode(country: Country | undefined): CountryCode | undefined {\r\n return country?.code as CountryCode | undefined;\r\n}\r\n\r\n/**\r\n * Remove all non-digit characters from phone number\r\n */\r\nexport function cleanPhone(phone: string): string {\r\n return phone.replace(/\\D/g, '');\r\n}\r\n\r\n/**\r\n * Format phone number according to country format\r\n */\r\nexport function formatPhone(phone: string, country: Country | undefined): string {\r\n if (!phone) return phone;\r\n\r\n const formatter = new AsYouType(getCountryCode(country));\r\n return formatter.input(normalizePhoneInput(phone));\r\n}\r\n\r\n/**\r\n * Get raw phone number without formatting\r\n */\r\nexport function unformatPhone(formattedPhone: string): string {\r\n return normalizePhoneInput(formattedPhone);\r\n}\r\n\r\n/**\r\n * Validate phone number length based on country\r\n */\r\nexport function validatePhoneLength(phone: string, country: Country | undefined): boolean {\r\n if (!phone || !country) return false;\r\n\r\n if (phone.trim().startsWith('+')) {\r\n return validateLength(normalizePhoneInput(phone)) === undefined;\r\n }\r\n\r\n return validateLength(cleanPhone(phone), getCountryCode(country)) === undefined;\r\n}\r\n\r\n/**\r\n * Validate phone number format\r\n */\r\nexport function validatePhone(\r\n phone: string,\r\n country: Country | undefined,\r\n customValidator?: (phone: string, country: Country | undefined) => boolean\r\n): boolean {\r\n if (!phone) return false;\r\n \r\n if (customValidator) {\r\n return customValidator(phone, country);\r\n }\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const countryCode = getCountryCode(country);\r\n\r\n if (!countryCode) {\r\n return isPossiblePhoneNumber(normalized.startsWith('+') ? normalized : `+${cleanPhone(normalized)}`);\r\n }\r\n\r\n if (normalized.startsWith('+')) {\r\n return isValidPhoneNumber(normalized);\r\n }\r\n\r\n return isValidPhoneNumber(cleanPhone(normalized), countryCode);\r\n}\r\n\r\n/**\r\n * Add dial code to phone number\r\n */\r\nexport function addDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n if (!normalized) return '';\r\n if (normalized === '+') return '';\r\n if (normalized.startsWith('+')) return normalized;\r\n\r\n const digits = cleanPhone(normalized);\r\n const matchingDialCode = country.dialCodes.find((dialCode) => digits.startsWith(dialCode.replace('+', '')));\r\n return matchingDialCode ? `+${digits}` : `${country.dialCode}${digits}`;\r\n}\r\n\r\n/**\r\n * Remove dial code from phone number\r\n */\r\nexport function removeDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const digits = cleanPhone(normalized);\r\n\r\n for (const dialCode of country.dialCodes) {\r\n const dialDigits = dialCode.replace('+', '');\r\n if (digits.startsWith(dialDigits)) {\r\n return digits.slice(dialDigits.length);\r\n }\r\n }\r\n\r\n return digits;\r\n}\r\n\r\n/**\r\n * Filter countries by search query\r\n */\r\nexport function filterCountries(\r\n countries: Country[],\r\n query: string,\r\n preferredCountries?: string[]\r\n): Country[] {\r\n const lowerQuery = query.toLowerCase().trim();\r\n \r\n if (!lowerQuery) {\r\n // Sort by preferred countries first\r\n if (preferredCountries?.length) {\r\n return [...countries].sort((a, b) => {\r\n const aPreferred = preferredCountries.indexOf(a.code);\r\n const bPreferred = preferredCountries.indexOf(b.code);\r\n if (aPreferred !== -1 && bPreferred !== -1) return aPreferred - bPreferred;\r\n if (aPreferred !== -1) return -1;\r\n if (bPreferred !== -1) return 1;\r\n return (a.displayName ?? a.name).localeCompare(b.displayName ?? b.name);\r\n });\r\n }\r\n return countries;\r\n }\r\n \r\n return countries.filter(\r\n country =>\r\n country.name.toLowerCase().includes(lowerQuery) ||\r\n (country.displayName ?? '').toLowerCase().includes(lowerQuery) ||\r\n country.code.toLowerCase().includes(lowerQuery) ||\r\n country.dialCodes.some((dialCode) => dialCode.includes(lowerQuery))\r\n );\r\n}\r\n\r\nexport function getCountryDisplayName(country: Country | undefined): string {\r\n return country?.displayName ?? country?.name ?? '';\r\n}\r\n\r\n/**\r\n * Get placeholder based on country format\r\n */\r\nexport function getPlaceholder(country: Country | undefined): string {\r\n if (!country?.format) return country?.dialCode ? `${country.dialCode} 000 000 0000` : 'Phone number';\r\n return country.format.replace(/#/g, '0');\r\n}\r\n","import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\r\nimport type { PhoneInputOptions, UsePhoneInputReturn } from './types';\r\nimport type { Country } from './countries';\r\nimport { countries, detectCountryFromPhone, getCountryByCode, localizeCountries, localizeCountry } from './countries';\r\nimport { resolvePhoneInputLabels } from './labels';\r\nimport {\r\n formatPhone,\r\n unformatPhone,\r\n validatePhone,\r\n addDialCode,\r\n removeDialCode,\r\n filterCountries,\r\n getPlaceholder,\r\n} from './utils';\r\n\r\nfunction countDigitsBeforePosition(value: string, position: number) {\r\n return value.slice(0, position).replace(/\\D/g, '').length;\r\n}\r\n\r\nfunction getCaretPositionFromDigitCount(value: string, digitCount: number) {\r\n if (digitCount <= 0) {\r\n return value.startsWith('+') ? 1 : 0;\r\n }\r\n\r\n let seenDigits = 0;\r\n\r\n for (let index = 0; index < value.length; index += 1) {\r\n if (/\\d/.test(value[index])) {\r\n seenDigits += 1;\r\n if (seenDigits === digitCount) {\r\n return index + 1;\r\n }\r\n }\r\n }\r\n\r\n return value.length;\r\n}\r\n\r\nexport function usePhoneInput(\r\n options: PhoneInputOptions & {\r\n value?: string;\r\n defaultValue?: string;\r\n onChange?: (phone: string, country: Country | undefined) => void;\r\n onBlur?: () => void;\r\n onFocus?: () => void;\r\n } = {}\r\n): UsePhoneInputReturn {\r\n const {\r\n value: controlledValue,\r\n defaultValue = '',\r\n onChange,\r\n onBlur,\r\n onFocus,\r\n defaultCountry = 'US',\r\n preferredCountries,\r\n excludeCountries,\r\n onlyCountries,\r\n autoDetect = true,\r\n formatOnType = true,\r\n includeDialCode = false,\r\n validator,\r\n locale,\r\n labels,\r\n } = options;\r\n\r\n const isControlled = controlledValue !== undefined;\r\n const inputRef = useRef<HTMLInputElement>(null);\r\n const pendingCaretDigitIndexRef = useRef<number | null>(null);\r\n\r\n // Filter available countries\r\n const availableCountries = useMemo(() => {\r\n let filtered = countries;\r\n \r\n if (onlyCountries?.length) {\r\n filtered = filtered.filter(c => onlyCountries.includes(c.code));\r\n }\r\n \r\n if (excludeCountries?.length) {\r\n filtered = filtered.filter(c => !excludeCountries.includes(c.code));\r\n }\r\n \r\n return filtered;\r\n }, [onlyCountries, excludeCountries]);\r\n\r\n const localizedCountries = useMemo(\r\n () => localizeCountries(availableCountries, locale),\r\n [availableCountries, locale]\r\n );\r\n\r\n const resolvedLabels = useMemo(\r\n () => resolvePhoneInputLabels(locale, labels),\r\n [locale, labels]\r\n );\r\n\r\n // Initialize state\r\n const initialCountry = availableCountries.find((candidate) => candidate.code === defaultCountry) || availableCountries[0];\r\n const [internalPhone, setInternalPhone] = useState(defaultValue);\r\n const [country, setCountry] = useState<Country | undefined>(initialCountry);\r\n const [isOpen, setIsOpen] = useState(false);\r\n const [searchQuery, setSearchQuery] = useState('');\r\n\r\n // Current phone value\r\n const phone = isControlled ? controlledValue : internalPhone;\r\n\r\n useEffect(() => {\r\n const nextCountry = availableCountries.find((candidate) => candidate.code === defaultCountry) || availableCountries[0];\r\n if (nextCountry && nextCountry.code !== country?.code) {\r\n setCountry(nextCountry);\r\n }\r\n }, [defaultCountry, availableCountries, country?.code]);\r\n\r\n // Auto-detect country from phone\r\n useEffect(() => {\r\n if (autoDetect && phone) {\r\n const detected = detectCountryFromPhone(phone);\r\n if (detected && availableCountries.some((candidate) => candidate.code === detected.code) && detected.code !== country?.code) {\r\n setCountry(detected);\r\n }\r\n }\r\n }, [availableCountries, autoDetect, phone, country?.code]);\r\n\r\n // Format phone number\r\n const formattedPhone = useMemo(() => {\r\n if (formatOnType) {\r\n return formatPhone(includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone, country);\r\n }\r\n return includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone;\r\n }, [formatOnType, includeDialCode, phone, country]);\r\n\r\n // Full phone with dial code\r\n const fullPhone = useMemo(() => {\r\n if (includeDialCode && country) {\r\n return addDialCode(phone, country);\r\n }\r\n return phone;\r\n }, [phone, country, includeDialCode]);\r\n\r\n // Validation\r\n const isValid = useMemo(\r\n () => validatePhone(phone, country, validator),\r\n [phone, country, validator]\r\n );\r\n\r\n const localizedCountry = useMemo(\r\n () => localizeCountry(country, locale),\r\n [country, locale]\r\n );\r\n\r\n // Filtered countries for dropdown\r\n const filteredCountries = useMemo(\r\n () => filterCountries(localizedCountries, searchQuery, preferredCountries),\r\n [localizedCountries, searchQuery, preferredCountries]\r\n );\r\n\r\n const getOutputCountry = useCallback(\r\n (nextCountry: Country | undefined) => localizeCountry(nextCountry, locale),\r\n [locale]\r\n );\r\n\r\n useLayoutEffect(() => {\r\n const nextDigitIndex = pendingCaretDigitIndexRef.current;\r\n const input = inputRef.current;\r\n\r\n if (nextDigitIndex === null || !input || typeof input.setSelectionRange !== 'function') {\r\n return;\r\n }\r\n\r\n if (typeof document !== 'undefined' && document.activeElement !== input) {\r\n return;\r\n }\r\n\r\n const caretPosition = getCaretPositionFromDigitCount(formattedPhone, nextDigitIndex);\r\n input.setSelectionRange(caretPosition, caretPosition);\r\n pendingCaretDigitIndexRef.current = null;\r\n }, [formattedPhone]);\r\n\r\n // Set phone handler\r\n const setPhone = useCallback(\r\n (newPhone: string) => {\r\n const unformatted = unformatPhone(newPhone);\r\n if (!isControlled) {\r\n setInternalPhone(unformatted);\r\n }\r\n onChange?.(\r\n includeDialCode ? addDialCode(unformatted, country) : unformatted,\r\n getOutputCountry(country)\r\n );\r\n },\r\n [isControlled, onChange, country, includeDialCode, getOutputCountry]\r\n );\r\n\r\n // Set country handler\r\n const setCountryByCode = useCallback(\r\n (code: string) => {\r\n const newCountry = getCountryByCode(code);\r\n if (newCountry) {\r\n setCountry(newCountry);\r\n onChange?.(\r\n includeDialCode ? addDialCode(phone, newCountry) : phone,\r\n getOutputCountry(newCountry)\r\n );\r\n }\r\n },\r\n [phone, onChange, includeDialCode, getOutputCountry]\r\n );\r\n\r\n // Select country from dropdown\r\n const selectCountry = useCallback(\r\n (selectedCountry: Country) => {\r\n const rawCountry = getCountryByCode(selectedCountry.code) ?? selectedCountry;\r\n setCountry(rawCountry);\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n onChange?.(\r\n includeDialCode ? addDialCode(phone, rawCountry) : phone,\r\n getOutputCountry(rawCountry)\r\n );\r\n },\r\n [phone, onChange, includeDialCode, getOutputCountry]\r\n );\r\n\r\n // Toggle dropdown\r\n const toggleDropdown = useCallback(() => {\r\n setIsOpen(prev => !prev);\r\n if (isOpen) {\r\n setSearchQuery('');\r\n }\r\n }, [isOpen]);\r\n\r\n // Open dropdown\r\n const openDropdown = useCallback(() => {\r\n setIsOpen(true);\r\n }, []);\r\n\r\n // Close dropdown\r\n const closeDropdown = useCallback(() => {\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n }, []);\r\n\r\n // Clear input\r\n const clear = useCallback(() => {\r\n if (!isControlled) {\r\n setInternalPhone('');\r\n }\r\n onChange?.('', getOutputCountry(country));\r\n }, [isControlled, onChange, country, getOutputCountry]);\r\n\r\n // Handle input change\r\n const handleInputChange = useCallback(\r\n (event: React.ChangeEvent<HTMLInputElement>) => {\r\n const rawValue = event.target.value;\r\n const caretPosition = event.target.selectionStart ?? rawValue.length;\r\n const unformatted = rawValue.trim().startsWith('+') ? `+${rawValue.replace(/\\D/g, '')}` : unformatPhone(rawValue);\r\n pendingCaretDigitIndexRef.current = countDigitsBeforePosition(rawValue, caretPosition);\r\n setPhone(unformatted);\r\n },\r\n [setPhone]\r\n );\r\n\r\n // Handle focus\r\n const handleFocus = useCallback(() => {\r\n onFocus?.();\r\n }, [onFocus]);\r\n\r\n // Handle blur\r\n const handleBlur = useCallback(() => {\r\n onBlur?.();\r\n }, [onBlur]);\r\n\r\n return {\r\n // State\r\n phone,\r\n fullPhone,\r\n country: localizedCountry,\r\n isValid,\r\n isOpen,\r\n searchQuery,\r\n labels: resolvedLabels,\r\n // Actions\r\n setPhone,\r\n setCountry: setCountryByCode,\r\n toggleDropdown,\r\n openDropdown,\r\n closeDropdown,\r\n setSearchQuery,\r\n clear,\r\n // Props\r\n inputProps: {\r\n ref: inputRef,\r\n value: formattedPhone,\r\n onChange: handleInputChange,\r\n onFocus: handleFocus,\r\n onBlur: handleBlur,\r\n type: 'tel',\r\n inputMode: 'tel',\r\n autoComplete: 'tel',\r\n placeholder: getPlaceholder(country),\r\n 'aria-invalid': phone ? !isValid : undefined,\r\n },\r\n countryButtonProps: {\r\n onClick: toggleDropdown,\r\n 'aria-expanded': isOpen,\r\n 'aria-haspopup': 'listbox',\r\n 'aria-label': resolvedLabels.countryButtonAriaLabel,\r\n },\r\n filteredCountries,\r\n selectCountry,\r\n };\r\n}\r\n","import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useRef, useState, type MutableRefObject, type Ref } from 'react';\nimport { usePhoneInput } from './usePhoneInput';\nimport type { PhoneInputProps } from './types';\nimport type { Country } from './countries';\nimport { getCountryDisplayName } from './utils';\n\n// SVG Icon Components (Lucide-style)\nconst ChevronUpIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"18 15 12 9 6 15\" />\n </svg>\n);\n\nconst ChevronDownIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"6 9 12 15 18 9\" />\n </svg>\n);\n\nexport interface PhoneInputRef {\n /** Focus the input */\n focus: () => void;\n /** Blur the input */\n blur: () => void;\n /** Clear the input */\n clear: () => void;\n /** Set country */\n setCountry: (countryCode: string) => void;\n /** Get current country */\n getCountry: () => Country | undefined;\n /** Open country selector */\n open: () => void;\n /** Close country selector */\n close: () => void;\n}\n\n/**\n * PhoneInput component - headless phone input with country selection\n * \n * @example\n * ```tsx\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"US\"\n * />\n * ```\n * \n * @example\n * ```tsx\n * // With custom styling\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"GB\"\n * containerClassName=\"phone-input-container\"\n * inputClassName=\"phone-input\"\n * selectorClassName=\"country-selector\"\n * />\n * ```\n */\nexport const PhoneInput = forwardRef<PhoneInputRef, PhoneInputProps>(\n function PhoneInput(props, ref) {\n const {\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n inputClassName,\n selectorClassName,\n containerClassName,\n searchable = true,\n placeholder,\n disabled,\n readOnly,\n name,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n ...options\n } = props;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const optionRefs = useRef<Array<HTMLLIElement | null>>([]);\n const [highlightedIndex, setHighlightedIndex] = useState(0);\n const listboxId = useId();\n\n const {\n inputProps,\n countryButtonProps,\n country,\n filteredCountries,\n isOpen,\n isValid,\n searchQuery,\n setSearchQuery,\n setCountry,\n selectCountry,\n clear,\n openDropdown,\n closeDropdown,\n labels,\n } = usePhoneInput({\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n ...options,\n });\n\n const hookInputRef = (inputProps as typeof inputProps & { ref?: Ref<HTMLInputElement> }).ref;\n const mergedInputRef = useCallback((element: HTMLInputElement | null) => {\n inputRef.current = element;\n\n if (typeof hookInputRef === 'function') {\n hookInputRef(element);\n } else if (hookInputRef && 'current' in hookInputRef) {\n (hookInputRef as MutableRefObject<HTMLInputElement | null>).current = element;\n }\n }, [hookInputRef]);\n\n // Focus the input\n const focus = useCallback(() => {\n inputRef.current?.focus();\n }, []);\n\n // Blur the input\n const blur = useCallback(() => {\n inputRef.current?.blur();\n }, []);\n\n // Handle country option click\n const handleCountryClick = useCallback((c: Country) => {\n selectCountry(c);\n setHighlightedIndex(0);\n }, [selectCountry]);\n\n // Handle country option keyboard navigation\n const handleCountryKeyDown = useCallback((e: React.KeyboardEvent, c: Country, index: number) => {\n switch (e.key) {\n case 'Enter':\n case ' ':\n e.preventDefault();\n selectCountry(c);\n setHighlightedIndex(0);\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (index < filteredCountries.length - 1) {\n const nextIndex = index + 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n if (index > 0) {\n const nextIndex = index - 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'Escape':\n e.preventDefault();\n closeDropdown();\n break;\n }\n }, [selectCountry, filteredCountries.length, closeDropdown]);\n\n useEffect(() => {\n if (filteredCountries.length === 0) {\n if (highlightedIndex !== 0) {\n setHighlightedIndex(0);\n }\n return;\n }\n\n if (highlightedIndex >= filteredCountries.length) {\n setHighlightedIndex(filteredCountries.length - 1);\n }\n }, [filteredCountries.length, highlightedIndex]);\n\n // Expose imperative methods\n useImperativeHandle(ref, () => ({\n focus,\n blur,\n clear,\n setCountry,\n getCountry: () => country,\n open: openDropdown,\n close: closeDropdown,\n }));\n\n // Render default UI\n return (\n <div className={containerClassName} data-valid={isValid}>\n {/* Country Selector Button */}\n <button\n {...countryButtonProps}\n type=\"button\"\n className={selectorClassName}\n disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n aria-controls={listboxId}\n >\n {country ? (\n <>\n <span className=\"phone-input-flag\">{country.flag}</span>\n <span className=\"phone-input-dial-code\">{country.dialCode}</span>\n </>\n ) : (\n <span className=\"phone-input-placeholder\">{labels.selectCountry}</span>\n )}\n <span className=\"phone-input-arrow\" aria-hidden=\"true\">\n {isOpen ? <ChevronUpIcon size={12} /> : <ChevronDownIcon size={12} />}\n </span>\n </button>\n\n {/* Phone Input */}\n <input\n {...inputProps}\n ref={mergedInputRef}\n id={id}\n name={name}\n className={inputClassName}\n placeholder={placeholder || inputProps.placeholder}\n disabled={disabled}\n readOnly={readOnly}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n />\n\n {/* Country Dropdown */}\n {isOpen && (\n <div className=\"phone-input-dropdown\">\n {/* Search Input */}\n {searchable && (\n <div className=\"phone-input-search\">\n <input\n type=\"text\"\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n placeholder={labels.countrySearchPlaceholder}\n autoFocus\n aria-controls={listboxId}\n aria-label={labels.searchCountriesAriaLabel}\n />\n </div>\n )}\n\n {/* Country List */}\n <ul className=\"phone-input-country-list\" id={listboxId} role=\"listbox\" aria-label={labels.countryOptionsAriaLabel}>\n {filteredCountries.map((c, index) => (\n <li\n key={c.code}\n ref={(element) => {\n optionRefs.current[index] = element;\n }}\n role=\"option\"\n aria-selected={c.code === country?.code}\n className={`phone-input-country-option ${\n c.code === country?.code ? 'selected' : ''\n } ${index === highlightedIndex ? 'highlighted' : ''}`}\n onClick={() => handleCountryClick(c)}\n onKeyDown={(e) => handleCountryKeyDown(e, c, index)}\n onMouseEnter={() => setHighlightedIndex(index)}\n tabIndex={index === highlightedIndex ? 0 : -1}\n >\n <span className=\"phone-input-flag\">{c.flag}</span>\n <span className=\"phone-input-country-name\">{getCountryDisplayName(c)}</span>\n <span className=\"phone-input-dial-code\">{c.dialCode}</span>\n </li>\n ))}\n {filteredCountries.length === 0 && (\n <li className=\"phone-input-no-results\">{labels.noCountriesFound}</li>\n )}\n </ul>\n </div>\n )}\n </div>\n );\n }\n);\n\nexport default PhoneInput;\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { InputHTMLAttributes } from 'react';
|
|
2
|
+
import { InputHTMLAttributes, RefObject } from 'react';
|
|
3
3
|
|
|
4
4
|
interface Country {
|
|
5
5
|
code: string;
|
|
@@ -8,13 +8,25 @@ interface Country {
|
|
|
8
8
|
dialCodes: string[];
|
|
9
9
|
flag: string;
|
|
10
10
|
format?: string;
|
|
11
|
+
displayName?: string;
|
|
11
12
|
}
|
|
12
13
|
declare const countries: Country[];
|
|
13
14
|
declare function getCountryByCode(code: string): Country | undefined;
|
|
15
|
+
declare function getLocalizedCountryName(country: Country | undefined, locale?: string | readonly string[]): string | undefined;
|
|
16
|
+
declare function localizeCountry(country: Country | undefined, locale?: string | readonly string[]): Country | undefined;
|
|
17
|
+
declare function localizeCountries(list: Country[], locale?: string | readonly string[]): Country[];
|
|
14
18
|
declare function getCountriesByDialCode(dialCode: string): Country[];
|
|
15
19
|
declare function getCountryByDialCode(dialCode: string): Country | undefined;
|
|
16
20
|
declare function detectCountryFromPhone(phone: string): Country | undefined;
|
|
17
21
|
|
|
22
|
+
interface PhoneInputLabels {
|
|
23
|
+
selectCountry: string;
|
|
24
|
+
countrySearchPlaceholder: string;
|
|
25
|
+
noCountriesFound: string;
|
|
26
|
+
searchCountriesAriaLabel: string;
|
|
27
|
+
countryOptionsAriaLabel: string;
|
|
28
|
+
countryButtonAriaLabel: string;
|
|
29
|
+
}
|
|
18
30
|
interface PhoneInputOptions {
|
|
19
31
|
defaultCountry?: string;
|
|
20
32
|
preferredCountries?: string[];
|
|
@@ -25,6 +37,8 @@ interface PhoneInputOptions {
|
|
|
25
37
|
formatOnType?: boolean;
|
|
26
38
|
includeDialCode?: boolean;
|
|
27
39
|
validator?: (phone: string, country: Country | undefined) => boolean;
|
|
40
|
+
locale?: string | readonly string[];
|
|
41
|
+
labels?: Partial<PhoneInputLabels>;
|
|
28
42
|
}
|
|
29
43
|
interface PhoneInputState {
|
|
30
44
|
phone: string;
|
|
@@ -33,6 +47,7 @@ interface PhoneInputState {
|
|
|
33
47
|
isValid: boolean;
|
|
34
48
|
isOpen: boolean;
|
|
35
49
|
searchQuery: string;
|
|
50
|
+
labels: PhoneInputLabels;
|
|
36
51
|
}
|
|
37
52
|
interface PhoneInputActions {
|
|
38
53
|
setPhone: (phone: string) => void;
|
|
@@ -44,11 +59,14 @@ interface PhoneInputActions {
|
|
|
44
59
|
clear: () => void;
|
|
45
60
|
}
|
|
46
61
|
interface UsePhoneInputReturn extends PhoneInputState, PhoneInputActions {
|
|
47
|
-
inputProps: InputHTMLAttributes<HTMLInputElement
|
|
62
|
+
inputProps: InputHTMLAttributes<HTMLInputElement> & {
|
|
63
|
+
ref: RefObject<HTMLInputElement | null>;
|
|
64
|
+
};
|
|
48
65
|
countryButtonProps: {
|
|
49
66
|
onClick: () => void;
|
|
50
67
|
'aria-expanded': boolean;
|
|
51
68
|
'aria-haspopup': 'listbox';
|
|
69
|
+
'aria-label': string;
|
|
52
70
|
};
|
|
53
71
|
filteredCountries: Country[];
|
|
54
72
|
selectCountry: (country: Country) => void;
|
|
@@ -62,6 +80,7 @@ interface PhoneInputProps extends PhoneInputOptions {
|
|
|
62
80
|
containerClassName?: string;
|
|
63
81
|
inputClassName?: string;
|
|
64
82
|
selectorClassName?: string;
|
|
83
|
+
searchable?: boolean;
|
|
65
84
|
placeholder?: string;
|
|
66
85
|
disabled?: boolean;
|
|
67
86
|
readOnly?: boolean;
|
|
@@ -90,6 +109,9 @@ interface PhoneInputRef {
|
|
|
90
109
|
}
|
|
91
110
|
declare const PhoneInput: react.ForwardRefExoticComponent<PhoneInputProps & react.RefAttributes<PhoneInputRef>>;
|
|
92
111
|
|
|
112
|
+
declare const DEFAULT_PHONE_INPUT_LABELS: PhoneInputLabels;
|
|
113
|
+
declare function resolvePhoneInputLabels(locale?: string | readonly string[], overrides?: Partial<PhoneInputLabels>): PhoneInputLabels;
|
|
114
|
+
|
|
93
115
|
declare function cleanPhone(phone: string): string;
|
|
94
116
|
declare function formatPhone(phone: string, country: Country | undefined): string;
|
|
95
117
|
declare function unformatPhone(formattedPhone: string): string;
|
|
@@ -98,6 +120,7 @@ declare function validatePhone(phone: string, country: Country | undefined, cust
|
|
|
98
120
|
declare function addDialCode(phone: string, country: Country | undefined): string;
|
|
99
121
|
declare function removeDialCode(phone: string, country: Country | undefined): string;
|
|
100
122
|
declare function filterCountries(countries: Country[], query: string, preferredCountries?: string[]): Country[];
|
|
123
|
+
declare function getCountryDisplayName(country: Country | undefined): string;
|
|
101
124
|
declare function getPlaceholder(country: Country | undefined): string;
|
|
102
125
|
|
|
103
|
-
export { type Country, PhoneInput, type PhoneInputActions, type PhoneInputOptions, type PhoneInputProps, type PhoneInputRef, type PhoneInputState, type UsePhoneInputReturn, addDialCode, cleanPhone, countries, detectCountryFromPhone, filterCountries, formatPhone, getCountriesByDialCode, getCountryByCode, getCountryByDialCode, getPlaceholder, removeDialCode, unformatPhone, usePhoneInput, validatePhone, validatePhoneLength };
|
|
126
|
+
export { type Country, DEFAULT_PHONE_INPUT_LABELS, PhoneInput, type PhoneInputActions, type PhoneInputLabels, type PhoneInputOptions, type PhoneInputProps, type PhoneInputRef, type PhoneInputState, type UsePhoneInputReturn, addDialCode, cleanPhone, countries, detectCountryFromPhone, filterCountries, formatPhone, getCountriesByDialCode, getCountryByCode, getCountryByDialCode, getCountryDisplayName, getLocalizedCountryName, getPlaceholder, localizeCountries, localizeCountry, removeDialCode, resolvePhoneInputLabels, unformatPhone, usePhoneInput, validatePhone, validatePhoneLength };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { InputHTMLAttributes } from 'react';
|
|
2
|
+
import { InputHTMLAttributes, RefObject } from 'react';
|
|
3
3
|
|
|
4
4
|
interface Country {
|
|
5
5
|
code: string;
|
|
@@ -8,13 +8,25 @@ interface Country {
|
|
|
8
8
|
dialCodes: string[];
|
|
9
9
|
flag: string;
|
|
10
10
|
format?: string;
|
|
11
|
+
displayName?: string;
|
|
11
12
|
}
|
|
12
13
|
declare const countries: Country[];
|
|
13
14
|
declare function getCountryByCode(code: string): Country | undefined;
|
|
15
|
+
declare function getLocalizedCountryName(country: Country | undefined, locale?: string | readonly string[]): string | undefined;
|
|
16
|
+
declare function localizeCountry(country: Country | undefined, locale?: string | readonly string[]): Country | undefined;
|
|
17
|
+
declare function localizeCountries(list: Country[], locale?: string | readonly string[]): Country[];
|
|
14
18
|
declare function getCountriesByDialCode(dialCode: string): Country[];
|
|
15
19
|
declare function getCountryByDialCode(dialCode: string): Country | undefined;
|
|
16
20
|
declare function detectCountryFromPhone(phone: string): Country | undefined;
|
|
17
21
|
|
|
22
|
+
interface PhoneInputLabels {
|
|
23
|
+
selectCountry: string;
|
|
24
|
+
countrySearchPlaceholder: string;
|
|
25
|
+
noCountriesFound: string;
|
|
26
|
+
searchCountriesAriaLabel: string;
|
|
27
|
+
countryOptionsAriaLabel: string;
|
|
28
|
+
countryButtonAriaLabel: string;
|
|
29
|
+
}
|
|
18
30
|
interface PhoneInputOptions {
|
|
19
31
|
defaultCountry?: string;
|
|
20
32
|
preferredCountries?: string[];
|
|
@@ -25,6 +37,8 @@ interface PhoneInputOptions {
|
|
|
25
37
|
formatOnType?: boolean;
|
|
26
38
|
includeDialCode?: boolean;
|
|
27
39
|
validator?: (phone: string, country: Country | undefined) => boolean;
|
|
40
|
+
locale?: string | readonly string[];
|
|
41
|
+
labels?: Partial<PhoneInputLabels>;
|
|
28
42
|
}
|
|
29
43
|
interface PhoneInputState {
|
|
30
44
|
phone: string;
|
|
@@ -33,6 +47,7 @@ interface PhoneInputState {
|
|
|
33
47
|
isValid: boolean;
|
|
34
48
|
isOpen: boolean;
|
|
35
49
|
searchQuery: string;
|
|
50
|
+
labels: PhoneInputLabels;
|
|
36
51
|
}
|
|
37
52
|
interface PhoneInputActions {
|
|
38
53
|
setPhone: (phone: string) => void;
|
|
@@ -44,11 +59,14 @@ interface PhoneInputActions {
|
|
|
44
59
|
clear: () => void;
|
|
45
60
|
}
|
|
46
61
|
interface UsePhoneInputReturn extends PhoneInputState, PhoneInputActions {
|
|
47
|
-
inputProps: InputHTMLAttributes<HTMLInputElement
|
|
62
|
+
inputProps: InputHTMLAttributes<HTMLInputElement> & {
|
|
63
|
+
ref: RefObject<HTMLInputElement | null>;
|
|
64
|
+
};
|
|
48
65
|
countryButtonProps: {
|
|
49
66
|
onClick: () => void;
|
|
50
67
|
'aria-expanded': boolean;
|
|
51
68
|
'aria-haspopup': 'listbox';
|
|
69
|
+
'aria-label': string;
|
|
52
70
|
};
|
|
53
71
|
filteredCountries: Country[];
|
|
54
72
|
selectCountry: (country: Country) => void;
|
|
@@ -62,6 +80,7 @@ interface PhoneInputProps extends PhoneInputOptions {
|
|
|
62
80
|
containerClassName?: string;
|
|
63
81
|
inputClassName?: string;
|
|
64
82
|
selectorClassName?: string;
|
|
83
|
+
searchable?: boolean;
|
|
65
84
|
placeholder?: string;
|
|
66
85
|
disabled?: boolean;
|
|
67
86
|
readOnly?: boolean;
|
|
@@ -90,6 +109,9 @@ interface PhoneInputRef {
|
|
|
90
109
|
}
|
|
91
110
|
declare const PhoneInput: react.ForwardRefExoticComponent<PhoneInputProps & react.RefAttributes<PhoneInputRef>>;
|
|
92
111
|
|
|
112
|
+
declare const DEFAULT_PHONE_INPUT_LABELS: PhoneInputLabels;
|
|
113
|
+
declare function resolvePhoneInputLabels(locale?: string | readonly string[], overrides?: Partial<PhoneInputLabels>): PhoneInputLabels;
|
|
114
|
+
|
|
93
115
|
declare function cleanPhone(phone: string): string;
|
|
94
116
|
declare function formatPhone(phone: string, country: Country | undefined): string;
|
|
95
117
|
declare function unformatPhone(formattedPhone: string): string;
|
|
@@ -98,6 +120,7 @@ declare function validatePhone(phone: string, country: Country | undefined, cust
|
|
|
98
120
|
declare function addDialCode(phone: string, country: Country | undefined): string;
|
|
99
121
|
declare function removeDialCode(phone: string, country: Country | undefined): string;
|
|
100
122
|
declare function filterCountries(countries: Country[], query: string, preferredCountries?: string[]): Country[];
|
|
123
|
+
declare function getCountryDisplayName(country: Country | undefined): string;
|
|
101
124
|
declare function getPlaceholder(country: Country | undefined): string;
|
|
102
125
|
|
|
103
|
-
export { type Country, PhoneInput, type PhoneInputActions, type PhoneInputOptions, type PhoneInputProps, type PhoneInputRef, type PhoneInputState, type UsePhoneInputReturn, addDialCode, cleanPhone, countries, detectCountryFromPhone, filterCountries, formatPhone, getCountriesByDialCode, getCountryByCode, getCountryByDialCode, getPlaceholder, removeDialCode, unformatPhone, usePhoneInput, validatePhone, validatePhoneLength };
|
|
126
|
+
export { type Country, DEFAULT_PHONE_INPUT_LABELS, PhoneInput, type PhoneInputActions, type PhoneInputLabels, type PhoneInputOptions, type PhoneInputProps, type PhoneInputRef, type PhoneInputState, type UsePhoneInputReturn, addDialCode, cleanPhone, countries, detectCountryFromPhone, filterCountries, formatPhone, getCountriesByDialCode, getCountryByCode, getCountryByDialCode, getCountryDisplayName, getLocalizedCountryName, getPlaceholder, localizeCountries, localizeCountry, removeDialCode, resolvePhoneInputLabels, unformatPhone, usePhoneInput, validatePhone, validatePhoneLength };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {forwardRef,useRef,useState,useId,useCallback,useEffect,useImperativeHandle,useMemo}from'react';import {getCountries,getCountryCallingCode,getExampleNumber,parsePhoneNumberFromString,AsYouType,isValidPhoneNumber,isPossiblePhoneNumber,validatePhoneNumberLength}from'libphonenumber-js';import be from'libphonenumber-js/mobile/examples';import xe from'world-countries';import {jsxs,Fragment,jsx}from'react/jsx-runtime';var Ie=["US","GB","CA","AU","DE","FR","IT","ES","JP","CN","IN","BR","MX","KR","NL","CH","SE","AE","SG","ZA","NG","SA","TR","ID","PH","TH","VN","MY","NZ","AR"],De=new Set(getCountries());function Ne(e,t){let o=e.startsWith("+")?e:`+${e}`,n=t.replace(/\D/g,"");return `${o}${n}`}function we(e){let t=e.idd?.root;if(!t)return [];let n=(e.idd?.suffixes?.length?e.idd.suffixes:[""]).map(u=>Ne(t,u)).filter(u=>/^\+\d+$/.test(u));return Array.from(new Set(n))}function Re(e){let t=getExampleNumber(e,be);return t?t.formatNational().replace(/\d/g,"#"):void 0}function ce(e){let t=Ie.indexOf(e);return t===-1?Number.MAX_SAFE_INTEGER:t}var Be=xe.filter(e=>De.has(e.cca2)).map(e=>{let t=e.cca2,o=we(e),n=`+${getCountryCallingCode(t)}`;return !e.flag||o.length===0?null:{code:t,name:e.name.common,dialCode:n,dialCodes:o,flag:e.flag,format:Re(t)}}).filter(e=>e!==null).sort((e,t)=>{let o=ce(e.code)-ce(t.code);return o!==0?o:e.name.localeCompare(t.name)}),B=Be,ke=new Map(B.map(e=>[e.code,e])),Se=B.reduce((e,t)=>{for(let o of t.dialCodes){let n=e.get(o)??[];n.push(t),e.set(o,n);}return e},new Map),Ee=B.flatMap(e=>e.dialCodes.map(t=>({dialCode:t,country:e}))).sort((e,t)=>t.dialCode.length-e.dialCode.length);function Le(e){let t=e.replace(/\D/g,"");return t?`+${t}`:""}function k(e){return ke.get(e.toUpperCase())}function pe(e){return Se.get(Le(e))??[]}function $e(e){return pe(e)[0]}function re(e){let t=e.trim();if(!t)return;let o=t.startsWith("+")?`+${t.replace(/\D/g,"")}`:t.startsWith("00")?`+${t.slice(2).replace(/\D/g,"")}`:"";if(!o)return;let n=parsePhoneNumberFromString(o);return n?.country?k(n.country):Ee.find(u=>o.startsWith(u.dialCode))?.country}function S(e){let t=e.trim(),o=R(t);return o?t.startsWith("+")?`+${o}`:o:""}function ie(e){return e?.code}function R(e){return e.replace(/\D/g,"")}function se(e,t){return e&&new AsYouType(ie(t)).input(S(e))}function Q(e){return S(e)}function Ae(e,t){return !e||!t?false:e.trim().startsWith("+")?validatePhoneNumberLength(S(e))===void 0:validatePhoneNumberLength(R(e),ie(t))===void 0}function ae(e,t,o){if(!e)return false;if(o)return o(e,t);let n=S(e),u=ie(t);return u?n.startsWith("+")?isValidPhoneNumber(n):isValidPhoneNumber(R(n),u):isPossiblePhoneNumber(n.startsWith("+")?n:`+${R(n)}`)}function E(e,t){if(!t)return e;let o=S(e);if(!o)return "";if(o.startsWith("+"))return o;let n=R(o);return t.dialCodes.find(c=>n.startsWith(c.replace("+","")))?`+${n}`:`${t.dialCode}${n}`}function G(e,t){if(!t)return e;let o=S(e),n=R(o);for(let u of t.dialCodes){let c=u.replace("+","");if(n.startsWith(c))return n.slice(c.length)}return n}function ue(e,t,o){let n=t.toLowerCase().trim();return n?e.filter(u=>u.name.toLowerCase().includes(n)||u.code.toLowerCase().includes(n)||u.dialCodes.some(c=>c.includes(n))):o?.length?[...e].sort((u,c)=>{let m=o.indexOf(u.code),P=o.indexOf(c.code);return m!==-1&&P!==-1?m-P:m!==-1?-1:P!==-1?1:u.name.localeCompare(c.name)}):e}function le(e){return e?.format?e.format.replace(/#/g,"0"):e?.dialCode?`${e.dialCode} 000 000 0000`:"Phone number"}function de(e={}){let{value:t,defaultValue:o="",onChange:n,onBlur:u,onFocus:c,defaultCountry:m="US",preferredCountries:P,excludeCountries:$,onlyCountries:W,autoDetect:z=true,formatOnType:U=true,includeDialCode:d=false,validator:H}=e,I=t!==void 0,g=useMemo(()=>{let i=B;return W?.length&&(i=i.filter(r=>W.includes(r.code))),$?.length&&(i=i.filter(r=>!$.includes(r.code))),i},[W,$]),_=k(m)||g[0],[X,V]=useState(o),[a,v]=useState(_),[f,p]=useState(false),[D,N]=useState(""),s=I?t:X;useEffect(()=>{let i=k(m)||g[0];i&&i.code!==a?.code&&v(i);},[m,g,a?.code]),useEffect(()=>{if(z&&s){let i=re(s);i&&g.some(r=>r.code===i.code)&&i.code!==a?.code&&v(i);}},[g,z,s,a?.code]);let b=useMemo(()=>U?se(d&&s.startsWith("+")?G(s,a):s,a):d&&s.startsWith("+")?G(s,a):s,[U,d,s,a]),C=useMemo(()=>d&&a?E(s,a):s,[s,a,d]),O=useMemo(()=>ae(s,a,H),[s,a,H]),Z=useMemo(()=>ue(g,D,P),[g,D,P]),A=useCallback(i=>{let r=Q(i);I||V(r),n?.(d?E(r,a):r,a);},[I,n,a,d]),j=useCallback(i=>{let r=k(i);r&&(v(r),n?.(d?E(s,r):s,r));},[s,n,d]),J=useCallback(i=>{v(i),p(false),N(""),n?.(d?E(s,i):s,i);},[s,n,d]),w=useCallback(()=>{p(i=>!i),f&&N("");},[f]),q=useCallback(()=>{p(true);},[]),ee=useCallback(()=>{p(false),N("");},[]),M=useCallback(()=>{I||V(""),n?.("",a);},[I,n,a]),te=useCallback(i=>{let r=i.target.value,y=r.trim().startsWith("+")?`+${r.replace(/\D/g,"")}`:Q(r);A(y);},[A]),ne=useCallback(()=>{c?.();},[c]),oe=useCallback(()=>{u?.();},[u]);return {phone:s,fullPhone:C,country:a,isValid:O,isOpen:f,searchQuery:D,setPhone:A,setCountry:j,toggleDropdown:w,openDropdown:q,closeDropdown:ee,setSearchQuery:N,clear:M,inputProps:{value:b,onChange:te,onFocus:ne,onBlur:oe,type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:le(a),"aria-invalid":s?!O:void 0},countryButtonProps:{onClick:w,"aria-expanded":f,"aria-haspopup":"listbox"},filteredCountries:Z,selectCountry:J}}var He=({size:e=12})=>jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"18 15 12 9 6 15"})}),Ve=({size:e=12})=>jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"6 9 12 15 18 9"})}),Qe=forwardRef(function(t,o){let{value:n,defaultValue:u,onChange:c,onBlur:m,onFocus:P,inputClassName:$,selectorClassName:W,containerClassName:z,placeholder:U,disabled:d,readOnly:H,name:I,id:g,"aria-label":_,"aria-labelledby":X,...V}=t,a=useRef(null),v=useRef([]),[f,p]=useState(0),D=useId(),{inputProps:N,countryButtonProps:s,country:b,filteredCountries:C,isOpen:O,isValid:Z,searchQuery:A,setSearchQuery:j,setCountry:J,selectCountry:w,clear:q,openDropdown:ee,closeDropdown:M}=de({value:n,defaultValue:u,onChange:c,onBlur:m,onFocus:P,...V}),te=useCallback(()=>{a.current?.focus();},[]),ne=useCallback(()=>{a.current?.blur();},[]),oe=useCallback(r=>{w(r),p(0);},[w]),i=useCallback((r,y,x)=>{switch(r.key){case "Enter":case " ":r.preventDefault(),w(y),p(0);break;case "ArrowDown":if(r.preventDefault(),x<C.length-1){let F=x+1;p(F),v.current[F]?.focus();}break;case "ArrowUp":if(r.preventDefault(),x>0){let F=x-1;p(F),v.current[F]?.focus();}break;case "Escape":r.preventDefault(),M();break}},[w,C.length,M]);return useEffect(()=>{if(C.length===0){f!==0&&p(0);return}f>=C.length&&p(C.length-1);},[C.length,f]),useImperativeHandle(o,()=>({focus:te,blur:ne,clear:q,setCountry:J,getCountry:()=>b,open:ee,close:M})),jsxs("div",{className:z,"data-valid":Z,children:[jsxs("button",{...s,type:"button",className:W,disabled:d,tabIndex:d?-1:0,"aria-controls":D,children:[b?jsxs(Fragment,{children:[jsx("span",{className:"phone-input-flag",children:b.flag}),jsx("span",{className:"phone-input-dial-code",children:b.dialCode})]}):jsx("span",{className:"phone-input-placeholder",children:"Select"}),jsx("span",{className:"phone-input-arrow","aria-hidden":"true",children:O?jsx(He,{size:12}):jsx(Ve,{size:12})})]}),jsx("input",{...N,ref:a,id:g,name:I,className:$,placeholder:U||N.placeholder,disabled:d,readOnly:H,"aria-label":_,"aria-labelledby":X}),O&&jsxs("div",{className:"phone-input-dropdown",children:[jsx("div",{className:"phone-input-search",children:jsx("input",{type:"text",value:A,onChange:r=>j(r.target.value),placeholder:"Search countries...",autoFocus:true,"aria-controls":D,"aria-label":"Search countries"})}),jsxs("ul",{className:"phone-input-country-list",id:D,role:"listbox","aria-label":"Country options",children:[C.map((r,y)=>jsxs("li",{ref:x=>{v.current[y]=x;},role:"option","aria-selected":r.code===b?.code,className:`phone-input-country-option ${r.code===b?.code?"selected":""} ${y===f?"highlighted":""}`,onClick:()=>oe(r),onKeyDown:x=>i(x,r,y),onMouseEnter:()=>p(y),tabIndex:y===f?0:-1,children:[jsx("span",{className:"phone-input-flag",children:r.flag}),jsx("span",{className:"phone-input-country-name",children:r.name}),jsx("span",{className:"phone-input-dial-code",children:r.dialCode})]},r.code)),C.length===0&&jsx("li",{className:"phone-input-no-results",children:"No countries found"})]})]})]})});export{Qe as PhoneInput,E as addDialCode,R as cleanPhone,B as countries,re as detectCountryFromPhone,ue as filterCountries,se as formatPhone,pe as getCountriesByDialCode,k as getCountryByCode,$e as getCountryByDialCode,le as getPlaceholder,G as removeDialCode,Q as unformatPhone,de as usePhoneInput,ae as validatePhone,Ae as validatePhoneLength};//# sourceMappingURL=index.js.map
|
|
1
|
+
import {forwardRef,useRef,useState,useId,useCallback,useEffect,useImperativeHandle,useMemo,useLayoutEffect}from'react';import {getCountries,getCountryCallingCode,getExampleNumber,parsePhoneNumberFromString,AsYouType,isValidPhoneNumber,isPossiblePhoneNumber,validatePhoneNumberLength}from'libphonenumber-js';import ke from'libphonenumber-js/mobile/examples';import Me from'world-countries';import {jsxs,Fragment,jsx}from'react/jsx-runtime';var Te=["US","GB","CA","AU","DE","FR","IT","ES","JP","CN","IN","BR","MX","KR","NL","CH","SE","AE","SG","ZA","NG","SA","TR","ID","PH","TH","VN","MY","NZ","AR"],We=new Set(getCountries());function $e(e,n){let t=e.startsWith("+")?e:`+${e}`,o=n.replace(/\D/g,"");return `${t}${o}`}function Ue(e){let n=e.idd?.root;if(!n)return [];let o=(e.idd?.suffixes?.length?e.idd.suffixes:[""]).map(a=>$e(n,a)).filter(a=>/^\+\d+$/.test(a));return Array.from(new Set(o))}function He(e){let n=getExampleNumber(e,ke);return n?n.formatNational().replace(/\d/g,"#"):void 0}function Ie(e){let n=Te.indexOf(e);return n===-1?Number.MAX_SAFE_INTEGER:n}var _e=Me.filter(e=>We.has(e.cca2)).map(e=>{let n=e.cca2,t=Ue(e),o=`+${getCountryCallingCode(n)}`;return !e.flag||t.length===0?null:{code:n,name:e.name.common,dialCode:o,dialCodes:t,flag:e.flag,format:He(n)}}).filter(e=>e!==null).sort((e,n)=>{let t=Ie(e.code)-Ie(n.code);return t!==0?t:e.name.localeCompare(n.name)}),T=_e,Ve=new Map(T.map(e=>[e.code,e])),Ge=T.reduce((e,n)=>{for(let t of n.dialCodes){let o=e.get(t)??[];o.push(n),e.set(t,o);}return e},new Map),Ke=T.flatMap(e=>e.dialCodes.map(n=>({dialCode:n,country:e}))).sort((e,n)=>n.dialCode.length-e.dialCode.length),Ae=new Map;function je(e){return Array.isArray(e)?[...e]:e?[e]:[]}function Qe(e){let n=je(e);if(n.length===0||typeof Intl>"u"||typeof Intl.DisplayNames>"u")return;let t=n.join("|"),o=Ae.get(t);if(o)return o;try{let a=new Intl.DisplayNames(n,{type:"region"});return Ae.set(t,a),a}catch{return}}function Ye(e){let n=e.replace(/\D/g,"");return n?`+${n}`:""}function K(e){return Ve.get(e.toUpperCase())}function Ne(e,n){return e?Qe(n)?.of(e.code)??e.displayName??e.name:void 0}function j(e,n){if(!e)return;let t=Ne(e,n);return t?{...e,displayName:t}:e}function de(e,n){return n?e.map(t=>j(t,n)??t):e}function xe(e){return Ge.get(Ye(e))??[]}function qe(e){return xe(e)[0]}function pe(e){let n=e.trim();if(!n)return;let t=n.startsWith("+")?`+${n.replace(/\D/g,"")}`:n.startsWith("00")?`+${n.slice(2).replace(/\D/g,"")}`:"";if(!t)return;let o=parsePhoneNumberFromString(t);return o?.country?K(o.country):Ke.find(a=>t.startsWith(a.dialCode))?.country}var fe={selectCountry:"Select country",countrySearchPlaceholder:"Search countries...",noCountriesFound:"No countries found",searchCountriesAriaLabel:"Search countries",countryOptionsAriaLabel:"Country options",countryButtonAriaLabel:"Open country selector"},Xe={en:fe,fr:{selectCountry:"Choisir un pays",countrySearchPlaceholder:"Rechercher un pays...",noCountriesFound:"Aucun pays trouv\xE9",searchCountriesAriaLabel:"Rechercher des pays",countryOptionsAriaLabel:"Options de pays",countryButtonAriaLabel:"Ouvrir le s\xE9lecteur de pays"},de:{selectCountry:"Land ausw\xE4hlen",countrySearchPlaceholder:"Land suchen...",noCountriesFound:"Keine L\xE4nder gefunden",searchCountriesAriaLabel:"L\xE4nder suchen",countryOptionsAriaLabel:"L\xE4nderoptionen",countryButtonAriaLabel:"L\xE4nderauswahl \xF6ffnen"},es:{selectCountry:"Seleccionar pa\xEDs",countrySearchPlaceholder:"Buscar pa\xEDs...",noCountriesFound:"No se encontraron pa\xEDses",searchCountriesAriaLabel:"Buscar pa\xEDses",countryOptionsAriaLabel:"Opciones de pa\xEDs",countryButtonAriaLabel:"Abrir selector de pa\xEDs"},pt:{selectCountry:"Selecionar pa\xEDs",countrySearchPlaceholder:"Pesquisar pa\xEDs...",noCountriesFound:"Nenhum pa\xEDs encontrado",searchCountriesAriaLabel:"Pesquisar pa\xEDses",countryOptionsAriaLabel:"Op\xE7\xF5es de pa\xEDs",countryButtonAriaLabel:"Abrir seletor de pa\xEDs"},it:{selectCountry:"Seleziona paese",countrySearchPlaceholder:"Cerca paese...",noCountriesFound:"Nessun paese trovato",searchCountriesAriaLabel:"Cerca paesi",countryOptionsAriaLabel:"Opzioni paese",countryButtonAriaLabel:"Apri selettore paese"},ja:{selectCountry:"\u56FD\u3092\u9078\u629E",countrySearchPlaceholder:"\u56FD\u3092\u691C\u7D22...",noCountriesFound:"\u56FD\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",searchCountriesAriaLabel:"\u56FD\u3092\u691C\u7D22",countryOptionsAriaLabel:"\u56FD\u306E\u5019\u88DC",countryButtonAriaLabel:"\u56FD\u306E\u30BB\u30EC\u30AF\u30BF\u30FC\u3092\u958B\u304F"},ko:{selectCountry:"\uAD6D\uAC00 \uC120\uD0DD",countrySearchPlaceholder:"\uAD6D\uAC00 \uAC80\uC0C9...",noCountriesFound:"\uAD6D\uAC00\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",searchCountriesAriaLabel:"\uAD6D\uAC00 \uAC80\uC0C9",countryOptionsAriaLabel:"\uAD6D\uAC00 \uC635\uC158",countryButtonAriaLabel:"\uAD6D\uAC00 \uC120\uD0DD\uAE30 \uC5F4\uAE30"},zh:{selectCountry:"\u9009\u62E9\u56FD\u5BB6",countrySearchPlaceholder:"\u641C\u7D22\u56FD\u5BB6...",noCountriesFound:"\u672A\u627E\u5230\u56FD\u5BB6",searchCountriesAriaLabel:"\u641C\u7D22\u56FD\u5BB6",countryOptionsAriaLabel:"\u56FD\u5BB6\u9009\u9879",countryButtonAriaLabel:"\u6253\u5F00\u56FD\u5BB6\u9009\u62E9\u5668"},ar:{selectCountry:"\u0627\u062E\u062A\u0631 \u0627\u0644\u062F\u0648\u0644\u0629",countrySearchPlaceholder:"\u0627\u0628\u062D\u062B \u0639\u0646 \u062F\u0648\u0644\u0629...",noCountriesFound:"\u0644\u0645 \u064A\u062A\u0645 \u0627\u0644\u0639\u062B\u0648\u0631 \u0639\u0644\u0649 \u062F\u0648\u0644",searchCountriesAriaLabel:"\u0627\u0628\u062D\u062B \u0639\u0646 \u0627\u0644\u062F\u0648\u0644",countryOptionsAriaLabel:"\u062E\u064A\u0627\u0631\u0627\u062A \u0627\u0644\u062F\u0648\u0644",countryButtonAriaLabel:"\u0627\u0641\u062A\u062D \u0645\u062D\u062F\u062F \u0627\u0644\u062F\u0648\u0644\u0629"},hi:{selectCountry:"\u0926\u0947\u0936 \u091A\u0941\u0928\u0947\u0902",countrySearchPlaceholder:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902...",noCountriesFound:"\u0915\u094B\u0908 \u0926\u0947\u0936 \u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E",searchCountriesAriaLabel:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902",countryOptionsAriaLabel:"\u0926\u0947\u0936 \u0935\u093F\u0915\u0932\u094D\u092A",countryButtonAriaLabel:"\u0926\u0947\u0936 \u091A\u092F\u0928 \u0916\u094B\u0932\u0947\u0902"}};function Ze(e){let t=(Array.isArray(e)?e:e?[e]:[]).find(Boolean);return t?t.toLowerCase().split("-")[0]:void 0}function Ce(e,n){let t=Ze(e),o=t?Xe[t]:void 0;return {...fe,...o,...n}}function W(e){let n=e.trim(),t=w(n);return n.startsWith("+")&&!t?"+":t?n.startsWith("+")?`+${t}`:t:""}function ye(e){return e?.code}function w(e){return e.replace(/\D/g,"")}function he(e,n){return e&&new AsYouType(ye(n)).input(W(e))}function ne(e){return W(e)}function nn(e,n){return !e||!n?false:e.trim().startsWith("+")?validatePhoneNumberLength(W(e))===void 0:validatePhoneNumberLength(w(e),ye(n))===void 0}function ge(e,n,t){if(!e)return false;if(t)return t(e,n);let o=W(e),a=ye(n);return a?o.startsWith("+")?isValidPhoneNumber(o):isValidPhoneNumber(w(o),a):isPossiblePhoneNumber(o.startsWith("+")?o:`+${w(o)}`)}function $(e,n){if(!n)return e;let t=W(e);if(!t||t==="+")return "";if(t.startsWith("+"))return t;let o=w(t);return n.dialCodes.find(d=>o.startsWith(d.replace("+","")))?`+${o}`:`${n.dialCode}${o}`}function te(e,n){if(!n)return e;let t=W(e),o=w(t);for(let a of n.dialCodes){let d=a.replace("+","");if(o.startsWith(d))return o.slice(d.length)}return o}function me(e,n,t){let o=n.toLowerCase().trim();return o?e.filter(a=>a.name.toLowerCase().includes(o)||(a.displayName??"").toLowerCase().includes(o)||a.code.toLowerCase().includes(o)||a.dialCodes.some(d=>d.includes(o))):t?.length?[...e].sort((a,d)=>{let P=t.indexOf(a.code),N=t.indexOf(d.code);return P!==-1&&N!==-1?P-N:P!==-1?-1:N!==-1?1:(a.displayName??a.name).localeCompare(d.displayName??d.name)}):e}function be(e){return e?.displayName??e?.name??""}function Pe(e){return e?.format?e.format.replace(/#/g,"0"):e?.dialCode?`${e.dialCode} 000 000 0000`:"Phone number"}function on(e,n){return e.slice(0,n).replace(/\D/g,"").length}function rn(e,n){if(n<=0)return e.startsWith("+")?1:0;let t=0;for(let o=0;o<e.length;o+=1)if(/\d/.test(e[o])&&(t+=1,t===n))return o+1;return e.length}function Le(e={}){let{value:n,defaultValue:t="",onChange:o,onBlur:a,onFocus:d,defaultCountry:P="US",preferredCountries:N,excludeCountries:H,onlyCountries:_,autoDetect:Y=true,formatOnType:q=true,includeDialCode:p=false,validator:O,locale:m,labels:X}=e,v=n!==void 0,Z=useRef(null),V=useRef(null),y=useMemo(()=>{let r=T;return _?.length&&(r=r.filter(i=>_.includes(i.code))),H?.length&&(r=r.filter(i=>!H.includes(i.code))),r},[_,H]),R=useMemo(()=>de(y,m),[y,m]),E=useMemo(()=>Ce(m,X),[m,X]),B=y.find(r=>r.code===P)||y[0],[L,F]=useState(t),[s,z]=useState(B),[h,f]=useState(false),[k,M]=useState(""),u=v?n:L;useEffect(()=>{let r=y.find(i=>i.code===P)||y[0];r&&r.code!==s?.code&&z(r);},[P,y,s?.code]),useEffect(()=>{if(Y&&u){let r=pe(u);r&&y.some(i=>i.code===r.code)&&r.code!==s?.code&&z(r);}},[y,Y,u,s?.code]);let G=useMemo(()=>q?he(p&&u.startsWith("+")?te(u,s):u,s):p&&u.startsWith("+")?te(u,s):u,[q,p,u,s]),re=useMemo(()=>p&&s?$(u,s):u,[u,s,p]),S=useMemo(()=>ge(u,s,O),[u,s,O]),ie=useMemo(()=>j(s,m),[s,m]),ae=useMemo(()=>me(R,k,N),[R,k,N]),C=useCallback(r=>j(r,m),[m]);useLayoutEffect(()=>{let r=V.current,i=Z.current;if(r===null||!i||typeof i.setSelectionRange!="function"||typeof document<"u"&&document.activeElement!==i)return;let ee=rn(G,r);i.setSelectionRange(ee,ee),V.current=null;},[G]);let I=useCallback(r=>{let i=ne(r);v||F(i),o?.(p?$(i,s):i,C(s));},[v,o,s,p,C]),x=useCallback(r=>{let i=K(r);i&&(z(i),o?.(p?$(u,i):u,C(i)));},[u,o,p,C]),se=useCallback(r=>{let i=K(r.code)??r;z(i),f(false),M(""),o?.(p?$(u,i):u,C(i));},[u,o,p,C]),J=useCallback(()=>{f(r=>!r),h&&M("");},[h]),ue=useCallback(()=>{f(true);},[]),le=useCallback(()=>{f(false),M("");},[]),ce=useCallback(()=>{v||F(""),o?.("",C(s));},[v,o,s,C]),l=useCallback(r=>{let i=r.target.value,ee=r.target.selectionStart??i.length,Oe=i.trim().startsWith("+")?`+${i.replace(/\D/g,"")}`:ne(i);V.current=on(i,ee),I(Oe);},[I]),A=useCallback(()=>{d?.();},[d]),b=useCallback(()=>{a?.();},[a]);return {phone:u,fullPhone:re,country:ie,isValid:S,isOpen:h,searchQuery:k,labels:E,setPhone:I,setCountry:x,toggleDropdown:J,openDropdown:ue,closeDropdown:le,setSearchQuery:M,clear:ce,inputProps:{ref:Z,value:G,onChange:l,onFocus:A,onBlur:b,type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:Pe(s),"aria-invalid":u?!S:void 0},countryButtonProps:{onClick:J,"aria-expanded":h,"aria-haspopup":"listbox","aria-label":E.countryButtonAriaLabel},filteredCountries:ae,selectCountry:se}}var dn=({size:e=12})=>jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"18 15 12 9 6 15"})}),pn=({size:e=12})=>jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polyline",{points:"6 9 12 15 18 9"})}),fn=forwardRef(function(n,t){let{value:o,defaultValue:a,onChange:d,onBlur:P,onFocus:N,inputClassName:H,selectorClassName:_,containerClassName:Y,searchable:q=true,placeholder:p,disabled:O,readOnly:m,name:X,id:v,"aria-label":Z,"aria-labelledby":V,...y}=n,R=useRef(null),E=useRef([]),[B,L]=useState(0),F=useId(),{inputProps:s,countryButtonProps:z,country:h,filteredCountries:f,isOpen:k,isValid:M,searchQuery:u,setSearchQuery:G,setCountry:re,selectCountry:S,clear:ie,openDropdown:ae,closeDropdown:C,labels:I}=Le({value:o,defaultValue:a,onChange:d,onBlur:P,onFocus:N,...y}),x=s.ref,se=useCallback(l=>{R.current=l,typeof x=="function"?x(l):x&&"current"in x&&(x.current=l);},[x]),J=useCallback(()=>{R.current?.focus();},[]),ue=useCallback(()=>{R.current?.blur();},[]),le=useCallback(l=>{S(l),L(0);},[S]),ce=useCallback((l,A,b)=>{switch(l.key){case "Enter":case " ":l.preventDefault(),S(A),L(0);break;case "ArrowDown":if(l.preventDefault(),b<f.length-1){let r=b+1;L(r),E.current[r]?.focus();}break;case "ArrowUp":if(l.preventDefault(),b>0){let r=b-1;L(r),E.current[r]?.focus();}break;case "Escape":l.preventDefault(),C();break}},[S,f.length,C]);return useEffect(()=>{if(f.length===0){B!==0&&L(0);return}B>=f.length&&L(f.length-1);},[f.length,B]),useImperativeHandle(t,()=>({focus:J,blur:ue,clear:ie,setCountry:re,getCountry:()=>h,open:ae,close:C})),jsxs("div",{className:Y,"data-valid":M,children:[jsxs("button",{...z,type:"button",className:_,disabled:O,tabIndex:O?-1:0,"aria-controls":F,children:[h?jsxs(Fragment,{children:[jsx("span",{className:"phone-input-flag",children:h.flag}),jsx("span",{className:"phone-input-dial-code",children:h.dialCode})]}):jsx("span",{className:"phone-input-placeholder",children:I.selectCountry}),jsx("span",{className:"phone-input-arrow","aria-hidden":"true",children:k?jsx(dn,{size:12}):jsx(pn,{size:12})})]}),jsx("input",{...s,ref:se,id:v,name:X,className:H,placeholder:p||s.placeholder,disabled:O,readOnly:m,"aria-label":Z,"aria-labelledby":V}),k&&jsxs("div",{className:"phone-input-dropdown",children:[q&&jsx("div",{className:"phone-input-search",children:jsx("input",{type:"text",value:u,onChange:l=>G(l.target.value),placeholder:I.countrySearchPlaceholder,autoFocus:true,"aria-controls":F,"aria-label":I.searchCountriesAriaLabel})}),jsxs("ul",{className:"phone-input-country-list",id:F,role:"listbox","aria-label":I.countryOptionsAriaLabel,children:[f.map((l,A)=>jsxs("li",{ref:b=>{E.current[A]=b;},role:"option","aria-selected":l.code===h?.code,className:`phone-input-country-option ${l.code===h?.code?"selected":""} ${A===B?"highlighted":""}`,onClick:()=>le(l),onKeyDown:b=>ce(b,l,A),onMouseEnter:()=>L(A),tabIndex:A===B?0:-1,children:[jsx("span",{className:"phone-input-flag",children:l.flag}),jsx("span",{className:"phone-input-country-name",children:be(l)}),jsx("span",{className:"phone-input-dial-code",children:l.dialCode})]},l.code)),f.length===0&&jsx("li",{className:"phone-input-no-results",children:I.noCountriesFound})]})]})]})});export{fe as DEFAULT_PHONE_INPUT_LABELS,fn as PhoneInput,$ as addDialCode,w as cleanPhone,T as countries,pe as detectCountryFromPhone,me as filterCountries,he as formatPhone,xe as getCountriesByDialCode,K as getCountryByCode,qe as getCountryByDialCode,be as getCountryDisplayName,Ne as getLocalizedCountryName,Pe as getPlaceholder,de as localizeCountries,j as localizeCountry,te as removeDialCode,Ce as resolvePhoneInputLabels,ne as unformatPhone,Le as usePhoneInput,ge as validatePhone,nn as validatePhoneLength};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countries.ts","../src/utils.ts","../src/usePhoneInput.ts","../src/PhoneInput.tsx"],"names":["PRIORITY_COUNTRIES","supportedCountries","getCountries","normalizeDialCode","root","suffix","normalizedRoot","digitsOnlySuffix","buildDialCodes","country","dialCodes","dialCode","getCountryFormat","code","example","getExampleNumber","examples","getCountryPriority","index","generatedCountries","worldCountries","getCountryCallingCode","left","right","priorityDelta","countries","countryMap","countriesByDialCode","map","matches","dialCodeMatchers","normalizeLookupDialCode","digits","getCountryByCode","getCountriesByDialCode","getCountryByDialCode","detectCountryFromPhone","phone","trimmed","normalized","parsedPhone","parsePhoneNumberFromString","entry","normalizePhoneInput","cleanPhone","getCountryCode","formatPhone","AsYouType","unformatPhone","formattedPhone","validatePhoneLength","validateLength","validatePhone","customValidator","countryCode","isValidPhoneNumber","isPossiblePhoneNumber","addDialCode","removeDialCode","dialDigits","filterCountries","query","preferredCountries","lowerQuery","a","b","aPreferred","bPreferred","getPlaceholder","usePhoneInput","options","controlledValue","defaultValue","onChange","onBlur","onFocus","defaultCountry","excludeCountries","onlyCountries","autoDetect","formatOnType","includeDialCode","validator","isControlled","availableCountries","useMemo","filtered","c","initialCountry","internalPhone","setInternalPhone","useState","setCountry","isOpen","setIsOpen","searchQuery","setSearchQuery","useEffect","nextCountry","detected","candidate","fullPhone","isValid","filteredCountries","setPhone","useCallback","newPhone","unformatted","setCountryByCode","newCountry","selectCountry","selectedCountry","toggleDropdown","prev","openDropdown","closeDropdown","clear","handleInputChange","event","rawValue","handleFocus","handleBlur","ChevronUpIcon","size","jsx","ChevronDownIcon","PhoneInput","forwardRef","props","ref","value","inputClassName","selectorClassName","containerClassName","placeholder","disabled","readOnly","name","id","ariaLabel","ariaLabelledBy","inputRef","useRef","optionRefs","highlightedIndex","setHighlightedIndex","listboxId","useId","inputProps","countryButtonProps","focus","blur","handleCountryClick","handleCountryKeyDown","e","nextIndex","useIm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AhB/CA,CAAAA,CAAE,IAiBT,CACD,CAAA,CACAgB,CAAAA,CAAkB,MAAA,GAAW,CAAA,EAC5BqB,GAAAA,CAAC,IAAA,CAAA,CAAG,SAAA,CAAU,wBAAA,CAAyB,QAAA,CAAA,oBAAA,CAAkB,CAAA,CAAA,CAE7D,CAAA,CAAA,CACF,CAAA,CAAA,CAEJ,CAEJ,CACF","file":"index.js","sourcesContent":["import { getCountries, getCountryCallingCode, getExampleNumber, parsePhoneNumberFromString, type CountryCode } from 'libphonenumber-js';\r\nimport examples from 'libphonenumber-js/mobile/examples';\r\nimport worldCountries from 'world-countries';\r\n\r\nexport interface Country {\r\n code: string;\r\n name: string;\r\n dialCode: string;\r\n dialCodes: string[];\r\n flag: string;\r\n format?: string;\r\n}\r\n\r\nconst PRIORITY_COUNTRIES = [\r\n 'US', 'GB', 'CA', 'AU', 'DE', 'FR', 'IT', 'ES', 'JP', 'CN', 'IN', 'BR', 'MX', 'KR', 'NL',\r\n 'CH', 'SE', 'AE', 'SG', 'ZA', 'NG', 'SA', 'TR', 'ID', 'PH', 'TH', 'VN', 'MY', 'NZ', 'AR'\r\n];\r\n\r\nconst supportedCountries = new Set(getCountries());\r\n\r\nfunction normalizeDialCode(root: string, suffix: string) {\r\n const normalizedRoot = root.startsWith('+') ? root : `+${root}`;\r\n const digitsOnlySuffix = suffix.replace(/\\D/g, '');\r\n return `${normalizedRoot}${digitsOnlySuffix}`;\r\n}\r\n\r\nfunction buildDialCodes(country: (typeof worldCountries)[number]) {\r\n const root = country.idd?.root;\r\n if (!root) {\r\n return [];\r\n }\r\n\r\n const suffixes = country.idd?.suffixes?.length ? country.idd.suffixes : [''];\r\n const dialCodes = suffixes\r\n .map((suffix) => normalizeDialCode(root, suffix))\r\n .filter((dialCode) => /^\\+\\d+$/.test(dialCode));\r\n\r\n return Array.from(new Set(dialCodes));\r\n}\r\n\r\nfunction getCountryFormat(code: CountryCode) {\r\n const example = getExampleNumber(code, examples);\r\n return example ? example.formatNational().replace(/\\d/g, '#') : undefined;\r\n}\r\n\r\nfunction getCountryPriority(code: string) {\r\n const index = PRIORITY_COUNTRIES.indexOf(code);\r\n return index === -1 ? Number.MAX_SAFE_INTEGER : index;\r\n}\r\n\r\nconst generatedCountries = worldCountries\r\n .filter((country) => supportedCountries.has(country.cca2 as CountryCode))\r\n .map<Country | null>((country) => {\r\n const code = country.cca2 as CountryCode;\r\n const dialCodes = buildDialCodes(country);\r\n const dialCode = `+${getCountryCallingCode(code)}`;\r\n\r\n if (!country.flag || dialCodes.length === 0) {\r\n return null;\r\n }\r\n\r\n return {\r\n code,\r\n name: country.name.common,\r\n dialCode,\r\n dialCodes,\r\n flag: country.flag,\r\n format: getCountryFormat(code),\r\n } satisfies Country;\r\n })\r\n .filter((country): country is Country => country !== null)\r\n .sort((left, right) => {\r\n const priorityDelta = getCountryPriority(left.code) - getCountryPriority(right.code);\r\n return priorityDelta !== 0 ? priorityDelta : left.name.localeCompare(right.name);\r\n });\r\n\r\nexport const countries: Country[] = generatedCountries;\r\n\r\nexport const countryMap = new Map(countries.map((country) => [country.code, country]));\r\n\r\nconst countriesByDialCode = countries.reduce((map, country) => {\r\n for (const dialCode of country.dialCodes) {\r\n const matches = map.get(dialCode) ?? [];\r\n matches.push(country);\r\n map.set(dialCode, matches);\r\n }\r\n\r\n return map;\r\n}, new Map<string, Country[]>());\r\n\r\nconst dialCodeMatchers = countries\r\n .flatMap((country) => country.dialCodes.map((dialCode) => ({ dialCode, country })))\r\n .sort((left, right) => right.dialCode.length - left.dialCode.length);\r\n\r\nfunction normalizeLookupDialCode(dialCode: string) {\r\n const digits = dialCode.replace(/\\D/g, '');\r\n return digits ? `+${digits}` : '';\r\n}\r\n\r\nexport function getCountryByCode(code: string): Country | undefined {\r\n return countryMap.get(code.toUpperCase());\r\n}\r\n\r\nexport function getCountriesByDialCode(dialCode: string): Country[] {\r\n return countriesByDialCode.get(normalizeLookupDialCode(dialCode)) ?? [];\r\n}\r\n\r\nexport function getCountryByDialCode(dialCode: string): Country | undefined {\r\n return getCountriesByDialCode(dialCode)[0];\r\n}\r\n\r\nexport function detectCountryFromPhone(phone: string): Country | undefined {\r\n const trimmed = phone.trim();\r\n\r\n if (!trimmed) {\r\n return undefined;\r\n }\r\n\r\n const normalized = trimmed.startsWith('+')\r\n ? `+${trimmed.replace(/\\D/g, '')}`\r\n : trimmed.startsWith('00')\r\n ? `+${trimmed.slice(2).replace(/\\D/g, '')}`\r\n : '';\r\n\r\n if (!normalized) {\r\n return undefined;\r\n }\r\n\r\n const parsedPhone = parsePhoneNumberFromString(normalized);\r\n if (parsedPhone?.country) {\r\n return getCountryByCode(parsedPhone.country);\r\n }\r\n\r\n return dialCodeMatchers.find((entry) => normalized.startsWith(entry.dialCode))?.country;\r\n}\r\n","import type { Country } from './countries';\r\nimport { AsYouType, isPossiblePhoneNumber, isValidPhoneNumber, validatePhoneNumberLength as validateLength, type CountryCode } from 'libphonenumber-js';\r\n\r\nfunction normalizePhoneInput(phone: string): string {\r\n const trimmed = phone.trim();\r\n const digits = cleanPhone(trimmed);\r\n\r\n if (!digits) {\r\n return '';\r\n }\r\n\r\n return trimmed.startsWith('+') ? `+${digits}` : digits;\r\n}\r\n\r\nfunction getCountryCode(country: Country | undefined): CountryCode | undefined {\r\n return country?.code as CountryCode | undefined;\r\n}\r\n\r\n/**\r\n * Remove all non-digit characters from phone number\r\n */\r\nexport function cleanPhone(phone: string): string {\r\n return phone.replace(/\\D/g, '');\r\n}\r\n\r\n/**\r\n * Format phone number according to country format\r\n */\r\nexport function formatPhone(phone: string, country: Country | undefined): string {\r\n if (!phone) return phone;\r\n\r\n const formatter = new AsYouType(getCountryCode(country));\r\n return formatter.input(normalizePhoneInput(phone));\r\n}\r\n\r\n/**\r\n * Get raw phone number without formatting\r\n */\r\nexport function unformatPhone(formattedPhone: string): string {\r\n return normalizePhoneInput(formattedPhone);\r\n}\r\n\r\n/**\r\n * Validate phone number length based on country\r\n */\r\nexport function validatePhoneLength(phone: string, country: Country | undefined): boolean {\r\n if (!phone || !country) return false;\r\n\r\n if (phone.trim().startsWith('+')) {\r\n return validateLength(normalizePhoneInput(phone)) === undefined;\r\n }\r\n\r\n return validateLength(cleanPhone(phone), getCountryCode(country)) === undefined;\r\n}\r\n\r\n/**\r\n * Validate phone number format\r\n */\r\nexport function validatePhone(\r\n phone: string,\r\n country: Country | undefined,\r\n customValidator?: (phone: string, country: Country | undefined) => boolean\r\n): boolean {\r\n if (!phone) return false;\r\n \r\n if (customValidator) {\r\n return customValidator(phone, country);\r\n }\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const countryCode = getCountryCode(country);\r\n\r\n if (!countryCode) {\r\n return isPossiblePhoneNumber(normalized.startsWith('+') ? normalized : `+${cleanPhone(normalized)}`);\r\n }\r\n\r\n if (normalized.startsWith('+')) {\r\n return isValidPhoneNumber(normalized);\r\n }\r\n\r\n return isValidPhoneNumber(cleanPhone(normalized), countryCode);\r\n}\r\n\r\n/**\r\n * Add dial code to phone number\r\n */\r\nexport function addDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n if (!normalized) return '';\r\n if (normalized.startsWith('+')) return normalized;\r\n\r\n const digits = cleanPhone(normalized);\r\n const matchingDialCode = country.dialCodes.find((dialCode) => digits.startsWith(dialCode.replace('+', '')));\r\n return matchingDialCode ? `+${digits}` : `${country.dialCode}${digits}`;\r\n}\r\n\r\n/**\r\n * Remove dial code from phone number\r\n */\r\nexport function removeDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const digits = cleanPhone(normalized);\r\n\r\n for (const dialCode of country.dialCodes) {\r\n const dialDigits = dialCode.replace('+', '');\r\n if (digits.startsWith(dialDigits)) {\r\n return digits.slice(dialDigits.length);\r\n }\r\n }\r\n\r\n return digits;\r\n}\r\n\r\n/**\r\n * Filter countries by search query\r\n */\r\nexport function filterCountries(\r\n countries: Country[],\r\n query: string,\r\n preferredCountries?: string[]\r\n): Country[] {\r\n const lowerQuery = query.toLowerCase().trim();\r\n \r\n if (!lowerQuery) {\r\n // Sort by preferred countries first\r\n if (preferredCountries?.length) {\r\n return [...countries].sort((a, b) => {\r\n const aPreferred = preferredCountries.indexOf(a.code);\r\n const bPreferred = preferredCountries.indexOf(b.code);\r\n if (aPreferred !== -1 && bPreferred !== -1) return aPreferred - bPreferred;\r\n if (aPreferred !== -1) return -1;\r\n if (bPreferred !== -1) return 1;\r\n return a.name.localeCompare(b.name);\r\n });\r\n }\r\n return countries;\r\n }\r\n \r\n return countries.filter(\r\n country =>\r\n country.name.toLowerCase().includes(lowerQuery) ||\r\n country.code.toLowerCase().includes(lowerQuery) ||\r\n country.dialCodes.some((dialCode) => dialCode.includes(lowerQuery))\r\n );\r\n}\r\n\r\n/**\r\n * Get placeholder based on country format\r\n */\r\nexport function getPlaceholder(country: Country | undefined): string {\r\n if (!country?.format) return country?.dialCode ? `${country.dialCode} 000 000 0000` : 'Phone number';\r\n return country.format.replace(/#/g, '0');\r\n}\r\n","import { useCallback, useMemo, useState, useEffect } from 'react';\r\nimport type { PhoneInputOptions, UsePhoneInputReturn } from './types';\r\nimport type { Country } from './countries';\r\nimport { countries, getCountryByCode, detectCountryFromPhone } from './countries';\r\nimport {\r\n formatPhone,\r\n unformatPhone,\r\n validatePhone,\r\n addDialCode,\r\n removeDialCode,\r\n filterCountries,\r\n getPlaceholder,\r\n} from './utils';\r\n\r\nexport function usePhoneInput(\r\n options: PhoneInputOptions & {\r\n value?: string;\r\n defaultValue?: string;\r\n onChange?: (phone: string, country: Country | undefined) => void;\r\n onBlur?: () => void;\r\n onFocus?: () => void;\r\n } = {}\r\n): UsePhoneInputReturn {\r\n const {\r\n value: controlledValue,\r\n defaultValue = '',\r\n onChange,\r\n onBlur,\r\n onFocus,\r\n defaultCountry = 'US',\r\n preferredCountries,\r\n excludeCountries,\r\n onlyCountries,\r\n autoDetect = true,\r\n formatOnType = true,\r\n includeDialCode = false,\r\n validator,\r\n } = options;\r\n\r\n const isControlled = controlledValue !== undefined;\r\n\r\n // Filter available countries\r\n const availableCountries = useMemo(() => {\r\n let filtered = countries;\r\n \r\n if (onlyCountries?.length) {\r\n filtered = filtered.filter(c => onlyCountries.includes(c.code));\r\n }\r\n \r\n if (excludeCountries?.length) {\r\n filtered = filtered.filter(c => !excludeCountries.includes(c.code));\r\n }\r\n \r\n return filtered;\r\n }, [onlyCountries, excludeCountries]);\r\n\r\n // Initialize state\r\n const initialCountry = getCountryByCode(defaultCountry) || availableCountries[0];\r\n const [internalPhone, setInternalPhone] = useState(defaultValue);\r\n const [country, setCountry] = useState<Country | undefined>(initialCountry);\r\n const [isOpen, setIsOpen] = useState(false);\r\n const [searchQuery, setSearchQuery] = useState('');\r\n\r\n // Current phone value\r\n const phone = isControlled ? controlledValue : internalPhone;\r\n\r\n useEffect(() => {\r\n const nextCountry = getCountryByCode(defaultCountry) || availableCountries[0];\r\n if (nextCountry && nextCountry.code !== country?.code) {\r\n setCountry(nextCountry);\r\n }\r\n }, [defaultCountry, availableCountries, country?.code]);\r\n\r\n // Auto-detect country from phone\r\n useEffect(() => {\r\n if (autoDetect && phone) {\r\n const detected = detectCountryFromPhone(phone);\r\n if (detected && availableCountries.some((candidate) => candidate.code === detected.code) && detected.code !== country?.code) {\r\n setCountry(detected);\r\n }\r\n }\r\n }, [availableCountries, autoDetect, phone, country?.code]);\r\n\r\n // Format phone number\r\n const formattedPhone = useMemo(() => {\r\n if (formatOnType) {\r\n return formatPhone(includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone, country);\r\n }\r\n return includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone;\r\n }, [formatOnType, includeDialCode, phone, country]);\r\n\r\n // Full phone with dial code\r\n const fullPhone = useMemo(() => {\r\n if (includeDialCode && country) {\r\n return addDialCode(phone, country);\r\n }\r\n return phone;\r\n }, [phone, country, includeDialCode]);\r\n\r\n // Validation\r\n const isValid = useMemo(\r\n () => validatePhone(phone, country, validator),\r\n [phone, country, validator]\r\n );\r\n\r\n // Filtered countries for dropdown\r\n const filteredCountries = useMemo(\r\n () => filterCountries(availableCountries, searchQuery, preferredCountries),\r\n [availableCountries, searchQuery, preferredCountries]\r\n );\r\n\r\n // Set phone handler\r\n const setPhone = useCallback(\r\n (newPhone: string) => {\r\n const unformatted = unformatPhone(newPhone);\r\n if (!isControlled) {\r\n setInternalPhone(unformatted);\r\n }\r\n onChange?.(includeDialCode ? addDialCode(unformatted, country) : unformatted, country);\r\n },\r\n [isControlled, onChange, country, includeDialCode]\r\n );\r\n\r\n // Set country handler\r\n const setCountryByCode = useCallback(\r\n (code: string) => {\r\n const newCountry = getCountryByCode(code);\r\n if (newCountry) {\r\n setCountry(newCountry);\r\n onChange?.(includeDialCode ? addDialCode(phone, newCountry) : phone, newCountry);\r\n }\r\n },\r\n [phone, onChange, includeDialCode]\r\n );\r\n\r\n // Select country from dropdown\r\n const selectCountry = useCallback(\r\n (selectedCountry: Country) => {\r\n setCountry(selectedCountry);\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n onChange?.(\r\n includeDialCode ? addDialCode(phone, selectedCountry) : phone,\r\n selectedCountry\r\n );\r\n },\r\n [phone, onChange, includeDialCode]\r\n );\r\n\r\n // Toggle dropdown\r\n const toggleDropdown = useCallback(() => {\r\n setIsOpen(prev => !prev);\r\n if (isOpen) {\r\n setSearchQuery('');\r\n }\r\n }, [isOpen]);\r\n\r\n // Open dropdown\r\n const openDropdown = useCallback(() => {\r\n setIsOpen(true);\r\n }, []);\r\n\r\n // Close dropdown\r\n const closeDropdown = useCallback(() => {\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n }, []);\r\n\r\n // Clear input\r\n const clear = useCallback(() => {\r\n if (!isControlled) {\r\n setInternalPhone('');\r\n }\r\n onChange?.('', country);\r\n }, [isControlled, onChange, country]);\r\n\r\n // Handle input change\r\n const handleInputChange = useCallback(\r\n (event: React.ChangeEvent<HTMLInputElement>) => {\r\n const rawValue = event.target.value;\r\n const unformatted = rawValue.trim().startsWith('+') ? `+${rawValue.replace(/\\D/g, '')}` : unformatPhone(rawValue);\r\n setPhone(unformatted);\r\n },\r\n [setPhone]\r\n );\r\n\r\n // Handle focus\r\n const handleFocus = useCallback(() => {\r\n onFocus?.();\r\n }, [onFocus]);\r\n\r\n // Handle blur\r\n const handleBlur = useCallback(() => {\r\n onBlur?.();\r\n }, [onBlur]);\r\n\r\n return {\r\n // State\r\n phone,\r\n fullPhone,\r\n country,\r\n isValid,\r\n isOpen,\r\n searchQuery,\r\n // Actions\r\n setPhone,\r\n setCountry: setCountryByCode,\r\n toggleDropdown,\r\n openDropdown,\r\n closeDropdown,\r\n setSearchQuery,\r\n clear,\r\n // Props\r\n inputProps: {\r\n value: formattedPhone,\r\n onChange: handleInputChange,\r\n onFocus: handleFocus,\r\n onBlur: handleBlur,\r\n type: 'tel',\r\n inputMode: 'tel',\r\n autoComplete: 'tel',\r\n placeholder: getPlaceholder(country),\r\n 'aria-invalid': phone ? !isValid : undefined,\r\n },\r\n countryButtonProps: {\r\n onClick: toggleDropdown,\r\n 'aria-expanded': isOpen,\r\n 'aria-haspopup': 'listbox',\r\n },\r\n filteredCountries,\r\n selectCountry,\r\n };\r\n}\r\n","import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useRef, useState } from 'react';\nimport { usePhoneInput } from './usePhoneInput';\nimport type { PhoneInputProps } from './types';\nimport type { Country } from './countries';\n\n// SVG Icon Components (Lucide-style)\nconst ChevronUpIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"18 15 12 9 6 15\" />\n </svg>\n);\n\nconst ChevronDownIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"6 9 12 15 18 9\" />\n </svg>\n);\n\nexport interface PhoneInputRef {\n /** Focus the input */\n focus: () => void;\n /** Blur the input */\n blur: () => void;\n /** Clear the input */\n clear: () => void;\n /** Set country */\n setCountry: (countryCode: string) => void;\n /** Get current country */\n getCountry: () => Country | undefined;\n /** Open country selector */\n open: () => void;\n /** Close country selector */\n close: () => void;\n}\n\n/**\n * PhoneInput component - headless phone input with country selection\n * \n * @example\n * ```tsx\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"US\"\n * />\n * ```\n * \n * @example\n * ```tsx\n * // With custom styling\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"GB\"\n * containerClassName=\"phone-input-container\"\n * inputClassName=\"phone-input\"\n * selectorClassName=\"country-selector\"\n * />\n * ```\n */\nexport const PhoneInput = forwardRef<PhoneInputRef, PhoneInputProps>(\n function PhoneInput(props, ref) {\n const {\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n inputClassName,\n selectorClassName,\n containerClassName,\n placeholder,\n disabled,\n readOnly,\n name,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n ...options\n } = props;\n\n const inputRef = useRef<HTMLInputElement>(null);\n const optionRefs = useRef<Array<HTMLLIElement | null>>([]);\n const [highlightedIndex, setHighlightedIndex] = useState(0);\n const listboxId = useId();\n\n const {\n inputProps,\n countryButtonProps,\n country,\n filteredCountries,\n isOpen,\n isValid,\n searchQuery,\n setSearchQuery,\n setCountry,\n selectCountry,\n clear,\n openDropdown,\n closeDropdown,\n } = usePhoneInput({\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n ...options,\n });\n\n // Focus the input\n const focus = useCallback(() => {\n inputRef.current?.focus();\n }, []);\n\n // Blur the input\n const blur = useCallback(() => {\n inputRef.current?.blur();\n }, []);\n\n // Handle country option click\n const handleCountryClick = useCallback((c: Country) => {\n selectCountry(c);\n setHighlightedIndex(0);\n }, [selectCountry]);\n\n // Handle country option keyboard navigation\n const handleCountryKeyDown = useCallback((e: React.KeyboardEvent, c: Country, index: number) => {\n switch (e.key) {\n case 'Enter':\n case ' ':\n e.preventDefault();\n selectCountry(c);\n setHighlightedIndex(0);\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (index < filteredCountries.length - 1) {\n const nextIndex = index + 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n if (index > 0) {\n const nextIndex = index - 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'Escape':\n e.preventDefault();\n closeDropdown();\n break;\n }\n }, [selectCountry, filteredCountries.length, closeDropdown]);\n\n useEffect(() => {\n if (filteredCountries.length === 0) {\n if (highlightedIndex !== 0) {\n setHighlightedIndex(0);\n }\n return;\n }\n\n if (highlightedIndex >= filteredCountries.length) {\n setHighlightedIndex(filteredCountries.length - 1);\n }\n }, [filteredCountries.length, highlightedIndex]);\n\n // Expose imperative methods\n useImperativeHandle(ref, () => ({\n focus,\n blur,\n clear,\n setCountry,\n getCountry: () => country,\n open: openDropdown,\n close: closeDropdown,\n }));\n\n // Render default UI\n return (\n <div className={containerClassName} data-valid={isValid}>\n {/* Country Selector Button */}\n <button\n {...countryButtonProps}\n type=\"button\"\n className={selectorClassName}\n disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n aria-controls={listboxId}\n >\n {country ? (\n <>\n <span className=\"phone-input-flag\">{country.flag}</span>\n <span className=\"phone-input-dial-code\">{country.dialCode}</span>\n </>\n ) : (\n <span className=\"phone-input-placeholder\">Select</span>\n )}\n <span className=\"phone-input-arrow\" aria-hidden=\"true\">\n {isOpen ? <ChevronUpIcon size={12} /> : <ChevronDownIcon size={12} />}\n </span>\n </button>\n\n {/* Phone Input */}\n <input\n {...inputProps}\n ref={inputRef}\n id={id}\n name={name}\n className={inputClassName}\n placeholder={placeholder || inputProps.placeholder}\n disabled={disabled}\n readOnly={readOnly}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n />\n\n {/* Country Dropdown */}\n {isOpen && (\n <div className=\"phone-input-dropdown\">\n {/* Search Input */}\n <div className=\"phone-input-search\">\n <input\n type=\"text\"\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n placeholder=\"Search countries...\"\n autoFocus\n aria-controls={listboxId}\n aria-label=\"Search countries\"\n />\n </div>\n\n {/* Country List */}\n <ul className=\"phone-input-country-list\" id={listboxId} role=\"listbox\" aria-label=\"Country options\">\n {filteredCountries.map((c, index) => (\n <li\n key={c.code}\n ref={(element) => {\n optionRefs.current[index] = element;\n }}\n role=\"option\"\n aria-selected={c.code === country?.code}\n className={`phone-input-country-option ${\n c.code === country?.code ? 'selected' : ''\n } ${index === highlightedIndex ? 'highlighted' : ''}`}\n onClick={() => handleCountryClick(c)}\n onKeyDown={(e) => handleCountryKeyDown(e, c, index)}\n onMouseEnter={() => setHighlightedIndex(index)}\n tabIndex={index === highlightedIndex ? 0 : -1}\n >\n <span className=\"phone-input-flag\">{c.flag}</span>\n <span className=\"phone-input-country-name\">{c.name}</span>\n <span className=\"phone-input-dial-code\">{c.dialCode}</span>\n </li>\n ))}\n {filteredCountries.length === 0 && (\n <li className=\"phone-input-no-results\">No countries found</li>\n )}\n </ul>\n </div>\n )}\n </div>\n );\n }\n);\n\nexport default PhoneInput;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/countries.ts","../src/labels.ts","../src/utils.ts","../src/usePhoneInput.ts","../src/PhoneInput.tsx"],"names":["PRIORITY_COUNTRIES","supportedCountries","getCountries","normalizeDialCode","root","suffix","normalizedRoot","digitsOnlySuffix","buildDialCodes","country","dialCodes","dialCode","getCountryFormat","code","example","getExampleNumber","examples","getCountryPriority","index","generatedCountries","worldCountries","getCountryCallingCode","left","right","priorityDelta","countries","countryMap","countriesByDialCode","map","matches","dialCodeMatchers","displayNameCache","normalizeLocales","locale","getDisplayNames","locales","cacheKey","cached","displayNames","normalizeLookupDialCode","digits","getCountryByCode","getLocalizedCountryName","localizeCountry","displayName","localizeCountries","list","getCountriesByDialCode","getCountryByDialCode","detectCountryFromPhone","phone","trimmed","normalized","parsedPhone","parsePhoneNumberFromString","entry","DEFAULT_PHONE_INPUT_LABELS","LABELS_BY_LANGUAGE","getPrimaryLanguage","firstLocale","resolvePhoneInputLabels","overrides","language","localizedDefaults","normalizePhoneInput","cleanPhone","getCountryCode","formatPhone","AsYouType","unformatPhone","formattedPhone","validatePhoneLength","validateLength","validatePhone","customValidator","countryCode","isValidPhoneNumber","isPossiblePhoneNumber","addDialCode","removeDialCode","dialDigits","filterCountries","query","preferredCountries","lowerQuery","b","aPreferred","bPreferred","getCountryDisplayName","getPlaceholder","countDigitsBeforePosition","value","position","getCaretPositionFromDigitCount","digitCount","seenDigits","usePhoneInput","options","controlledValue","defaultValue","onChange","onBlur","onFocus","defaultCountry","excludeCountries","onlyCountries","autoDetect","formatOnType","includeDialCode","validator","labels","isControlled","inputRef","useRef","pendingCaretDigitIndexRef","availableCountries","useMemo","filtered","c","localizedCountries","resolvedLabels","initialCountry","candidate","internalPhone","setInternalPhone","useState","setCountry","isOpen","setIsOpen","searchQuery","setSearchQuery","useEffect","nextCountry","detected","fullPhone","isValid","localizedCountry","filteredCountries","getOutputCountry","useCallback","useLayoutEffect","nextDigitIndex","input","caretPosition","setPhone","newPhone","unformatted","setCountryByCode","newCountry","selectCountry","selectedCountry","rawCountry","toggleDropdown","prev","openDropdown","closeDropdown","clear","handleInputChange","event","rawValue","handleFocus","handleBlur","ChevronUpIcon","size","jsx","ChevronDownIcon","PhoneInput","forwardRef","props","ref","inputClassName","selectorClassName","containerClassName","searchable","placeholder","disabled","readOnly","name","id","ariaLabel","ariaLabelledBy","optionRefs","highlightedIndex","setHighlightedIndex","listboxId","useId","inputProps","countryButtonProps","hookInputRef","mergedInputRef","element","focus","blur","handleCountryClick","handleCountryKeyDown","e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,CAAA,CACAmB,CAAAA,CAAkB,MAAA,GAAW,GAC5B2B,GAAAA,CAAC,IAAA,CAAA,CAAG,SAAA,CAAU,wBAAA,CAA0B,SAAAtD,CAAAA,CAAO,gBAAA,CAAiB,GAEpE,CAAA,CAAA,CACF,CAAA,CAAA,CAEJ,CAEJ,CACF","file":"index.js","sourcesContent":["import { getCountries, getCountryCallingCode, getExampleNumber, parsePhoneNumberFromString, type CountryCode } from 'libphonenumber-js';\r\nimport examples from 'libphonenumber-js/mobile/examples';\r\nimport worldCountries from 'world-countries';\r\n\r\nexport interface Country {\r\n code: string;\r\n name: string;\r\n dialCode: string;\r\n dialCodes: string[];\r\n flag: string;\r\n format?: string;\r\n displayName?: string;\r\n}\r\n\r\nconst PRIORITY_COUNTRIES = [\r\n 'US', 'GB', 'CA', 'AU', 'DE', 'FR', 'IT', 'ES', 'JP', 'CN', 'IN', 'BR', 'MX', 'KR', 'NL',\r\n 'CH', 'SE', 'AE', 'SG', 'ZA', 'NG', 'SA', 'TR', 'ID', 'PH', 'TH', 'VN', 'MY', 'NZ', 'AR'\r\n];\r\n\r\nconst supportedCountries = new Set(getCountries());\r\n\r\nfunction normalizeDialCode(root: string, suffix: string) {\r\n const normalizedRoot = root.startsWith('+') ? root : `+${root}`;\r\n const digitsOnlySuffix = suffix.replace(/\\D/g, '');\r\n return `${normalizedRoot}${digitsOnlySuffix}`;\r\n}\r\n\r\nfunction buildDialCodes(country: (typeof worldCountries)[number]) {\r\n const root = country.idd?.root;\r\n if (!root) {\r\n return [];\r\n }\r\n\r\n const suffixes = country.idd?.suffixes?.length ? country.idd.suffixes : [''];\r\n const dialCodes = suffixes\r\n .map((suffix) => normalizeDialCode(root, suffix))\r\n .filter((dialCode) => /^\\+\\d+$/.test(dialCode));\r\n\r\n return Array.from(new Set(dialCodes));\r\n}\r\n\r\nfunction getCountryFormat(code: CountryCode) {\r\n const example = getExampleNumber(code, examples);\r\n return example ? example.formatNational().replace(/\\d/g, '#') : undefined;\r\n}\r\n\r\nfunction getCountryPriority(code: string) {\r\n const index = PRIORITY_COUNTRIES.indexOf(code);\r\n return index === -1 ? Number.MAX_SAFE_INTEGER : index;\r\n}\r\n\r\nconst generatedCountries = worldCountries\r\n .filter((country) => supportedCountries.has(country.cca2 as CountryCode))\r\n .map<Country | null>((country) => {\r\n const code = country.cca2 as CountryCode;\r\n const dialCodes = buildDialCodes(country);\r\n const dialCode = `+${getCountryCallingCode(code)}`;\r\n\r\n if (!country.flag || dialCodes.length === 0) {\r\n return null;\r\n }\r\n\r\n return {\r\n code,\r\n name: country.name.common,\r\n dialCode,\r\n dialCodes,\r\n flag: country.flag,\r\n format: getCountryFormat(code),\r\n } satisfies Country;\r\n })\r\n .filter((country): country is Country => country !== null)\r\n .sort((left, right) => {\r\n const priorityDelta = getCountryPriority(left.code) - getCountryPriority(right.code);\r\n return priorityDelta !== 0 ? priorityDelta : left.name.localeCompare(right.name);\r\n });\r\n\r\nexport const countries: Country[] = generatedCountries;\r\n\r\nexport const countryMap = new Map(countries.map((country) => [country.code, country]));\r\n\r\nconst countriesByDialCode = countries.reduce((map, country) => {\r\n for (const dialCode of country.dialCodes) {\r\n const matches = map.get(dialCode) ?? [];\r\n matches.push(country);\r\n map.set(dialCode, matches);\r\n }\r\n\r\n return map;\r\n}, new Map<string, Country[]>());\r\n\r\nconst dialCodeMatchers = countries\r\n .flatMap((country) => country.dialCodes.map((dialCode) => ({ dialCode, country })))\r\n .sort((left, right) => right.dialCode.length - left.dialCode.length);\r\n\r\nconst displayNameCache = new Map<string, Intl.DisplayNames>();\r\n\r\nfunction normalizeLocales(locale?: string | readonly string[]) {\r\n return Array.isArray(locale) ? [...locale] : locale ? [locale] : [];\r\n}\r\n\r\nfunction getDisplayNames(locale?: string | readonly string[]) {\r\n const locales = normalizeLocales(locale);\r\n if (locales.length === 0 || typeof Intl === 'undefined' || typeof Intl.DisplayNames === 'undefined') {\r\n return undefined;\r\n }\r\n\r\n const cacheKey = locales.join('|');\r\n const cached = displayNameCache.get(cacheKey);\r\n if (cached) {\r\n return cached;\r\n }\r\n\r\n try {\r\n const displayNames = new Intl.DisplayNames(locales, { type: 'region' });\r\n displayNameCache.set(cacheKey, displayNames);\r\n return displayNames;\r\n } catch {\r\n return undefined;\r\n }\r\n}\r\n\r\nfunction normalizeLookupDialCode(dialCode: string) {\r\n const digits = dialCode.replace(/\\D/g, '');\r\n return digits ? `+${digits}` : '';\r\n}\r\n\r\nexport function getCountryByCode(code: string): Country | undefined {\r\n return countryMap.get(code.toUpperCase());\r\n}\r\n\r\nexport function getLocalizedCountryName(\r\n country: Country | undefined,\r\n locale?: string | readonly string[]\r\n): string | undefined {\r\n if (!country) {\r\n return undefined;\r\n }\r\n\r\n const displayNames = getDisplayNames(locale);\r\n return displayNames?.of(country.code) ?? country.displayName ?? country.name;\r\n}\r\n\r\nexport function localizeCountry(\r\n country: Country | undefined,\r\n locale?: string | readonly string[]\r\n): Country | undefined {\r\n if (!country) {\r\n return undefined;\r\n }\r\n\r\n const displayName = getLocalizedCountryName(country, locale);\r\n return displayName ? { ...country, displayName } : country;\r\n}\r\n\r\nexport function localizeCountries(\r\n list: Country[],\r\n locale?: string | readonly string[]\r\n): Country[] {\r\n if (!locale) {\r\n return list;\r\n }\r\n\r\n return list.map((country) => localizeCountry(country, locale) ?? country);\r\n}\r\n\r\nexport function getCountriesByDialCode(dialCode: string): Country[] {\r\n return countriesByDialCode.get(normalizeLookupDialCode(dialCode)) ?? [];\r\n}\r\n\r\nexport function getCountryByDialCode(dialCode: string): Country | undefined {\r\n return getCountriesByDialCode(dialCode)[0];\r\n}\r\n\r\nexport function detectCountryFromPhone(phone: string): Country | undefined {\r\n const trimmed = phone.trim();\r\n\r\n if (!trimmed) {\r\n return undefined;\r\n }\r\n\r\n const normalized = trimmed.startsWith('+')\r\n ? `+${trimmed.replace(/\\D/g, '')}`\r\n : trimmed.startsWith('00')\r\n ? `+${trimmed.slice(2).replace(/\\D/g, '')}`\r\n : '';\r\n\r\n if (!normalized) {\r\n return undefined;\r\n }\r\n\r\n const parsedPhone = parsePhoneNumberFromString(normalized);\r\n if (parsedPhone?.country) {\r\n return getCountryByCode(parsedPhone.country);\r\n }\r\n\r\n return dialCodeMatchers.find((entry) => normalized.startsWith(entry.dialCode))?.country;\r\n}\r\n","import type { PhoneInputLabels } from './types';\r\n\r\nexport const DEFAULT_PHONE_INPUT_LABELS: PhoneInputLabels = {\r\n selectCountry: 'Select country',\r\n countrySearchPlaceholder: 'Search countries...',\r\n noCountriesFound: 'No countries found',\r\n searchCountriesAriaLabel: 'Search countries',\r\n countryOptionsAriaLabel: 'Country options',\r\n countryButtonAriaLabel: 'Open country selector',\r\n};\r\n\r\nconst LABELS_BY_LANGUAGE: Record<string, Partial<PhoneInputLabels>> = {\r\n en: DEFAULT_PHONE_INPUT_LABELS,\r\n fr: {\r\n selectCountry: 'Choisir un pays',\r\n countrySearchPlaceholder: 'Rechercher un pays...',\r\n noCountriesFound: 'Aucun pays trouvé',\r\n searchCountriesAriaLabel: 'Rechercher des pays',\r\n countryOptionsAriaLabel: 'Options de pays',\r\n countryButtonAriaLabel: 'Ouvrir le sélecteur de pays',\r\n },\r\n de: {\r\n selectCountry: 'Land auswählen',\r\n countrySearchPlaceholder: 'Land suchen...',\r\n noCountriesFound: 'Keine Länder gefunden',\r\n searchCountriesAriaLabel: 'Länder suchen',\r\n countryOptionsAriaLabel: 'Länderoptionen',\r\n countryButtonAriaLabel: 'Länderauswahl öffnen',\r\n },\r\n es: {\r\n selectCountry: 'Seleccionar país',\r\n countrySearchPlaceholder: 'Buscar país...',\r\n noCountriesFound: 'No se encontraron países',\r\n searchCountriesAriaLabel: 'Buscar países',\r\n countryOptionsAriaLabel: 'Opciones de país',\r\n countryButtonAriaLabel: 'Abrir selector de país',\r\n },\r\n pt: {\r\n selectCountry: 'Selecionar país',\r\n countrySearchPlaceholder: 'Pesquisar país...',\r\n noCountriesFound: 'Nenhum país encontrado',\r\n searchCountriesAriaLabel: 'Pesquisar países',\r\n countryOptionsAriaLabel: 'Opções de país',\r\n countryButtonAriaLabel: 'Abrir seletor de país',\r\n },\r\n it: {\r\n selectCountry: 'Seleziona paese',\r\n countrySearchPlaceholder: 'Cerca paese...',\r\n noCountriesFound: 'Nessun paese trovato',\r\n searchCountriesAriaLabel: 'Cerca paesi',\r\n countryOptionsAriaLabel: 'Opzioni paese',\r\n countryButtonAriaLabel: 'Apri selettore paese',\r\n },\r\n ja: {\r\n selectCountry: '国を選択',\r\n countrySearchPlaceholder: '国を検索...',\r\n noCountriesFound: '国が見つかりません',\r\n searchCountriesAriaLabel: '国を検索',\r\n countryOptionsAriaLabel: '国の候補',\r\n countryButtonAriaLabel: '国のセレクターを開く',\r\n },\r\n ko: {\r\n selectCountry: '국가 선택',\r\n countrySearchPlaceholder: '국가 검색...',\r\n noCountriesFound: '국가를 찾을 수 없습니다',\r\n searchCountriesAriaLabel: '국가 검색',\r\n countryOptionsAriaLabel: '국가 옵션',\r\n countryButtonAriaLabel: '국가 선택기 열기',\r\n },\r\n zh: {\r\n selectCountry: '选择国家',\r\n countrySearchPlaceholder: '搜索国家...',\r\n noCountriesFound: '未找到国家',\r\n searchCountriesAriaLabel: '搜索国家',\r\n countryOptionsAriaLabel: '国家选项',\r\n countryButtonAriaLabel: '打开国家选择器',\r\n },\r\n ar: {\r\n selectCountry: 'اختر الدولة',\r\n countrySearchPlaceholder: 'ابحث عن دولة...',\r\n noCountriesFound: 'لم يتم العثور على دول',\r\n searchCountriesAriaLabel: 'ابحث عن الدول',\r\n countryOptionsAriaLabel: 'خيارات الدول',\r\n countryButtonAriaLabel: 'افتح محدد الدولة',\r\n },\r\n hi: {\r\n selectCountry: 'देश चुनें',\r\n countrySearchPlaceholder: 'देश खोजें...',\r\n noCountriesFound: 'कोई देश नहीं मिला',\r\n searchCountriesAriaLabel: 'देश खोजें',\r\n countryOptionsAriaLabel: 'देश विकल्प',\r\n countryButtonAriaLabel: 'देश चयन खोलें',\r\n },\r\n};\r\n\r\nfunction getPrimaryLanguage(locale?: string | readonly string[]): string | undefined {\r\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : [];\r\n const firstLocale = locales.find(Boolean);\r\n return firstLocale ? firstLocale.toLowerCase().split('-')[0] : undefined;\r\n}\r\n\r\nexport function resolvePhoneInputLabels(\r\n locale?: string | readonly string[],\r\n overrides?: Partial<PhoneInputLabels>\r\n): PhoneInputLabels {\r\n const language = getPrimaryLanguage(locale);\r\n const localizedDefaults = language ? LABELS_BY_LANGUAGE[language] : undefined;\r\n\r\n return {\r\n ...DEFAULT_PHONE_INPUT_LABELS,\r\n ...localizedDefaults,\r\n ...overrides,\r\n };\r\n}","import type { Country } from './countries';\r\nimport { AsYouType, isPossiblePhoneNumber, isValidPhoneNumber, validatePhoneNumberLength as validateLength, type CountryCode } from 'libphonenumber-js';\r\n\r\nfunction normalizePhoneInput(phone: string): string {\r\n const trimmed = phone.trim();\r\n const digits = cleanPhone(trimmed);\r\n\r\n if (trimmed.startsWith('+') && !digits) {\r\n return '+';\r\n }\r\n\r\n if (!digits) {\r\n return '';\r\n }\r\n\r\n return trimmed.startsWith('+') ? `+${digits}` : digits;\r\n}\r\n\r\nfunction getCountryCode(country: Country | undefined): CountryCode | undefined {\r\n return country?.code as CountryCode | undefined;\r\n}\r\n\r\n/**\r\n * Remove all non-digit characters from phone number\r\n */\r\nexport function cleanPhone(phone: string): string {\r\n return phone.replace(/\\D/g, '');\r\n}\r\n\r\n/**\r\n * Format phone number according to country format\r\n */\r\nexport function formatPhone(phone: string, country: Country | undefined): string {\r\n if (!phone) return phone;\r\n\r\n const formatter = new AsYouType(getCountryCode(country));\r\n return formatter.input(normalizePhoneInput(phone));\r\n}\r\n\r\n/**\r\n * Get raw phone number without formatting\r\n */\r\nexport function unformatPhone(formattedPhone: string): string {\r\n return normalizePhoneInput(formattedPhone);\r\n}\r\n\r\n/**\r\n * Validate phone number length based on country\r\n */\r\nexport function validatePhoneLength(phone: string, country: Country | undefined): boolean {\r\n if (!phone || !country) return false;\r\n\r\n if (phone.trim().startsWith('+')) {\r\n return validateLength(normalizePhoneInput(phone)) === undefined;\r\n }\r\n\r\n return validateLength(cleanPhone(phone), getCountryCode(country)) === undefined;\r\n}\r\n\r\n/**\r\n * Validate phone number format\r\n */\r\nexport function validatePhone(\r\n phone: string,\r\n country: Country | undefined,\r\n customValidator?: (phone: string, country: Country | undefined) => boolean\r\n): boolean {\r\n if (!phone) return false;\r\n \r\n if (customValidator) {\r\n return customValidator(phone, country);\r\n }\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const countryCode = getCountryCode(country);\r\n\r\n if (!countryCode) {\r\n return isPossiblePhoneNumber(normalized.startsWith('+') ? normalized : `+${cleanPhone(normalized)}`);\r\n }\r\n\r\n if (normalized.startsWith('+')) {\r\n return isValidPhoneNumber(normalized);\r\n }\r\n\r\n return isValidPhoneNumber(cleanPhone(normalized), countryCode);\r\n}\r\n\r\n/**\r\n * Add dial code to phone number\r\n */\r\nexport function addDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n if (!normalized) return '';\r\n if (normalized === '+') return '';\r\n if (normalized.startsWith('+')) return normalized;\r\n\r\n const digits = cleanPhone(normalized);\r\n const matchingDialCode = country.dialCodes.find((dialCode) => digits.startsWith(dialCode.replace('+', '')));\r\n return matchingDialCode ? `+${digits}` : `${country.dialCode}${digits}`;\r\n}\r\n\r\n/**\r\n * Remove dial code from phone number\r\n */\r\nexport function removeDialCode(phone: string, country: Country | undefined): string {\r\n if (!country) return phone;\r\n\r\n const normalized = normalizePhoneInput(phone);\r\n const digits = cleanPhone(normalized);\r\n\r\n for (const dialCode of country.dialCodes) {\r\n const dialDigits = dialCode.replace('+', '');\r\n if (digits.startsWith(dialDigits)) {\r\n return digits.slice(dialDigits.length);\r\n }\r\n }\r\n\r\n return digits;\r\n}\r\n\r\n/**\r\n * Filter countries by search query\r\n */\r\nexport function filterCountries(\r\n countries: Country[],\r\n query: string,\r\n preferredCountries?: string[]\r\n): Country[] {\r\n const lowerQuery = query.toLowerCase().trim();\r\n \r\n if (!lowerQuery) {\r\n // Sort by preferred countries first\r\n if (preferredCountries?.length) {\r\n return [...countries].sort((a, b) => {\r\n const aPreferred = preferredCountries.indexOf(a.code);\r\n const bPreferred = preferredCountries.indexOf(b.code);\r\n if (aPreferred !== -1 && bPreferred !== -1) return aPreferred - bPreferred;\r\n if (aPreferred !== -1) return -1;\r\n if (bPreferred !== -1) return 1;\r\n return (a.displayName ?? a.name).localeCompare(b.displayName ?? b.name);\r\n });\r\n }\r\n return countries;\r\n }\r\n \r\n return countries.filter(\r\n country =>\r\n country.name.toLowerCase().includes(lowerQuery) ||\r\n (country.displayName ?? '').toLowerCase().includes(lowerQuery) ||\r\n country.code.toLowerCase().includes(lowerQuery) ||\r\n country.dialCodes.some((dialCode) => dialCode.includes(lowerQuery))\r\n );\r\n}\r\n\r\nexport function getCountryDisplayName(country: Country | undefined): string {\r\n return country?.displayName ?? country?.name ?? '';\r\n}\r\n\r\n/**\r\n * Get placeholder based on country format\r\n */\r\nexport function getPlaceholder(country: Country | undefined): string {\r\n if (!country?.format) return country?.dialCode ? `${country.dialCode} 000 000 0000` : 'Phone number';\r\n return country.format.replace(/#/g, '0');\r\n}\r\n","import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\r\nimport type { PhoneInputOptions, UsePhoneInputReturn } from './types';\r\nimport type { Country } from './countries';\r\nimport { countries, detectCountryFromPhone, getCountryByCode, localizeCountries, localizeCountry } from './countries';\r\nimport { resolvePhoneInputLabels } from './labels';\r\nimport {\r\n formatPhone,\r\n unformatPhone,\r\n validatePhone,\r\n addDialCode,\r\n removeDialCode,\r\n filterCountries,\r\n getPlaceholder,\r\n} from './utils';\r\n\r\nfunction countDigitsBeforePosition(value: string, position: number) {\r\n return value.slice(0, position).replace(/\\D/g, '').length;\r\n}\r\n\r\nfunction getCaretPositionFromDigitCount(value: string, digitCount: number) {\r\n if (digitCount <= 0) {\r\n return value.startsWith('+') ? 1 : 0;\r\n }\r\n\r\n let seenDigits = 0;\r\n\r\n for (let index = 0; index < value.length; index += 1) {\r\n if (/\\d/.test(value[index])) {\r\n seenDigits += 1;\r\n if (seenDigits === digitCount) {\r\n return index + 1;\r\n }\r\n }\r\n }\r\n\r\n return value.length;\r\n}\r\n\r\nexport function usePhoneInput(\r\n options: PhoneInputOptions & {\r\n value?: string;\r\n defaultValue?: string;\r\n onChange?: (phone: string, country: Country | undefined) => void;\r\n onBlur?: () => void;\r\n onFocus?: () => void;\r\n } = {}\r\n): UsePhoneInputReturn {\r\n const {\r\n value: controlledValue,\r\n defaultValue = '',\r\n onChange,\r\n onBlur,\r\n onFocus,\r\n defaultCountry = 'US',\r\n preferredCountries,\r\n excludeCountries,\r\n onlyCountries,\r\n autoDetect = true,\r\n formatOnType = true,\r\n includeDialCode = false,\r\n validator,\r\n locale,\r\n labels,\r\n } = options;\r\n\r\n const isControlled = controlledValue !== undefined;\r\n const inputRef = useRef<HTMLInputElement>(null);\r\n const pendingCaretDigitIndexRef = useRef<number | null>(null);\r\n\r\n // Filter available countries\r\n const availableCountries = useMemo(() => {\r\n let filtered = countries;\r\n \r\n if (onlyCountries?.length) {\r\n filtered = filtered.filter(c => onlyCountries.includes(c.code));\r\n }\r\n \r\n if (excludeCountries?.length) {\r\n filtered = filtered.filter(c => !excludeCountries.includes(c.code));\r\n }\r\n \r\n return filtered;\r\n }, [onlyCountries, excludeCountries]);\r\n\r\n const localizedCountries = useMemo(\r\n () => localizeCountries(availableCountries, locale),\r\n [availableCountries, locale]\r\n );\r\n\r\n const resolvedLabels = useMemo(\r\n () => resolvePhoneInputLabels(locale, labels),\r\n [locale, labels]\r\n );\r\n\r\n // Initialize state\r\n const initialCountry = availableCountries.find((candidate) => candidate.code === defaultCountry) || availableCountries[0];\r\n const [internalPhone, setInternalPhone] = useState(defaultValue);\r\n const [country, setCountry] = useState<Country | undefined>(initialCountry);\r\n const [isOpen, setIsOpen] = useState(false);\r\n const [searchQuery, setSearchQuery] = useState('');\r\n\r\n // Current phone value\r\n const phone = isControlled ? controlledValue : internalPhone;\r\n\r\n useEffect(() => {\r\n const nextCountry = availableCountries.find((candidate) => candidate.code === defaultCountry) || availableCountries[0];\r\n if (nextCountry && nextCountry.code !== country?.code) {\r\n setCountry(nextCountry);\r\n }\r\n }, [defaultCountry, availableCountries, country?.code]);\r\n\r\n // Auto-detect country from phone\r\n useEffect(() => {\r\n if (autoDetect && phone) {\r\n const detected = detectCountryFromPhone(phone);\r\n if (detected && availableCountries.some((candidate) => candidate.code === detected.code) && detected.code !== country?.code) {\r\n setCountry(detected);\r\n }\r\n }\r\n }, [availableCountries, autoDetect, phone, country?.code]);\r\n\r\n // Format phone number\r\n const formattedPhone = useMemo(() => {\r\n if (formatOnType) {\r\n return formatPhone(includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone, country);\r\n }\r\n return includeDialCode && phone.startsWith('+') ? removeDialCode(phone, country) : phone;\r\n }, [formatOnType, includeDialCode, phone, country]);\r\n\r\n // Full phone with dial code\r\n const fullPhone = useMemo(() => {\r\n if (includeDialCode && country) {\r\n return addDialCode(phone, country);\r\n }\r\n return phone;\r\n }, [phone, country, includeDialCode]);\r\n\r\n // Validation\r\n const isValid = useMemo(\r\n () => validatePhone(phone, country, validator),\r\n [phone, country, validator]\r\n );\r\n\r\n const localizedCountry = useMemo(\r\n () => localizeCountry(country, locale),\r\n [country, locale]\r\n );\r\n\r\n // Filtered countries for dropdown\r\n const filteredCountries = useMemo(\r\n () => filterCountries(localizedCountries, searchQuery, preferredCountries),\r\n [localizedCountries, searchQuery, preferredCountries]\r\n );\r\n\r\n const getOutputCountry = useCallback(\r\n (nextCountry: Country | undefined) => localizeCountry(nextCountry, locale),\r\n [locale]\r\n );\r\n\r\n useLayoutEffect(() => {\r\n const nextDigitIndex = pendingCaretDigitIndexRef.current;\r\n const input = inputRef.current;\r\n\r\n if (nextDigitIndex === null || !input || typeof input.setSelectionRange !== 'function') {\r\n return;\r\n }\r\n\r\n if (typeof document !== 'undefined' && document.activeElement !== input) {\r\n return;\r\n }\r\n\r\n const caretPosition = getCaretPositionFromDigitCount(formattedPhone, nextDigitIndex);\r\n input.setSelectionRange(caretPosition, caretPosition);\r\n pendingCaretDigitIndexRef.current = null;\r\n }, [formattedPhone]);\r\n\r\n // Set phone handler\r\n const setPhone = useCallback(\r\n (newPhone: string) => {\r\n const unformatted = unformatPhone(newPhone);\r\n if (!isControlled) {\r\n setInternalPhone(unformatted);\r\n }\r\n onChange?.(\r\n includeDialCode ? addDialCode(unformatted, country) : unformatted,\r\n getOutputCountry(country)\r\n );\r\n },\r\n [isControlled, onChange, country, includeDialCode, getOutputCountry]\r\n );\r\n\r\n // Set country handler\r\n const setCountryByCode = useCallback(\r\n (code: string) => {\r\n const newCountry = getCountryByCode(code);\r\n if (newCountry) {\r\n setCountry(newCountry);\r\n onChange?.(\r\n includeDialCode ? addDialCode(phone, newCountry) : phone,\r\n getOutputCountry(newCountry)\r\n );\r\n }\r\n },\r\n [phone, onChange, includeDialCode, getOutputCountry]\r\n );\r\n\r\n // Select country from dropdown\r\n const selectCountry = useCallback(\r\n (selectedCountry: Country) => {\r\n const rawCountry = getCountryByCode(selectedCountry.code) ?? selectedCountry;\r\n setCountry(rawCountry);\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n onChange?.(\r\n includeDialCode ? addDialCode(phone, rawCountry) : phone,\r\n getOutputCountry(rawCountry)\r\n );\r\n },\r\n [phone, onChange, includeDialCode, getOutputCountry]\r\n );\r\n\r\n // Toggle dropdown\r\n const toggleDropdown = useCallback(() => {\r\n setIsOpen(prev => !prev);\r\n if (isOpen) {\r\n setSearchQuery('');\r\n }\r\n }, [isOpen]);\r\n\r\n // Open dropdown\r\n const openDropdown = useCallback(() => {\r\n setIsOpen(true);\r\n }, []);\r\n\r\n // Close dropdown\r\n const closeDropdown = useCallback(() => {\r\n setIsOpen(false);\r\n setSearchQuery('');\r\n }, []);\r\n\r\n // Clear input\r\n const clear = useCallback(() => {\r\n if (!isControlled) {\r\n setInternalPhone('');\r\n }\r\n onChange?.('', getOutputCountry(country));\r\n }, [isControlled, onChange, country, getOutputCountry]);\r\n\r\n // Handle input change\r\n const handleInputChange = useCallback(\r\n (event: React.ChangeEvent<HTMLInputElement>) => {\r\n const rawValue = event.target.value;\r\n const caretPosition = event.target.selectionStart ?? rawValue.length;\r\n const unformatted = rawValue.trim().startsWith('+') ? `+${rawValue.replace(/\\D/g, '')}` : unformatPhone(rawValue);\r\n pendingCaretDigitIndexRef.current = countDigitsBeforePosition(rawValue, caretPosition);\r\n setPhone(unformatted);\r\n },\r\n [setPhone]\r\n );\r\n\r\n // Handle focus\r\n const handleFocus = useCallback(() => {\r\n onFocus?.();\r\n }, [onFocus]);\r\n\r\n // Handle blur\r\n const handleBlur = useCallback(() => {\r\n onBlur?.();\r\n }, [onBlur]);\r\n\r\n return {\r\n // State\r\n phone,\r\n fullPhone,\r\n country: localizedCountry,\r\n isValid,\r\n isOpen,\r\n searchQuery,\r\n labels: resolvedLabels,\r\n // Actions\r\n setPhone,\r\n setCountry: setCountryByCode,\r\n toggleDropdown,\r\n openDropdown,\r\n closeDropdown,\r\n setSearchQuery,\r\n clear,\r\n // Props\r\n inputProps: {\r\n ref: inputRef,\r\n value: formattedPhone,\r\n onChange: handleInputChange,\r\n onFocus: handleFocus,\r\n onBlur: handleBlur,\r\n type: 'tel',\r\n inputMode: 'tel',\r\n autoComplete: 'tel',\r\n placeholder: getPlaceholder(country),\r\n 'aria-invalid': phone ? !isValid : undefined,\r\n },\r\n countryButtonProps: {\r\n onClick: toggleDropdown,\r\n 'aria-expanded': isOpen,\r\n 'aria-haspopup': 'listbox',\r\n 'aria-label': resolvedLabels.countryButtonAriaLabel,\r\n },\r\n filteredCountries,\r\n selectCountry,\r\n };\r\n}\r\n","import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useRef, useState, type MutableRefObject, type Ref } from 'react';\nimport { usePhoneInput } from './usePhoneInput';\nimport type { PhoneInputProps } from './types';\nimport type { Country } from './countries';\nimport { getCountryDisplayName } from './utils';\n\n// SVG Icon Components (Lucide-style)\nconst ChevronUpIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"18 15 12 9 6 15\" />\n </svg>\n);\n\nconst ChevronDownIcon = ({ size = 12 }: { size?: number }) => (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"6 9 12 15 18 9\" />\n </svg>\n);\n\nexport interface PhoneInputRef {\n /** Focus the input */\n focus: () => void;\n /** Blur the input */\n blur: () => void;\n /** Clear the input */\n clear: () => void;\n /** Set country */\n setCountry: (countryCode: string) => void;\n /** Get current country */\n getCountry: () => Country | undefined;\n /** Open country selector */\n open: () => void;\n /** Close country selector */\n close: () => void;\n}\n\n/**\n * PhoneInput component - headless phone input with country selection\n * \n * @example\n * ```tsx\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"US\"\n * />\n * ```\n * \n * @example\n * ```tsx\n * // With custom styling\n * <PhoneInput\n * value={value}\n * onChange={setValue}\n * defaultCountry=\"GB\"\n * containerClassName=\"phone-input-container\"\n * inputClassName=\"phone-input\"\n * selectorClassName=\"country-selector\"\n * />\n * ```\n */\nexport const PhoneInput = forwardRef<PhoneInputRef, PhoneInputProps>(\n function PhoneInput(props, ref) {\n const {\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n inputClassName,\n selectorClassName,\n containerClassName,\n searchable = true,\n placeholder,\n disabled,\n readOnly,\n name,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n ...options\n } = props;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const optionRefs = useRef<Array<HTMLLIElement | null>>([]);\n const [highlightedIndex, setHighlightedIndex] = useState(0);\n const listboxId = useId();\n\n const {\n inputProps,\n countryButtonProps,\n country,\n filteredCountries,\n isOpen,\n isValid,\n searchQuery,\n setSearchQuery,\n setCountry,\n selectCountry,\n clear,\n openDropdown,\n closeDropdown,\n labels,\n } = usePhoneInput({\n value,\n defaultValue,\n onChange,\n onBlur,\n onFocus,\n ...options,\n });\n\n const hookInputRef = (inputProps as typeof inputProps & { ref?: Ref<HTMLInputElement> }).ref;\n const mergedInputRef = useCallback((element: HTMLInputElement | null) => {\n inputRef.current = element;\n\n if (typeof hookInputRef === 'function') {\n hookInputRef(element);\n } else if (hookInputRef && 'current' in hookInputRef) {\n (hookInputRef as MutableRefObject<HTMLInputElement | null>).current = element;\n }\n }, [hookInputRef]);\n\n // Focus the input\n const focus = useCallback(() => {\n inputRef.current?.focus();\n }, []);\n\n // Blur the input\n const blur = useCallback(() => {\n inputRef.current?.blur();\n }, []);\n\n // Handle country option click\n const handleCountryClick = useCallback((c: Country) => {\n selectCountry(c);\n setHighlightedIndex(0);\n }, [selectCountry]);\n\n // Handle country option keyboard navigation\n const handleCountryKeyDown = useCallback((e: React.KeyboardEvent, c: Country, index: number) => {\n switch (e.key) {\n case 'Enter':\n case ' ':\n e.preventDefault();\n selectCountry(c);\n setHighlightedIndex(0);\n break;\n case 'ArrowDown':\n e.preventDefault();\n if (index < filteredCountries.length - 1) {\n const nextIndex = index + 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n if (index > 0) {\n const nextIndex = index - 1;\n setHighlightedIndex(nextIndex);\n optionRefs.current[nextIndex]?.focus();\n }\n break;\n case 'Escape':\n e.preventDefault();\n closeDropdown();\n break;\n }\n }, [selectCountry, filteredCountries.length, closeDropdown]);\n\n useEffect(() => {\n if (filteredCountries.length === 0) {\n if (highlightedIndex !== 0) {\n setHighlightedIndex(0);\n }\n return;\n }\n\n if (highlightedIndex >= filteredCountries.length) {\n setHighlightedIndex(filteredCountries.length - 1);\n }\n }, [filteredCountries.length, highlightedIndex]);\n\n // Expose imperative methods\n useImperativeHandle(ref, () => ({\n focus,\n blur,\n clear,\n setCountry,\n getCountry: () => country,\n open: openDropdown,\n close: closeDropdown,\n }));\n\n // Render default UI\n return (\n <div className={containerClassName} data-valid={isValid}>\n {/* Country Selector Button */}\n <button\n {...countryButtonProps}\n type=\"button\"\n className={selectorClassName}\n disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n aria-controls={listboxId}\n >\n {country ? (\n <>\n <span className=\"phone-input-flag\">{country.flag}</span>\n <span className=\"phone-input-dial-code\">{country.dialCode}</span>\n </>\n ) : (\n <span className=\"phone-input-placeholder\">{labels.selectCountry}</span>\n )}\n <span className=\"phone-input-arrow\" aria-hidden=\"true\">\n {isOpen ? <ChevronUpIcon size={12} /> : <ChevronDownIcon size={12} />}\n </span>\n </button>\n\n {/* Phone Input */}\n <input\n {...inputProps}\n ref={mergedInputRef}\n id={id}\n name={name}\n className={inputClassName}\n placeholder={placeholder || inputProps.placeholder}\n disabled={disabled}\n readOnly={readOnly}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n />\n\n {/* Country Dropdown */}\n {isOpen && (\n <div className=\"phone-input-dropdown\">\n {/* Search Input */}\n {searchable && (\n <div className=\"phone-input-search\">\n <input\n type=\"text\"\n value={searchQuery}\n onChange={(e) => setSearchQuery(e.target.value)}\n placeholder={labels.countrySearchPlaceholder}\n autoFocus\n aria-controls={listboxId}\n aria-label={labels.searchCountriesAriaLabel}\n />\n </div>\n )}\n\n {/* Country List */}\n <ul className=\"phone-input-country-list\" id={listboxId} role=\"listbox\" aria-label={labels.countryOptionsAriaLabel}>\n {filteredCountries.map((c, index) => (\n <li\n key={c.code}\n ref={(element) => {\n optionRefs.current[index] = element;\n }}\n role=\"option\"\n aria-selected={c.code === country?.code}\n className={`phone-input-country-option ${\n c.code === country?.code ? 'selected' : ''\n } ${index === highlightedIndex ? 'highlighted' : ''}`}\n onClick={() => handleCountryClick(c)}\n onKeyDown={(e) => handleCountryKeyDown(e, c, index)}\n onMouseEnter={() => setHighlightedIndex(index)}\n tabIndex={index === highlightedIndex ? 0 : -1}\n >\n <span className=\"phone-input-flag\">{c.flag}</span>\n <span className=\"phone-input-country-name\">{getCountryDisplayName(c)}</span>\n <span className=\"phone-input-dial-code\">{c.dialCode}</span>\n </li>\n ))}\n {filteredCountries.length === 0 && (\n <li className=\"phone-input-no-results\">{labels.noCountriesFound}</li>\n )}\n </ul>\n </div>\n )}\n </div>\n );\n }\n);\n\nexport default PhoneInput;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@input-kit/phone",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Headless phone input with full world country codes, libphonenumber formatting, and TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,15 +44,6 @@
|
|
|
44
44
|
],
|
|
45
45
|
"author": "Harshit",
|
|
46
46
|
"license": "MIT",
|
|
47
|
-
"repository": {
|
|
48
|
-
"type": "git",
|
|
49
|
-
"url": "git+https://github.com/yourusername/input-kit.git",
|
|
50
|
-
"directory": "packages/phone"
|
|
51
|
-
},
|
|
52
|
-
"bugs": {
|
|
53
|
-
"url": "https://github.com/yourusername/input-kit/issues"
|
|
54
|
-
},
|
|
55
|
-
"homepage": "https://github.com/yourusername/input-kit/tree/main/packages/phone#readme",
|
|
56
47
|
"engines": {
|
|
57
48
|
"node": ">=18.0.0"
|
|
58
49
|
},
|