diff --git a/example/example.js b/example/example.js index e070e715c..c452ef407 100644 --- a/example/example.js +++ b/example/example.js @@ -1,3 +1,3 @@ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("prop-types"),require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["prop-types","react","react-dom"],t):"object"==typeof exports?exports.IntlTelInput=t(require("prop-types"),require("react"),require("react-dom")):e.IntlTelInput=t(e.PropTypes,e.React,e.ReactDOM)}(this,function(e,t,o){return function(e){function t(n){if(o[n])return o[n].exports;var i=o[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var o={};return t.m=e,t.c=o,t.i=function(e){return e},t.d=function(e,o,n){t.o(e,o)||Object.defineProperty(e,o,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=28)}([function(t,o){t.exports=e},function(e,o){e.exports=t},function(e,t,o){var n,i;!function(){"use strict";function o(){for(var e=[],t=0;t=0},retrieveLiIndex:function(e){if(!e)return-1;for(var t=e.parentNode.childNodes,o=0,n=0,i=t.length;n-1;)s.splice(t,1),i&&(t<=a&&a--,t<=l&&l--)}),this},has:function(e){return f(e,s)>-1},empty:function(){return s=[],this},disable:function(){return s=u=t=void 0,this},disabled:function(){return!s},lock:function(){return u=void 0,t||h.disable(),this},locked:function(){return!u},fireWith:function(e,t){return t=t||[],t=[e,t.slice?t.slice():t],!s||n&&!u||(i?u.push(t):d(t)),this},fire:function(){return h.fireWith(this,arguments),this},fired:function(){return!!n}};return h},b.Deferred=function(e){var t=[["resolve","done",b.Callbacks("once memory"),"resolved"],["reject","fail",b.Callbacks("once memory"),"rejected"],["notify","progress",b.Callbacks("memory")]],o="pending",n={state:function(){return o},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return b.Deferred(function(o){c(t,function(t,n){var r=t[0],a=e[n];i[t[1]](h(a)?function(){var e;try{e=a.apply(this,arguments)}catch(e){return void o.reject(e)}e&&h(e.promise)?e.promise().done(o.resolve).fail(o.reject).progress(o.notify):o["notify"!==r?"resolveWith":r+"With"](this===i?o:this,[e])}:o[r])}),e=null}).promise()},promise:function(e){return null!=e?p(e,n):n}},i={};return n.pipe=n.then,c(t,function(e,r){var a=e[2],l=e[3];n[e[1]]=a.add,l&&a.add(function(){o=l},t[1^r][2].disable,t[2][2].lock),i[e[0]]=a.fire,i[e[0]+"With"]=a.fireWith}),n.promise(i),e&&e.call(i,i),i},b.when=function(e){var t,o,n,i=0,r="array"===g(e)&&1===arguments.length?e:d.call(arguments),a=r.length,l=1!==a||e&&h(e.promise)?a:0,s=1===l?e:b.Deferred(),u=function(e,o,n){return function(i){o[e]=this,n[e]=arguments.length>1?d.call(arguments):i,n===t?s.notifyWith(o,n):--l||s.resolveWith(o,n)}};if(a>1)for(t=new Array(a),o=new Array(a),n=new Array(a);i1?t-1:0),n=1;nt,l=!r&&a?"-"+(i-1)+"px":"";this.listElement.style.top=l,this.listElement.setAttribute("class","country-list")}},{key:"setFlag",value:function(e){this.props.setFlag(e)}},{key:"appendListItem",value:function(e){var t=this,o=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=this.props.preferredCountries.length;return e.map(function(e,i){var r=o?i:i+n,l={country:!0,highlight:t.props.highlightedCountry===r,preferred:o},u=h()(l),d=o?"pref-":"";return s.a.createElement("li",{key:""+d+e.iso2,className:u,"data-dial-code":e.dialCode,"data-country-code":e.iso2,onMouseOver:t.props.isMobile?null:t.handleMouseOver,onClick:a(t.setFlag,e.iso2)},s.a.createElement("div",{ref:function(e){t.selectedFlag=e},className:"flag-box"},s.a.createElement("div",{ref:function(e){t.selectedFlagInner=e},className:"iti-flag "+e.iso2})),s.a.createElement("span",{className:"country-name"},e.name),s.a.createElement("span",{className:"dial-code"},"+",e.dialCode))})}},{key:"handleMouseOver",value:function(e){if(e.currentTarget.getAttribute("class").indexOf("country")>-1){var t=p.a.retrieveLiIndex(e.currentTarget);this.props.changeHighlightCountry(!0,t)}}},{key:"render",value:function(){var e=this,t="",o=this.props.preferredCountries,n=null,i=this.props.countries,r=h()({"country-list":!0,hide:!this.props.showDropdown}),a=null;return o.length&&(n=this.appendListItem(o,!0),a=s.a.createElement("div",{className:"divider"})),t=this.appendListItem(i),s.a.createElement("ul",{ref:function(t){e.listElement=t},className:r},n,a,t)}}]),t}(l.Component);m.propTypes={setFlag:d.a.func,countries:d.a.arrayOf(d.a.object),inputTop:d.a.number,inputOuterHeight:d.a.number,preferredCountries:d.a.arrayOf(d.a.object),highlightedCountry:d.a.number,changeHighlightCountry:d.a.func,showDropdown:d.a.bool,isMobile:d.a.bool},t.a=m},function(e,t,o){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=o(1),l=o.n(a),s=o(0),u=o.n(s),d=o(5),c=o.n(d),h=function(){function e(e,t){for(var o=0;o=4},o.wrapperClass={},o.autoCountry="",o.tempCountry="",o.startedLoadingAutoCountry=!1,o.deferreds=[],o.autoCountryDeferred=new p.a.Deferred,o.utilsScriptDeferred=new p.a.Deferred,o.isOpening=!1,o.isMobile="undefined"!=typeof navigator&&C.test(navigator.userAgent),o.preferredCountries=[],o.countries=[],o.countryCodes={},o.windowLoaded=!1,o.keys={UP:38,DOWN:40,ENTER:13,ESC:27,PLUS:43,A:65,Z:90,SPACE:32,TAB:9},o.query="",o.state={showDropdown:!1,highlightedCountry:0,value:e.value||e.defaultValue,disabled:e.disabled,readonly:!1,offsetTop:0,outerHeight:0,placeholder:"",title:"",countryCode:"us",dialCode:""},o.selectedCountryData={},o.addCountryCode=o.addCountryCode.bind(o),o.autoCountryLoaded=o.autoCountryLoaded.bind(o),o.getDialCode=o.getDialCode.bind(o),o.handleOnBlur=o.handleOnBlur.bind(o),o.handleSelectedFlagKeydown=o.handleSelectedFlagKeydown.bind(o),o.setInitialState=o.setInitialState.bind(o),o.setNumber=o.setNumber.bind(o),o.scrollTo=o.scrollTo.bind(o),o.updateDialCode=o.updateDialCode.bind(o),o.notifyPhoneNumberChange=o.notifyPhoneNumberChange.bind(o),o.isValidNumber=o.isValidNumber.bind(o),o.isUnknownNanp=o.isUnknownNanp.bind(o),o.initRequests=o.initRequests.bind(o),o.updateFlagFromNumber=o.updateFlagFromNumber.bind(o),o.updatePlaceholder=o.updatePlaceholder.bind(o),o.loadAutoCountry=o.loadAutoCountry.bind(o),o.loadUtils=o.loadUtils.bind(o),o.processCountryData=o.processCountryData.bind(o),o.getNumber=o.getNumber.bind(o),o.setFlag=o.setFlag.bind(o),o.clickSelectedFlag=o.clickSelectedFlag.bind(o),o.updateValFromNumber=o.updateValFromNumber.bind(o),o.handleWindowScroll=o.handleWindowScroll.bind(o),o.handleDocumentKeyDown=o.handleDocumentKeyDown.bind(o),o.handleDocumentClick=o.handleDocumentClick.bind(o),o.bindDocumentClick=o.bindDocumentClick.bind(o),o.unbindDocumentClick=o.unbindDocumentClick.bind(o),o.searchForCountry=o.searchForCountry.bind(o),o.handleEnterKey=o.handleEnterKey.bind(o),o.toggleDropdown=o.toggleDropdown.bind(o),o.handleUpDownKey=o.handleUpDownKey.bind(o),o.handleInputChange=o.handleInputChange.bind(o),o.changeHighlightCountry=o.changeHighlightCountry.bind(o),o.formatNumber=o.formatNumber.bind(o),o}return r(t,e),k(t,[{key:"componentDidMount",value:function(){var e=this;this.initialPlaceholder=this.props.placeholder,this.autoHideDialCode=this.props.autoHideDialCode,this.allowDropdown=this.props.allowDropdown,this.nationalMode=this.props.nationalMode,this.dropdownContainer="",this.nationalMode&&(this.autoHideDialCode=!1),this.props.separateDialCode&&(this.autoHideDialCode=!1,this.nationalMode=!1,this.allowDropdown=!0),this.processCountryData.call(this),this.tempCountry=this.getTempCountry(this.props.defaultCountry),"complete"===document.readyState?this.windowLoaded=!0:window.addEventListener("load",function(){e.windowLoaded=!0}),this.generateMarkup(),this.setInitialState(),this.initRequests(),this.deferreds.push(this.autoCountryDeferred.promise()),this.deferreds.push(this.utilsScriptDeferred.promise()),p.a.when(this.deferreds).done(function(){e.setInitialState()}),document.addEventListener("keydown",this.handleDocumentKeyDown)}},{key:"componentWillReceiveProps",value:function(e){this.props.value!==e.value&&this.setState({value:e.value}),this.props.disabled!==e.disabled&&this.setState({disabled:e.disabled})}},{key:"componentWillUpdate",value:function(e,t){t.showDropdown?(document.addEventListener("keydown",this.handleDocumentKeyDown),this.bindDocumentClick()):(document.removeEventListener("keydown",this.handleDocumentKeyDown),this.unbindDocumentClick())}},{key:"componentDidUpdate",value:function(e){this.props.value!==e.value&&this.updateFlagFromNumber(this.props.value)}},{key:"componentWillUnmount",value:function(){document.removeEventListener("keydown",this.handleDocumentKeyDown),window.removeEventListener("scroll",this.handleWindowScroll),this.unbindDocumentClick()}},{key:"getTempCountry",value:function(e){if("auto"===e)return"auto";var t=M.a.getCountryData(this.countries,e);return t.iso2||(t=this.props.preferredCountries.length>0?M.a.getCountryData(this.countries,this.props.preferredCountries[0]):g.a.getCountries()[0]),t.iso2}},{key:"setNumber",value:function(e,t){this.updateFlagFromNumber(e),this.updateValFromNumber(e,!t)}},{key:"setFlag",value:function(e,t){var o=this,n=this.selectedCountryData&&this.selectedCountryData.iso2?this.selectedCountryData:{};this.selectedCountryData=e?M.a.getCountryData(this.countries,e,!1,!1,this.props.noCountryDataHandler):{},this.selectedCountryData.iso2&&(this.defaultCountry=this.selectedCountryData.iso2);var i=e?this.selectedCountryData.name+": +"+this.selectedCountryData.dialCode:"Unknown",r=this.state.dialCode;this.props.separateDialCode&&(r=this.selectedCountryData.dialCode?"+"+this.selectedCountryData.dialCode:"",n.dialCode&&delete this.wrapperClass["iti-sdc-"+(n.dialCode.length+1)],r&&(this.wrapperClass["iti-sdc-"+r.length]=!0));var a=0;e&&"auto"!==e&&(a=this.preferredCountries.findIndex(function(t){return t.iso2===e}),a===-1&&(a=this.countries.findIndex(function(t){return t.iso2===e}),a===-1&&(a=0),a+=this.preferredCountries.length)),this.state.showDropdown&&this.tel.focus();var l=this.updateDialCode(this.selectedCountryData.dialCode,!t);this.setState({value:l,showDropdown:!1,highlightedCountry:a,countryCode:e,title:i,dialCode:r},function(){if(o.updatePlaceholder(),o.wrapperClass.active=!1,!t&&n.iso2!==e&&"function"==typeof o.props.onSelectFlag){var i=o.state.value;o.props.onSelectFlag(i,o.selectedCountryData)}})}},{key:"getExtension",value:function(e){return window.intlTelInputUtils?window.intlTelInputUtils.getExtension(this.getFullNumber(e),this.selectedCountryData.iso2):""}},{key:"getNumber",value:function(e,t){return window.intlTelInputUtils?window.intlTelInputUtils.formatNumber(this.getFullNumber(e),this.selectedCountryData.iso2,t):""}},{key:"getFullNumber",value:function(e){var t=this.props.separateDialCode?"+"+this.selectedCountryData.dialCode:"";return t+e}},{key:"getDialCode",value:function(e){var t="";if("+"===e.charAt(0))for(var o="",n=0,i=e.length;nt?e.substr(0,t):e}},{key:"removeEmptyDialCode",value:function(){var e=this.state.value,t="+"===e.charAt(0);if(t){var o=M.a.getNumeric(e);o&&this.selectedCountryData.dialCode!==o||this.setState({value:""})}}},{key:"handleUpDownKey",value:function(e){var t=this.flagDropDown.querySelectorAll(".highlight")[0],o=t?t.previousElementSibling:void 0,n=t?t.nextElementSibling:void 0,i=e===this.keys.UP?o:n;if(i){i.getAttribute("class").indexOf("divider")>-1&&(i=e===this.keys.UP?i.previousElementSibling:i.nextElementSibling),this.scrollTo(i);var r=M.a.retrieveLiIndex(i);this.setState({showDropdown:!0,highlightedCountry:r})}}},{key:"handleEnterKey",value:function(){var e=this,t=this.flagDropDown.querySelectorAll(".highlight")[0];if(t){var o=M.a.retrieveLiIndex(t),n=t.getAttribute("data-country-code");this.setState({showDropdown:!1,highlightedCountry:o,countryCode:n},function(){e.setFlag(e.state.countryCode),e.unbindDocumentClick()})}}},{key:"searchForCountry",value:function(e){for(var t=0,o=this.countries.length;t2&&void 0!==arguments[2]&&arguments[2];if(t&&window.intlTelInputUtils&&this.selectedCountryData){var i=this.props.separateDialCode||!this.nationalMode&&"+"===e.charAt(0)?window.intlTelInputUtils.numberFormat.INTERNATIONAL:window.intlTelInputUtils.numberFormat.NATIONAL;e=window.intlTelInputUtils.formatNumber(e,this.selectedCountryData.iso2,i)}e=this.beforeSetNumber(e),this.setState({showDropdown:!1,value:e},function(){n&&o.notifyPhoneNumberChange(o.state.value),o.unbindDocumentClick()})}},{key:"updateFlagFromNumber",value:function(e,t){e&&this.nationalMode&&this.selectedCountryData&&"1"===this.selectedCountryData.dialCode&&"+"!==e.charAt(0)&&("1"!==e.charAt(0)&&(e="1"+e),e="+"+e);var o=this.getDialCode(e),n=null;if(o){var i=this.countryCodes[M.a.getNumeric(o)],r=this.selectedCountryData&&i.indexOf(this.selectedCountryData.iso2)!==-1;if(!r||this.isUnknownNanp(e,o))for(var a=0;ar){t&&(d+=u);var c=n-a;o.scrollTop=d-c}}catch(e){}}},{key:"updateDialCode",value:function(e,t){var o=this.state.value;if(!e)return o;var n=o;if(e="+"+e,"+"===o.charAt(0)){var i=this.getDialCode(o);n=i?o.replace(i,e):e}else this.nationalMode||this.separateDialCode||(o?n=e+o:!t&&this.autoHideDialCode||(n=e));return n!==o&&this.notifyPhoneNumberChange(n),n}},{key:"generateMarkup",value:function(){this.wrapperClass["allow-dropdown"]=this.allowDropdown,this.wrapperClass["separate-dial-code"]=this.props.separateDialCode,this.isMobile&&this.props.useMobileFullscreenDropdown&&(M.a.addClass(document.querySelector("body"),"iti-mobile"),this.dropdownContainer="body",window.addEventListener("scroll",this.handleWindowScroll))}},{key:"handleSelectedFlagKeydown",value:function(e){this.state.showDropdown||e.which!==this.keys.UP&&e.which!==this.keys.DOWN&&e.which!==this.keys.SPACE&&e.which!==this.keys.ENTER||(e.preventDefault(),e.stopPropagation(),this.toggleDropdown(!0)),e.which===this.keys.TAB&&this.toggleDropdown(!1)}},{key:"isValidNumber",value:function(e){var t=M.a.trim(e),o=this.nationalMode?this.selectedCountryData.iso2:"";return!!window.intlTelInputUtils&&window.intlTelInputUtils.isValidNumber(t,o)}},{key:"formatFullNumber",value:function(e){return window.intlTelInputUtils?this.getNumber(e,window.intlTelInputUtils.numberFormat.INTERNATIONAL):e}},{key:"notifyPhoneNumberChange",value:function(e){if("function"==typeof this.props.onPhoneNumberChange){var t=this.formatFullNumber(e),o=this.isValidNumber(t);this.props.onPhoneNumberChange(o,e,this.selectedCountryData,t,this.getExtension(e))}}},{key:"beforeSetNumber",value:function(e){if(this.props.separateDialCode){var t=this.getDialCode(e);if(t){null!==this.selectedCountryData.areaCodes&&(t="+"+this.selectedCountryData.dialCode);var o=" "===e[t.length]||"-"===e[t.length]?t.length+1:t.length;e=e.substr(o)}}return this.cap(e)}},{key:"handleWindowScroll",value:function(){var e=this;this.setState({showDropdown:!1},function(){window.removeEventListener("scroll",e.handleWindowScroll)})}},{key:"handleDocumentKeyDown",value:function(e){var t=this,o=void 0;e.preventDefault(),e.which===this.keys.UP||e.which===this.keys.DOWN?this.handleUpDownKey(e.which):e.which===this.keys.ENTER?this.handleEnterKey():e.which===this.keys.ESC?this.setState({showDropdown:!1}):(e.which>=this.keys.A&&e.which<=this.keys.Z||e.which===this.keys.SPACE)&&(o&&clearTimeout(o),this.query||(this.query=""),this.query+=String.fromCharCode(e.which),this.searchForCountry(this.query),o=setTimeout(function(){t.query=""},1e3))}},{key:"handleDocumentClick",value:function(e){(null===e.target.getAttribute("class")||e.target.getAttribute("class")&&e.target.getAttribute("class").indexOf("country")===-1)&&(this.isOpening=!1),this.isOpening||this.toggleDropdown(!1),this.isOpening=!1}},{key:"handleInputChange",value:function(e){var t=this,o=this.props.format?this.formatNumber(e.target.value):e.target.value;void 0!==this.props.value?(this.updateFlagFromNumber(o),this.notifyPhoneNumberChange(o)):this.setState({value:o},function(){t.updateFlagFromNumber(o),t.notifyPhoneNumberChange(o)})}},{key:"changeHighlightCountry",value:function(e,t){this.setState({showDropdown:e,highlightedCountry:t})}},{key:"loadUtils",value:function(){var e=this;if(window.intlTelInputUtils)return void this.utilsScriptDeferred.resolve();var t=new XMLHttpRequest;t.open("GET",this.props.utilsScript,!0),t.onload=function(){if(t.status>=200&&t.status<400){var o=t.responseText;if(o&&!document.getElementById("intlTelInputUtils")){var n=document.getElementsByTagName("body")[0],i=document.createElement("script");i.id="intlTelInputUtils",i.text=o,n.appendChild(i)}e.utilsScriptDeferred.resolve()}},t.send()}},{key:"autoCountryLoaded",value:function(){"auto"===this.tempCountry&&(this.tempCountry=this.autoCountry,this.autoCountryDeferred.resolve())}},{key:"render",value:function(){this.wrapperClass[this.props.css[0]]=!0;var e=this.props.css[1],t=Object.assign({},this.props.style||{});this.state.showDropdown&&(this.wrapperClass.expanded=!0);var o=c()(this.wrapperClass),n=this.selectedCountryData?this.selectedCountryData.name+": +"+this.selectedCountryData.dialCode:"Unknown",i=void 0!==this.props.value?this.props.value:this.state.value;return l.a.createElement("div",{className:o,style:t},l.a.createElement(b.a,{refCallback:this.setFlagDropdownRef,allowDropdown:this.allowDropdown,dropdownContainer:this.dropdownContainer,separateDialCode:this.props.separateDialCode,dialCode:this.state.dialCode,clickSelectedFlag:this.clickSelectedFlag,setFlag:this.setFlag,countryCode:this.state.countryCode,isMobile:this.isMobile,handleSelectedFlagKeydown:this.handleSelectedFlagKeydown,changeHighlightCountry:this.changeHighlightCountry,countries:this.countries,showDropdown:this.state.showDropdown,inputTop:this.state.offsetTop,inputOuterHeight:this.state.outerHeight,preferredCountries:this.preferredCountries,highlightedCountry:this.state.highlightedCountry,titleTip:n}),l.a.createElement(y.a,{refCallback:this.setTelRef,handleInputChange:this.handleInputChange,handleOnBlur:this.handleOnBlur,className:e,disabled:this.state.disabled,readonly:this.state.readonly,fieldName:this.props.fieldName,fieldId:this.props.fieldId,value:i,placeholder:this.state.placeholder,autoFocus:this.props.autoFocus,autoComplete:this.props.autoComplete,inputProps:this.props.telInputProps}))}}]),t}(a.Component);O.propTypes={css:u.a.arrayOf(u.a.string),fieldName:u.a.string,fieldId:u.a.string,value:u.a.string,defaultValue:u.a.string,countriesData:u.a.arrayOf(u.a.array),allowDropdown:u.a.bool,autoHideDialCode:u.a.bool,autoPlaceholder:u.a.bool,customPlaceholder:u.a.func,excludeCountries:u.a.arrayOf(u.a.string),formatOnInit:u.a.bool,separateDialCode:u.a.bool,defaultCountry:u.a.string,geoIpLookup:u.a.func,nationalMode:u.a.bool,numberType:u.a.string,noCountryDataHandler:u.a.func,onlyCountries:u.a.arrayOf(u.a.string),preferredCountries:u.a.arrayOf(u.a.string),utilsScript:u.a.string,onPhoneNumberChange:u.a.func,onPhoneNumberBlur:u.a.func,onSelectFlag:u.a.func,disabled:u.a.bool,placeholder:u.a.string,autoFocus:u.a.bool,autoComplete:u.a.string,style:m.a,useMobileFullscreenDropdown:u.a.bool,telInputProps:u.a.object,format:u.a.bool},O.defaultProps={css:["intl-tel-input",""],fieldName:"",fieldId:"",defaultValue:"",countriesData:null,allowDropdown:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,excludeCountries:[],formatOnInit:!0,separateDialCode:!1,defaultCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",noCountryDataHandler:null,onlyCountries:[],preferredCountries:["us","gb"],utilsScript:"",onPhoneNumberChange:null,onPhoneNumberBlur:null,onSelectFlag:null,disabled:!1,autoFocus:!1,useMobileFullscreenDropdown:!0,autoComplete:"off",telInputProps:{},format:!1},t.default=O},function(e,t,o){"use strict";function n(){}function i(e){try{return e.then}catch(e){return b=e,y}}function r(e,t){try{return e(t)}catch(e){return b=e,y}}function a(e,t,o){try{e(t,o)}catch(e){return b=e,y}}function l(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._45=0,this._81=0,this._65=null,this._54=null,e!==n&&m(e,this)}function s(e,t,o){return new e.constructor(function(i,r){var a=new l(n);a.then(i,r),u(e,new f(t,o,a))})}function u(e,t){for(;3===e._81;)e=e._65;return l._10&&l._10(e),0===e._81?0===e._45?(e._45=1,void(e._54=t)):1===e._45?(e._45=2,void(e._54=[e._54,t])):void e._54.push(t):void d(e,t)}function d(e,t){g(function(){var o=1===e._81?t.onFulfilled:t.onRejected;if(null===o)return void(1===e._81?c(t.promise,e._65):h(t.promise,e._65));var n=r(o,e._65);n===y?h(t.promise,b):c(t.promise,n)})}function c(e,t){if(t===e)return h(e,new TypeError("A promise cannot be resolved with itself."));if(t&&("object"==typeof t||"function"==typeof t)){var o=i(t);if(o===y)return h(e,b);if(o===e.then&&t instanceof l)return e._81=3,e._65=t,void p(e);if("function"==typeof o)return void m(o.bind(t),e)}e._81=1,e._65=t,p(e)}function h(e,t){e._81=2,e._65=t,l._97&&l._97(e,t),p(e)}function p(e){if(1===e._45&&(u(e,e._54),e._54=null),2===e._45){for(var t=0;t1)for(var o=1;od){for(var t=0,o=l.length-u;t-1?t:e}function p(e,t){t=t||{};var o=t.body;if(e instanceof p){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new i(e.headers)),this.method=e.method,this.mode=e.mode,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new i(t.headers)),this.method=h(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function f(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var o=e.split("="),n=o.shift().replace(/\+/g," "),i=o.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(i))}}),t}function m(e){var t=new i;return e.split(/\r?\n/).forEach(function(e){var o=e.split(":"),n=o.shift().trim();if(n){var i=o.join(":").trim();t.append(n,i)}}),t}function g(e,t){t||(t={}),this.type="default",this.status="status"in t?t.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new i(t.headers),this.url=t.url||"",this._initBody(e)}if(!e.fetch){var b={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(b.arrayBuffer)var y=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],M=function(e){return e&&DataView.prototype.isPrototypeOf(e)},S=ArrayBuffer.isView||function(e){return e&&y.indexOf(Object.prototype.toString.call(e))>-1};i.prototype.append=function(e,n){e=t(e),n=o(n);var i=this.map[e];this.map[e]=i?i+","+n:n},i.prototype.delete=function(e){delete this.map[t(e)]},i.prototype.get=function(e){return e=t(e),this.has(e)?this.map[e]:null},i.prototype.has=function(e){return this.map.hasOwnProperty(t(e))},i.prototype.set=function(e,n){this.map[t(e)]=o(n)},i.prototype.forEach=function(e,t){for(var o in this.map)this.map.hasOwnProperty(o)&&e.call(t,this.map[o],o,this)},i.prototype.keys=function(){var e=[];return this.forEach(function(t,o){e.push(o)}),n(e)},i.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),n(e)},i.prototype.entries=function(){var e=[];return this.forEach(function(t,o){e.push([o,t])}),n(e)},b.iterable&&(i.prototype[Symbol.iterator]=i.prototype.entries);var k=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},c.call(p.prototype),c.call(g.prototype),g.prototype.clone=function(){return new g(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new i(this.headers),url:this.url})},g.error=function(){var e=new g(null,{status:0,statusText:""});return e.type="error",e};var C=[301,302,303,307,308];g.redirect=function(e,t){if(C.indexOf(t)===-1)throw new RangeError("Invalid status code");return new g(null,{status:t,headers:{location:e}})},e.Headers=i,e.Request=p,e.Response=g,e.fetch=function(e,t){return new Promise(function(o,n){var i=new p(e,t),r=new XMLHttpRequest;r.onload=function(){var e={status:r.status,statusText:r.statusText,headers:m(r.getAllResponseHeaders()||"")};e.url="responseURL"in r?r.responseURL:e.headers.get("X-Request-URL");var t="response"in r?r.response:r.responseText;o(new g(t,e))},r.onerror=function(){n(new TypeError("Network request failed"))},r.ontimeout=function(){n(new TypeError("Network request failed"))},r.open(i.method,i.url,!0),"include"===i.credentials&&(r.withCredentials=!0),"responseType"in r&&b.blob&&(r.responseType="blob"),i.headers.forEach(function(e,t){r.setRequestHeader(t,e)}),r.send("undefined"==typeof i._bodyInit?null:i._bodyInit)})},e.fetch.polyfill=!0}}("undefined"!=typeof self?self:this)},function(e,t,o){o(17),e.exports=o(18)}])}); \ No newline at end of file +},function(e,t,o){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=o(1),l=o.n(a),s=o(0),u=o.n(s),d=o(2),c=o.n(d),h=o(10),p=o.n(h),f=o(9),m=o.n(f),g=o(3),b=o(6),y=o(7),M=o(4),S=o(8),k=(o.n(S),function(){function e(e,t){for(var o=0;o=4},o.wrapperClass={},o.autoCountry="",o.tempCountry="",o.startedLoadingAutoCountry=!1,o.deferreds=[],o.autoCountryDeferred=new p.a.Deferred,o.utilsScriptDeferred=new p.a.Deferred,o.isOpening=!1,o.isMobile="undefined"!=typeof navigator&&C.test(navigator.userAgent),o.preferredCountries=[],o.countries=[],o.countryCodes={},o.windowLoaded=!1,o.keys={UP:38,DOWN:40,ENTER:13,ESC:27,PLUS:43,A:65,Z:90,SPACE:32,TAB:9},o.query="",o.state={showDropdown:!1,highlightedCountry:0,value:e.value||e.defaultValue,disabled:e.disabled,readonly:!1,offsetTop:0,outerHeight:0,placeholder:"",title:"",countryCode:"us",dialCode:""},o.selectedCountryData={},o.addCountryCode=o.addCountryCode.bind(o),o.autoCountryLoaded=o.autoCountryLoaded.bind(o),o.getDialCode=o.getDialCode.bind(o),o.handleOnBlur=o.handleOnBlur.bind(o),o.handleSelectedFlagKeydown=o.handleSelectedFlagKeydown.bind(o),o.setInitialState=o.setInitialState.bind(o),o.setNumber=o.setNumber.bind(o),o.scrollTo=o.scrollTo.bind(o),o.updateDialCode=o.updateDialCode.bind(o),o.notifyPhoneNumberChange=o.notifyPhoneNumberChange.bind(o),o.isValidNumber=o.isValidNumber.bind(o),o.isUnknownNanp=o.isUnknownNanp.bind(o),o.initRequests=o.initRequests.bind(o),o.updateFlagFromNumber=o.updateFlagFromNumber.bind(o),o.updatePlaceholder=o.updatePlaceholder.bind(o),o.loadAutoCountry=o.loadAutoCountry.bind(o),o.loadUtils=o.loadUtils.bind(o),o.processCountryData=o.processCountryData.bind(o),o.getNumber=o.getNumber.bind(o),o.setFlag=o.setFlag.bind(o),o.clickSelectedFlag=o.clickSelectedFlag.bind(o),o.updateValFromNumber=o.updateValFromNumber.bind(o),o.handleWindowScroll=o.handleWindowScroll.bind(o),o.handleDocumentKeyDown=o.handleDocumentKeyDown.bind(o),o.handleDocumentClick=o.handleDocumentClick.bind(o),o.bindDocumentClick=o.bindDocumentClick.bind(o),o.unbindDocumentClick=o.unbindDocumentClick.bind(o),o.searchForCountry=o.searchForCountry.bind(o),o.handleEnterKey=o.handleEnterKey.bind(o),o.toggleDropdown=o.toggleDropdown.bind(o),o.handleUpDownKey=o.handleUpDownKey.bind(o),o.handleInputChange=o.handleInputChange.bind(o),o.changeHighlightCountry=o.changeHighlightCountry.bind(o),o.formatNumber=o.formatNumber.bind(o),o}return r(t,e),k(t,[{key:"componentDidMount",value:function(){var e=this;this.initialPlaceholder=this.props.placeholder,this.autoHideDialCode=this.props.autoHideDialCode,this.allowDropdown=this.props.allowDropdown,this.nationalMode=this.props.nationalMode,this.dropdownContainer="",this.nationalMode&&(this.autoHideDialCode=!1),this.props.separateDialCode&&(this.autoHideDialCode=!1,this.nationalMode=!1,this.allowDropdown=!0),this.processCountryData.call(this),this.tempCountry=this.getTempCountry(this.props.defaultCountry),"complete"===document.readyState?this.windowLoaded=!0:window.addEventListener("load",function(){e.windowLoaded=!0}),this.generateMarkup(),this.setInitialState(),this.initRequests(),this.deferreds.push(this.autoCountryDeferred.promise()),this.deferreds.push(this.utilsScriptDeferred.promise()),p.a.when(this.deferreds).done(function(){e.setInitialState()}),document.addEventListener("keydown",this.handleDocumentKeyDown)}},{key:"componentWillReceiveProps",value:function(e){this.props.value!==e.value&&this.setState({value:e.value}),this.props.disabled!==e.disabled&&this.setState({disabled:e.disabled})}},{key:"componentWillUpdate",value:function(e,t){t.showDropdown?(document.addEventListener("keydown",this.handleDocumentKeyDown),this.bindDocumentClick()):(document.removeEventListener("keydown",this.handleDocumentKeyDown),this.unbindDocumentClick())}},{key:"componentDidUpdate",value:function(e){this.props.value!==e.value&&this.updateFlagFromNumber(this.props.value)}},{key:"componentWillUnmount",value:function(){document.removeEventListener("keydown",this.handleDocumentKeyDown),window.removeEventListener("scroll",this.handleWindowScroll),this.unbindDocumentClick()}},{key:"getTempCountry",value:function(e){if("auto"===e)return"auto";var t=M.a.getCountryData(this.countries,e);return t.iso2||(t=this.props.preferredCountries.length>0?M.a.getCountryData(this.countries,this.props.preferredCountries[0]):g.a.getCountries()[0]),t.iso2}},{key:"setNumber",value:function(e,t){this.updateFlagFromNumber(e),this.updateValFromNumber(e,!t)}},{key:"setFlag",value:function(e,t){var o=this,n=this.selectedCountryData&&this.selectedCountryData.iso2?this.selectedCountryData:{};this.selectedCountryData=e?M.a.getCountryData(this.countries,e,!1,!1,this.props.noCountryDataHandler):{},this.selectedCountryData.iso2&&(this.defaultCountry=this.selectedCountryData.iso2);var i=e?this.selectedCountryData.name+": +"+this.selectedCountryData.dialCode:"Unknown",r=this.state.dialCode;this.props.separateDialCode&&(r=this.selectedCountryData.dialCode?"+"+this.selectedCountryData.dialCode:"",n.dialCode&&delete this.wrapperClass["iti-sdc-"+(n.dialCode.length+1)],r&&(this.wrapperClass["iti-sdc-"+r.length]=!0));var a=0;e&&"auto"!==e&&(a=this.preferredCountries.findIndex(function(t){return t.iso2===e}),a===-1&&(a=this.countries.findIndex(function(t){return t.iso2===e}),a===-1&&(a=0),a+=this.preferredCountries.length)),this.state.showDropdown&&this.tel.focus();var l=this.updateDialCode(this.selectedCountryData.dialCode,!t);this.setState({value:l,showDropdown:!1,highlightedCountry:a,countryCode:e,title:i,dialCode:r},function(){if(o.updatePlaceholder(),o.wrapperClass.active=!1,!t&&n.iso2!==e&&"function"==typeof o.props.onSelectFlag){var i=o.state.value;o.props.onSelectFlag(i,o.selectedCountryData)}})}},{key:"getExtension",value:function(e){return window.intlTelInputUtils?window.intlTelInputUtils.getExtension(this.getFullNumber(e),this.selectedCountryData.iso2):""}},{key:"getNumber",value:function(e,t){return window.intlTelInputUtils?window.intlTelInputUtils.formatNumber(this.getFullNumber(e),this.selectedCountryData.iso2,t):""}},{key:"getFullNumber",value:function(e){var t=this.props.separateDialCode?"+"+this.selectedCountryData.dialCode:"";return t+e}},{key:"getDialCode",value:function(e){var t="";if("+"===e.charAt(0))for(var o="",n=0,i=e.length;nt?e.substr(0,t):e}},{key:"removeEmptyDialCode",value:function(){var e=this.state.value,t="+"===e.charAt(0);if(t){var o=M.a.getNumeric(e);o&&this.selectedCountryData.dialCode!==o||this.setState({value:""})}}},{key:"handleUpDownKey",value:function(e){var t=this.flagDropDown.querySelectorAll(".highlight")[0],o=t?t.previousElementSibling:void 0,n=t?t.nextElementSibling:void 0,i=e===this.keys.UP?o:n;if(i){i.getAttribute("class").indexOf("divider")>-1&&(i=e===this.keys.UP?i.previousElementSibling:i.nextElementSibling),this.scrollTo(i);var r=M.a.retrieveLiIndex(i);this.setState({showDropdown:!0,highlightedCountry:r})}}},{key:"handleEnterKey",value:function(){var e=this,t=this.flagDropDown.querySelectorAll(".highlight")[0];if(t){var o=M.a.retrieveLiIndex(t),n=t.getAttribute("data-country-code");this.setState({showDropdown:!1,highlightedCountry:o,countryCode:n},function(){e.setFlag(e.state.countryCode),e.unbindDocumentClick()})}}},{key:"searchForCountry",value:function(e){for(var t=0,o=this.countries.length;t2&&void 0!==arguments[2]&&arguments[2];if(t&&window.intlTelInputUtils&&this.selectedCountryData){var i=this.props.separateDialCode||!this.nationalMode&&"+"===e.charAt(0)?window.intlTelInputUtils.numberFormat.INTERNATIONAL:window.intlTelInputUtils.numberFormat.NATIONAL;e=window.intlTelInputUtils.formatNumber(e,this.selectedCountryData.iso2,i)}e=this.beforeSetNumber(e),this.setState({showDropdown:!1,value:e},function(){n&&o.notifyPhoneNumberChange(o.state.value),o.unbindDocumentClick()})}},{key:"updateFlagFromNumber",value:function(e,t){e&&this.nationalMode&&this.selectedCountryData&&"1"===this.selectedCountryData.dialCode&&"+"!==e.charAt(0)&&("1"!==e.charAt(0)&&(e="1"+e),e="+"+e);var o=this.getDialCode(e),n=null;if(o){var i=this.countryCodes[M.a.getNumeric(o)],r=this.selectedCountryData&&i.indexOf(this.selectedCountryData.iso2)!==-1;if(!r||this.isUnknownNanp(e,o))for(var a=0;ar){t&&(d+=u);var c=n-a;o.scrollTop=d-c}}catch(e){}}},{key:"updateDialCode",value:function(e,t){var o=this.state.value;if(!e)return o;var n=o;if(e="+"+e,"+"===o.charAt(0)){var i=this.getDialCode(o);n=i?o.replace(i,e):e}else this.nationalMode||this.separateDialCode||(o?n=e+o:!t&&this.autoHideDialCode||(n=e));return n!==o&&this.notifyPhoneNumberChange(n),n}},{key:"generateMarkup",value:function(){this.wrapperClass["allow-dropdown"]=this.allowDropdown,this.wrapperClass["separate-dial-code"]=this.props.separateDialCode,this.isMobile&&this.props.useMobileFullscreenDropdown&&(M.a.addClass(document.querySelector("body"),"iti-mobile"),this.dropdownContainer="body",window.addEventListener("scroll",this.handleWindowScroll))}},{key:"handleSelectedFlagKeydown",value:function(e){this.state.showDropdown||e.which!==this.keys.UP&&e.which!==this.keys.DOWN&&e.which!==this.keys.SPACE&&e.which!==this.keys.ENTER||(e.preventDefault(),e.stopPropagation(),this.toggleDropdown(!0)),e.which===this.keys.TAB&&this.toggleDropdown(!1)}},{key:"isValidNumber",value:function(e){var t=M.a.trim(e),o=this.nationalMode?this.selectedCountryData.iso2:"";return!!window.intlTelInputUtils&&window.intlTelInputUtils.isValidNumber(t,o)}},{key:"formatFullNumber",value:function(e){return window.intlTelInputUtils?this.getNumber(e,window.intlTelInputUtils.numberFormat.INTERNATIONAL):e}},{key:"notifyPhoneNumberChange",value:function(e){if("function"==typeof this.props.onPhoneNumberChange){var t=this.formatFullNumber(e),o=this.isValidNumber(t);this.props.onPhoneNumberChange(o,e,this.selectedCountryData,t,this.getExtension(e))}}},{key:"beforeSetNumber",value:function(e){if(this.props.separateDialCode){var t=this.getDialCode(e);if(t){null!==this.selectedCountryData.areaCodes&&(t="+"+this.selectedCountryData.dialCode);var o=" "===e[t.length]||"-"===e[t.length]?t.length+1:t.length;e=e.substr(o)}}return this.cap(e)}},{key:"handleWindowScroll",value:function(){var e=this;this.setState({showDropdown:!1},function(){window.removeEventListener("scroll",e.handleWindowScroll)})}},{key:"handleDocumentKeyDown",value:function(e){var t=this,o=void 0;e.preventDefault(),e.which===this.keys.UP||e.which===this.keys.DOWN?this.handleUpDownKey(e.which):e.which===this.keys.ENTER?this.handleEnterKey():e.which===this.keys.ESC?this.setState({showDropdown:!1}):(e.which>=this.keys.A&&e.which<=this.keys.Z||e.which===this.keys.SPACE)&&(o&&clearTimeout(o),this.query||(this.query=""),this.query+=String.fromCharCode(e.which),this.searchForCountry(this.query),o=setTimeout(function(){t.query=""},1e3))}},{key:"handleDocumentClick",value:function(e){(null===e.target.getAttribute("class")||e.target.getAttribute("class")&&e.target.getAttribute("class").indexOf("country")===-1)&&(this.isOpening=!1),this.isOpening||this.toggleDropdown(!1),this.isOpening=!1}},{key:"handleInputChange",value:function(e){var t=this,o=this.props.format?this.formatNumber(e.target.value):e.target.value;void 0!==this.props.value?(this.updateFlagFromNumber(o),this.notifyPhoneNumberChange(o)):this.setState({value:o},function(){t.updateFlagFromNumber(o),t.notifyPhoneNumberChange(o)})}},{key:"changeHighlightCountry",value:function(e,t){this.setState({showDropdown:e,highlightedCountry:t})}},{key:"loadUtils",value:function(){var e=this;if(window.intlTelInputUtils)return void this.utilsScriptDeferred.resolve();var t=new XMLHttpRequest;t.open("GET",this.props.utilsScript,!0),t.onload=function(){if(t.status>=200&&t.status<400){var o=t.responseText;if(o&&!document.getElementById("intlTelInputUtils")){var n=document.getElementsByTagName("body")[0],i=document.createElement("script");i.id="intlTelInputUtils",i.text=o,n.appendChild(i)}e.utilsScriptDeferred.resolve()}},t.send()}},{key:"autoCountryLoaded",value:function(){"auto"===this.tempCountry&&(this.tempCountry=this.autoCountry,this.autoCountryDeferred.resolve())}},{key:"render",value:function(){this.wrapperClass[this.props.css[0]]=!0;var e=this.props.css[1],t=Object.assign({},this.props.style||{});this.state.showDropdown&&(this.wrapperClass.expanded=!0);var o=c()(this.wrapperClass),n=this.selectedCountryData?this.selectedCountryData.name+": +"+this.selectedCountryData.dialCode:"Unknown",i=void 0!==this.props.value?this.props.value:this.state.value;return l.a.createElement("div",{className:o,style:t},l.a.createElement(b.a,{refCallback:this.setFlagDropdownRef,allowDropdown:this.allowDropdown,dropdownContainer:this.dropdownContainer,separateDialCode:this.props.separateDialCode,dialCode:this.state.dialCode,clickSelectedFlag:this.clickSelectedFlag,setFlag:this.setFlag,countryCode:this.state.countryCode,isMobile:this.isMobile,handleSelectedFlagKeydown:this.handleSelectedFlagKeydown,changeHighlightCountry:this.changeHighlightCountry,countries:this.countries,showDropdown:this.state.showDropdown,inputTop:this.state.offsetTop,inputOuterHeight:this.state.outerHeight,preferredCountries:this.preferredCountries,highlightedCountry:this.state.highlightedCountry,titleTip:n}),l.a.createElement(y.a,{refCallback:this.setTelRef,handleInputChange:this.handleInputChange,handleOnBlur:this.handleOnBlur,className:e,disabled:this.state.disabled,readonly:this.state.readonly,fieldName:this.props.fieldName,fieldId:this.props.fieldId,value:i,placeholder:this.state.placeholder,autoFocus:this.props.autoFocus,autoComplete:this.props.autoComplete,inputProps:this.props.telInputProps}))}}]),t}(a.Component);O.propTypes={css:u.a.arrayOf(u.a.string),fieldName:u.a.string,fieldId:u.a.string,value:u.a.string,defaultValue:u.a.string,countriesData:u.a.arrayOf(u.a.array),allowDropdown:u.a.bool,autoHideDialCode:u.a.bool,autoPlaceholder:u.a.bool,customPlaceholder:u.a.func,excludeCountries:u.a.arrayOf(u.a.string),formatOnInit:u.a.bool,separateDialCode:u.a.bool,defaultCountry:u.a.string,geoIpLookup:u.a.func,nationalMode:u.a.bool,numberType:u.a.string,noCountryDataHandler:u.a.func,onlyCountries:u.a.arrayOf(u.a.string),preferredCountries:u.a.arrayOf(u.a.string),utilsScript:u.a.string,onPhoneNumberChange:u.a.func,onPhoneNumberBlur:u.a.func,onSelectFlag:u.a.func,disabled:u.a.bool,placeholder:u.a.string,autoFocus:u.a.bool,autoComplete:u.a.string,style:m.a,useMobileFullscreenDropdown:u.a.bool,telInputProps:u.a.object,format:u.a.bool},O.defaultProps={css:["intl-tel-input",""],fieldName:"",fieldId:"",defaultValue:"",countriesData:null,allowDropdown:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,excludeCountries:[],formatOnInit:!0,separateDialCode:!1,defaultCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",noCountryDataHandler:null,onlyCountries:[],preferredCountries:["us","gb"],utilsScript:"",onPhoneNumberChange:null,onPhoneNumberBlur:null,onSelectFlag:null,disabled:!1,autoFocus:!1,useMobileFullscreenDropdown:!0,autoComplete:"off",telInputProps:{},format:!1},t.default=O},function(e,t,o){"use strict";function n(){}function i(e){try{return e.then}catch(e){return b=e,y}}function r(e,t){try{return e(t)}catch(e){return b=e,y}}function a(e,t,o){try{e(t,o)}catch(e){return b=e,y}}function l(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._45=0,this._81=0,this._65=null,this._54=null,e!==n&&m(e,this)}function s(e,t,o){return new e.constructor(function(i,r){var a=new l(n);a.then(i,r),u(e,new f(t,o,a))})}function u(e,t){for(;3===e._81;)e=e._65;return l._10&&l._10(e),0===e._81?0===e._45?(e._45=1,void(e._54=t)):1===e._45?(e._45=2,void(e._54=[e._54,t])):void e._54.push(t):void d(e,t)}function d(e,t){g(function(){var o=1===e._81?t.onFulfilled:t.onRejected;if(null===o)return void(1===e._81?c(t.promise,e._65):h(t.promise,e._65));var n=r(o,e._65);n===y?h(t.promise,b):c(t.promise,n)})}function c(e,t){if(t===e)return h(e,new TypeError("A promise cannot be resolved with itself."));if(t&&("object"==typeof t||"function"==typeof t)){var o=i(t);if(o===y)return h(e,b);if(o===e.then&&t instanceof l)return e._81=3,e._65=t,void p(e);if("function"==typeof o)return void m(o.bind(t),e)}e._81=1,e._65=t,p(e)}function h(e,t){e._81=2,e._65=t,l._97&&l._97(e,t),p(e)}function p(e){if(1===e._45&&(u(e,e._54),e._54=null),2===e._45){for(var t=0;td){for(var t=0,o=l.length-u;t1)for(var o=1;o-1?t:e}function p(e,t){t=t||{};var o=t.body;if(e instanceof p){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new i(e.headers)),this.method=e.method,this.mode=e.mode,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new i(t.headers)),this.method=h(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function f(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var o=e.split("="),n=o.shift().replace(/\+/g," "),i=o.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(i))}}),t}function m(e){var t=new i;return e.split(/\r?\n/).forEach(function(e){var o=e.split(":"),n=o.shift().trim();if(n){var i=o.join(":").trim();t.append(n,i)}}),t}function g(e,t){t||(t={}),this.type="default",this.status="status"in t?t.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new i(t.headers),this.url=t.url||"",this._initBody(e)}if(!e.fetch){var b={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(b.arrayBuffer)var y=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],M=function(e){return e&&DataView.prototype.isPrototypeOf(e)},S=ArrayBuffer.isView||function(e){return e&&y.indexOf(Object.prototype.toString.call(e))>-1};i.prototype.append=function(e,n){e=t(e),n=o(n);var i=this.map[e];this.map[e]=i?i+","+n:n},i.prototype.delete=function(e){delete this.map[t(e)]},i.prototype.get=function(e){return e=t(e),this.has(e)?this.map[e]:null},i.prototype.has=function(e){return this.map.hasOwnProperty(t(e))},i.prototype.set=function(e,n){this.map[t(e)]=o(n)},i.prototype.forEach=function(e,t){for(var o in this.map)this.map.hasOwnProperty(o)&&e.call(t,this.map[o],o,this)},i.prototype.keys=function(){var e=[];return this.forEach(function(t,o){e.push(o)}),n(e)},i.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),n(e)},i.prototype.entries=function(){var e=[];return this.forEach(function(t,o){e.push([o,t])}),n(e)},b.iterable&&(i.prototype[Symbol.iterator]=i.prototype.entries);var k=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},c.call(p.prototype),c.call(g.prototype),g.prototype.clone=function(){return new g(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new i(this.headers),url:this.url})},g.error=function(){var e=new g(null,{status:0,statusText:""});return e.type="error",e};var C=[301,302,303,307,308];g.redirect=function(e,t){if(C.indexOf(t)===-1)throw new RangeError("Invalid status code");return new g(null,{status:t,headers:{location:e}})},e.Headers=i,e.Request=p,e.Response=g,e.fetch=function(e,t){return new Promise(function(o,n){var i=new p(e,t),r=new XMLHttpRequest;r.onload=function(){var e={status:r.status,statusText:r.statusText,headers:m(r.getAllResponseHeaders()||"")};e.url="responseURL"in r?r.responseURL:e.headers.get("X-Request-URL");var t="response"in r?r.response:r.responseText;o(new g(t,e))},r.onerror=function(){n(new TypeError("Network request failed"))},r.ontimeout=function(){n(new TypeError("Network request failed"))},r.open(i.method,i.url,!0),"include"===i.credentials&&(r.withCredentials=!0),"responseType"in r&&b.blob&&(r.responseType="blob"),i.headers.forEach(function(e,t){r.setRequestHeader(t,e)}),r.send("undefined"==typeof i._bodyInit?null:i._bodyInit)})},e.fetch.polyfill=!0}}("undefined"!=typeof self?self:this)},function(e,t,o){o(17),e.exports=o(18)}])}); \ No newline at end of file diff --git a/example/index.html b/example/index.html index eb5fa13d6..7529514a6 100644 --- a/example/index.html +++ b/example/index.html @@ -1 +1 @@ -React-Intl-Tel-Input Fork me on GitHub

Demo

If you can see this, something is broken (or JS is not enabled)!!.


Installation

npm install --save react-intl-tel-input

or...

yarn add react-intl-tel-input

Compatibility

react-intl-tel-input versionreact version
5.x.x+^16.2.0
4.x.x^15.0.0

Syntax

General

Demo: Lookup user's country

Validation callback

Styling


Props

keydefaultdescription
css['intl-tel-input', '']CSS classnames. First one is for the component wrapper, and second one is for text input.
style{}Style object for the wrapper div. Useful for setting 100% width on the wrapper, etc.
defaultValue''The value used to initialize input. This will only work on uncontrolled component.
value''The value of the input field. Useful for making input value controlled from outside the component.
fieldName''It's used as `input` field `name` attribute.
fieldId''It's used as `input` field `id` attribute.
countriesDataarrayCountries data can be configured, it defaults to data defined in `AllCountries`.
disablednullDisable this component.
allowDropdowntrueWhether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected flag is not clickable. Also we display the selected flag on the right instead because it is just a marker of state.
autoCompleteoffSet the value of the autoComplete attribute on the input. For example, set it to phone to tell the browser where to auto complete phone numbers.
autoPlaceholdertrueAdd or remove input placeholder with an example number for the selected country.
autoHideDialCodetrueIf there is just a dial code in the input: remove it on blur, and re-add it on focus.
placeholdernullStatic placeholder for input controller. When defined it takes priority over autoPlaceholder.
customPlaceholdernullChange the placeholder generated by autoPlaceholder. Must return a string.
defaultCountry''Default country.
excludeCountriesundefinedDon't display the countries you specify. (Array)
formatOnInittrueFormat the input value during initialisation.
noCountryDataHandlernullThe function which can catch the "no this default country" exception.
geoIpLookupnullGeoIp lookup function.
nationalModetrueDon't insert international dial codes.
numberType'MOBILE'Number type to use for placeholders.
onlyCountries[]Display only these countries.
preferredCountries['us', 'gb']The countries at the top of the list. defaults to United States and United Kingdom.
separateDialCodefalseDisplay the country dial code next to the selected flag so it's not part of the typed number. Note that this will disable nationalMode because technically we are dealing with international numbers, but with the dial code separated.
utilsScript''Specify the path to the libphonenumber script to enable validation/formatting.
onSelectFlagnullAllow main app to do things when a country is selected.
onPhoneNumberChangenullOptional validation callback function. It returns validation status, input box value and selected country data.
onPhoneNumberBlurnullOptional validation callback function. It returns validation status, input box value and selected country data.
useMobileFullscreenDropdowntrueRender fullscreen flag dropdown when mobile useragent is detected. The dropdown element is rendered as a direct child of document.body
telInputProps{}Pass through arbitrary props to the tel input element.
formatfalseFormat the number.

Inspired by

@jackocnr and his awesome project International Telephone Input.


Lincense

MIT License

\ No newline at end of file +React-Intl-Tel-Input Fork me on GitHub

Demo

If you can see this, something is broken (or JS is not enabled)!!.


Installation

npm install --save react-intl-tel-input

or...

yarn add react-intl-tel-input

Syntax

General

Demo: Lookup user's country

Validation callback

Styling


Props

keydefaultdescription
css['intl-tel-input', '']CSS classnames. First one is for the component wrapper, and second one is for text input.
style{}Style object for the wrapper div. Useful for setting 100% width on the wrapper, etc.
defaultValue''The value used to initialize input. This will only work on uncontrolled component.
value''The value of the input field. Useful for making input value controlled from outside the component.
fieldName''It's used as `input` field `name` attribute.
fieldId''It's used as `input` field `id` attribute.
countriesDataarrayCountries data can be configured, it defaults to data defined in `AllCountries`.
disablednullDisable this component.
allowDropdowntrueWhether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected flag is not clickable. Also we display the selected flag on the right instead because it is just a marker of state.
autoCompleteoffSet the value of the autoComplete attribute on the input. For example, set it to phone to tell the browser where to auto complete phone numbers.
autoPlaceholdertrueAdd or remove input placeholder with an example number for the selected country.
autoHideDialCodetrueIf there is just a dial code in the input: remove it on blur, and re-add it on focus.
placeholdernullStatic placeholder for input controller. When defined it takes priority over autoPlaceholder.
customPlaceholdernullChange the placeholder generated by autoPlaceholder. Must return a string.
defaultCountry''Default country.
excludeCountriesundefinedDon't display the countries you specify. (Array)
formatOnInittrueFormat the input value during initialisation.
noCountryDataHandlernullThe function which can catch the "no this default country" exception.
geoIpLookupnullGeoIp lookup function.
nationalModetrueDon't insert international dial codes.
numberType'MOBILE'Number type to use for placeholders.
onlyCountries[]Display only these countries.
preferredCountries['us', 'gb']The countries at the top of the list. defaults to United States and United Kingdom.
separateDialCodefalseDisplay the country dial code next to the selected flag so it's not part of the typed number. Note that this will disable nationalMode because technically we are dealing with international numbers, but with the dial code separated.
utilsScript''Specify the path to the libphonenumber script to enable validation/formatting.
onSelectFlagnullAllow main app to do things when a country is selected.
onPhoneNumberChangenullOptional validation callback function. It returns validation status, input box value and selected country data.
onPhoneNumberBlurnullOptional validation callback function. It returns validation status, input box value and selected country data.
useMobileFullscreenDropdowntrueRender fullscreen flag dropdown when mobile useragent is detected. The dropdown element is rendered as a direct child of document.body
telInputProps{}Pass through arbitrary props to the tel input element.
formatfalseFormat the number.

Inspired by

@jackocnr and his awesome project International Telephone Input.


Lincense

MIT License

\ No newline at end of file