@nexusui/components
Version:
These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.
2 lines (1 loc) • 998 B
JavaScript
import{useMemo as e}from"react";import t from"lodash/tail";import r from"lodash/head";import n from"lodash/reduce";const a=({autoFormat:a,disableCountryCode:o,enableLongNumbers:i,innerValue:l,selectedCountryDialCode:m="",selectedCountryFormat:d="",lastSelectedCountry:s})=>e((()=>{const e=d,{current:u}=s,x=m,f=u.dialCode||"";let T;const c=((e,t)=>{let r;return e&&t?(r=t.split(" "),r.shift(),r=r.join(" ")):r=t,r})(o,e);let g=l?.replace(/\D/g,"");if(f&&f!==x&&g!==x&&g.startsWith(f)&&(g=g.replace(f,x)),!(h=g)||0===h.length)return o?"":"+";var h;if(g&&g.length<2||!c||!a)return o?g:`+${g}`;const p=n(c,((e,n)=>0===e.remainingText.length?e:"."!==n?{formattedText:e.formattedText+n,remainingText:e.remainingText}:{formattedText:e.formattedText+r(e.remainingText),remainingText:t(e.remainingText)}),{formattedText:"",remainingText:g.split("")});return T=i?p.formattedText+p.remainingText.join(""):p.formattedText,T.includes("(")&&!T.includes(")")&&(T+=")"),T}),[a,o,i,l,m,d,s]);export{a as default};