UNPKG

@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) 1.17 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("lodash/tail"),r=require("lodash/head"),n=require("lodash/reduce");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=a(t),o=a(r),l=a(n);exports.default=({autoFormat:t,disableCountryCode:r,enableLongNumbers:n,innerValue:a,selectedCountryDialCode:u="",selectedCountryFormat:d="",lastSelectedCountry:s})=>e.useMemo((()=>{const e=d,{current:f}=s,m=u,c=f.dialCode||"";let x;const T=((e,t)=>{let r;return e&&t?(r=t.split(" "),r.shift(),r=r.join(" ")):r=t,r})(r,e);let g=a?.replace(/\D/g,"");if(c&&c!==m&&g!==m&&g.startsWith(c)&&(g=g.replace(c,m)),!(h=g)||0===h.length)return r?"":"+";var h;if(g&&g.length<2||!T||!t)return r?g:`+${g}`;const p=l.default(T,((e,t)=>0===e.remainingText.length?e:"."!==t?{formattedText:e.formattedText+t,remainingText:e.remainingText}:{formattedText:e.formattedText+o.default(e.remainingText),remainingText:i.default(e.remainingText)}),{formattedText:"",remainingText:g.split("")});return x=n?p.formattedText+p.remainingText.join(""):p.formattedText,x.includes("(")&&!x.includes(")")&&(x+=")"),x}),[t,r,n,a,u,d,s]);