{"version":3,"sources":["../source/PhoneInputWithCountry.js"],"names":["React","PropTypes","classNames","InputSmart","InputBasic","Flag","InternationalIcon","sortCountryOptions","isCountrySupportedWithError","getSupportedCountries","getSupportedCountryOptions","getCountries","createCountryIconComponent","metadata","metadataPropType","labels","labelsPropType","getPreSelectedCountry","getCountrySelectOptions","parsePhoneNumber","generateNationalNumberDigits","migrateParsedInputForNewCountry","getCountryForPartialE164Number","getInitialParsedInput","parseInput","e164","PhoneNumberInput_","props","createRef","country","newCountry","international","onChange","state","prevParsedInput","parsedInput","prevCountry","newParsedInput","newValue","getInputRef","current","focus","setState","hasUserSelectedACountry","value","_input","defaultCountry","addInternationalOption","limitMaxLength","countries","input","isFocused","event","_onFocus","onFocus","onBlur","_onBlur","countrySelectProps","countryOptionsOrder","undefined","phoneNumber","CountryIcon","generateInitialParsedInput","onCountryChange","selectedCountry","prevProps","prevState","inputRef","name","disabled","autoComplete","style","className","inputComponent","numberInputProps","smartCaret","CountrySelectComponent","countrySelectComponent","ContainerComponent","containerComponent","flags","flagComponent","flagUrl","internationalIcon","displayInitialValueAsLocalNumber","reset","rest","InputComponent","countrySelectOptions","useMemoCountrySelectOptions","onCountryFocus","onCountryBlur","prevDefaultCountry","prevValue","prevReset","newDefaultCountry","newReset","newState","parsedCountry","indexOf","PureComponent","PhoneNumberInput","forwardRef","ref","propTypes","string","func","isRequired","onKeyDown","bool","arrayOf","objectOf","elementType","object","defaultProps","any","countrySelectOptionsMemo","countrySelectOptionsMemoDependencies","generator","dependencies","areEqualArrays","a","b","length","i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,iBAAP,MAA8B,qBAA9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QAAvC,CAA5B;AACA;;AAED,IAAIuG,wBAAJ;AACA,IAAIC,oCAAJ;;AACA,SAAS5B,2BAAT,CAAqC6B,SAArC,EAAgDC,YAAhD,EAA8D;AAC7D,MAAI,CAACF,oCAAD,IACH,CAACG,cAAc,CAACD,YAAD,EAAeF,oCAAf,CADhB,EACsE;AACrED,IAAAA,wBAAwB,GAAGE,SAAS,EAApC;AACAD,IAAAA,oCAAoC,GAAGE,YAAvC;AACA;;AACD,SAAOH,wBAAP;AACA;;AAED,SAASI,cAAT,CAAwBC,CAAxB,EAA2BC,CAA3B,EAA8B;AAC7B,MAAID,CAAC,CAACE,MAAF,KAAaD,CAAC,CAACC,MAAnB,EAA2B;AAC1B,WAAO,KAAP;AACA;;AACD,MAAIC,CAAC,GAAG,CAAR;;AACA,SAAOA,CAAC,GAAGH,CAAC,CAACE,MAAb,EAAqB;AACpB,QAAIF,CAAC,CAACG,CAAD,CAAD,KAASF,CAAC,CAACE,CAAD,CAAd,EAAmB;AAClB,aAAO,KAAP;AACA;;AACDA,IAAAA,CAAC;AACD;;AACD,SAAO,IAAP;AACA","sourcesContent":["import React from 'react'\r\nimport PropTypes from 'prop-types'\r\nimport classNames from 'classnames'\r\n\r\nimport InputSmart from './InputSmart'\r\nimport InputBasic from './InputBasic'\r\n\r\nimport Flag from './Flag'\r\nimport InternationalIcon from './InternationalIcon'\r\n\r\nimport {\r\n\tsortCountryOptions,\r\n\tisCountrySupportedWithError,\r\n\tgetSupportedCountries,\r\n\tgetSupportedCountryOptions,\r\n\tgetCountries\r\n} from './countries'\r\n\r\nimport { createCountryIconComponent } from './CountryIcon'\r\n\r\nimport {\r\n\tmetadata as metadataPropType,\r\n\tlabels as labelsPropType\r\n} from './PropTypes'\r\n\r\nimport {\r\n\tgetPreSelectedCountry,\r\n\tgetCountrySelectOptions,\r\n\tparsePhoneNumber,\r\n\tgenerateNationalNumberDigits,\r\n\tmigrateParsedInputForNewCountry,\r\n\tgetCountryForPartialE164Number,\r\n\tgetInitialParsedInput,\r\n\tparseInput,\r\n\te164\r\n} from './phoneInputHelpers'\r\n\r\nclass PhoneNumberInput_ extends React.PureComponent {\r\n\tinputRef = React.createRef()\r\n\r\n\tconstructor(props) {\r\n\t\tsuper(props)\r\n\r\n\t\tconst {\r\n\t\t\tvalue,\r\n\t\t\tlabels,\r\n\t\t\taddInternationalOption,\r\n\t\t\tmetadata,\r\n\t\t\tcountryOptionsOrder\r\n\t\t} = this.props\r\n\r\n\t\tlet {\r\n\t\t\tdefaultCountry,\r\n\t\t\tcountries\r\n\t\t} = this.props\r\n\r\n\t\t// Validate `defaultCountry`.\r\n\t\tif (defaultCountry) {\r\n\t\t\tif (!this.isCountrySupportedWithError(defaultCountry)) {\r\n\t\t\t\tdefaultCountry = undefined\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Validate `countries`.\r\n\t\tcountries = getSupportedCountries(countries, metadata)\r\n\r\n\t\tconst phoneNumber = parsePhoneNumber(value, metadata)\r\n\r\n\t\tthis.CountryIcon = createCountryIconComponent(this.props)\r\n\r\n\t\tthis.state = {\r\n\t\t\t// Workaround for `this.props` inside `getDerivedStateFromProps()`.\r\n\t\t\tprops: this.props,\r\n\r\n\t\t\t// The country selected.\r\n\t\t\tcountry: getPreSelectedCountry(\r\n\t\t\t\tphoneNumber,\r\n\t\t\t\tdefaultCountry,\r\n\t\t\t\tcountries || getCountries(metadata),\r\n\t\t\t\taddInternationalOption,\r\n\t\t\t\tmetadata\r\n\t\t\t),\r\n\r\n\t\t\t// `countries` are stored in `this.state` because they're filtered.\r\n\t\t\t// For example, a developer might theoretically pass some unsupported\r\n\t\t\t// countries as part of the `countries` property, and because of that\r\n\t\t\t// the component uses `this.state.countries` (which are filtered)\r\n\t\t\t// instead of `this.props.countries`\r\n\t\t\t// (which could potentially contain unsupported countries).\r\n\t\t\tcountries,\r\n\r\n\t\t\t// `parsedInput` state property holds non-formatted user's input.\r\n\t\t\t// The reason is that there's no way of finding out\r\n\t\t\t// in which form should `value` be displayed: international or national.\r\n\t\t\t// E.g. if `value` is `+78005553535` then it could be input\r\n\t\t\t// by a user both as `8 (800) 555-35-35` and `+7 800 555 35 35`.\r\n\t\t\t// Hence storing just `value`is not sufficient for correct formatting.\r\n\t\t\t// E.g. if a user entered `8 (800) 555-35-35`\r\n\t\t\t// then value is `+78005553535` and `parsedInput` is `88005553535`\r\n\t\t\t// and if a user entered `+7 800 555 35 35`\r\n\t\t\t// then value is `+78005553535` and `parsedInput` is `+78005553535`.\r\n\t\t\tparsedInput: generateInitialParsedInput(value, phoneNumber, this.props),\r\n\r\n\t\t\t// `value` property is duplicated in state.\r\n\t\t\t// The reason is that `getDerivedStateFromProps()`\r\n\t\t\t// needs this `value` to compare to the new `value` property\r\n\t\t\t// to find out if `parsedInput` needs updating:\r\n\t\t\t// If the `value` property was changed externally\r\n\t\t\t// then it won't be equal to `state.value`\r\n\t\t\t// in which case `parsedInput` and `country` should be updated.\r\n\t\t\tvalue\r\n\t\t}\r\n\t}\r\n\r\n\tcomponentDidMount() {\r\n\t\tconst { onCountryChange } = this.props\r\n\t\tlet { defaultCountry } = this.props\r\n\t\tconst { country: selectedCountry } = this.state\r\n\t\tif (onCountryChange) {\r\n\t\t\tif (defaultCountry) {\r\n\t\t\t\tif (!this.isCountrySupportedWithError(defaultCountry)) {\r\n\t\t\t\t\tdefaultCountry = undefined\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (selectedCountry !== defaultCountry) {\r\n\t\t\t\tonCountryChange(selectedCountry)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tcomponentDidUpdate(prevProps, prevState) {\r\n\t\tconst { onCountryChange } = this.props\r\n\t\tconst { country } = this.state\r\n\t\t// Call `onCountryChange` when user selects another country.\r\n\t\tif (onCountryChange && country !== prevState.country) {\r\n\t\t\tonCountryChange(country)\r\n\t\t}\r\n\t}\r\n\r\n\t// A shorthand for not passing `metadata` as a second argument.\r\n\tisCountrySupportedWithError = (country) => {\r\n\t\tconst { metadata } = this.props\r\n\t\treturn isCountrySupportedWithError(country, metadata)\r\n\t}\r\n\r\n\t// Country `` holds any digits\r\n\t\t// then migrate those digits for the new `country`.\r\n\t\tconst newParsedInput = migrateParsedInputForNewCountry(\r\n\t\t\tprevParsedInput,\r\n\t\t\tprevCountry,\r\n\t\t\tnewCountry,\r\n\t\t\tmetadata,\r\n\t\t\t// Convert the phone number to \"national\" format\r\n\t\t\t// when the user changes the selected country by hand.\r\n\t\t\tinternational ? false : true\r\n\t\t)\r\n\r\n\t\tconst newValue = e164(newParsedInput, newCountry, metadata)\r\n\r\n\t\t// Focus phone number `` upon country selection.\r\n\t\tthis.getInputRef().current.focus()\r\n\r\n\t\t// If the user has already manually selected a country\r\n\t\t// then don't override that already selected country\r\n\t\t// if the `defaultCountry` property changes.\r\n\t\t// That's what `hasUserSelectedACountry` flag is for.\r\n\r\n\t\tthis.setState({\r\n\t\t\tcountry: newCountry,\r\n\t\t\thasUserSelectedACountry: true,\r\n\t\t\tparsedInput: newParsedInput,\r\n\t\t\tvalue: newValue\r\n\t\t},\r\n\t\t() => {\r\n\t\t\t// Update the new `value` property.\r\n\t\t\t// Doing it after the `state` has been updated\r\n\t\t\t// because `onChange()` will trigger `getDerivedStateFromProps()`\r\n\t\t\t// with the new `value` which will be compared to `state.value` there.\r\n\t\t\tonChange(newValue)\r\n\t\t})\r\n\t}\r\n\r\n\t/**\r\n\t * `` `onChange()` handler.\r\n\t * Updates `value` property accordingly (so that they are kept in sync).\r\n\t * @param {string?} input — Either a parsed phone number or an empty string. Examples: `\"\"`, `\"+\"`, `\"+123\"`, `\"123\"`.\r\n\t */\r\n\tonChange = (_input) => {\r\n\t\tconst {\r\n\t\t\tdefaultCountry,\r\n\t\t\tonChange,\r\n\t\t\taddInternationalOption,\r\n\t\t\tinternational,\r\n\t\t\tlimitMaxLength,\r\n\t\t\tmetadata\r\n\t\t} = this.props\r\n\r\n\t\tconst {\r\n\t\t\tinput,\r\n\t\t\tcountry,\r\n\t\t\tvalue\r\n\t\t} = parseInput(\r\n\t\t\t_input,\r\n\t\t\tthis.state.parsedInput,\r\n\t\t\tthis.state.country,\r\n\t\t\tdefaultCountry,\r\n\t\t\tthis.state.countries,\r\n\t\t\taddInternationalOption,\r\n\t\t\tinternational,\r\n\t\t\tlimitMaxLength,\r\n\t\t\tmetadata\r\n\t\t)\r\n\r\n\t\tthis.setState({\r\n\t\t\tparsedInput: input,\r\n\t\t\tvalue,\r\n\t\t\tcountry\r\n\t\t},\r\n\t\t// Update the new `value` property.\r\n\t\t// Doing it after the `state` has been updated\r\n\t\t// because `onChange()` will trigger `getDerivedStateFromProps()`\r\n\t\t// with the new `value` which will be compared to `state.value` there.\r\n\t\t() => onChange(value))\r\n\t}\r\n\r\n\t// Toggles the `--focus` CSS class.\r\n\t_onFocus = () => this.setState({ isFocused: true })\r\n\r\n\t// Toggles the `--focus` CSS class.\r\n\t_onBlur = () => this.setState({ isFocused: false })\r\n\r\n\tonFocus = (event) => {\r\n\t\tthis._onFocus()\r\n\t\tconst { onFocus } = this.props\r\n\t\tif (onFocus) {\r\n\t\t\tonFocus(event)\r\n\t\t}\r\n\t}\r\n\r\n\tonBlur = (event) => {\r\n\t\tconst { onBlur } = this.props\r\n\t\tthis._onBlur()\r\n\t\tif (onBlur) {\r\n\t\t\tonBlur(event)\r\n\t\t}\r\n\t}\r\n\r\n\tonCountryFocus = (event) => {\r\n\t\tthis._onFocus()\r\n\t\t// this.setState({ countrySelectFocused: true })\r\n\t\tconst { countrySelectProps } = this.props\r\n\t\tif (countrySelectProps) {\r\n\t\t\tconst { onFocus } = countrySelectProps\r\n\t\t\tif (onFocus) {\r\n\t\t\t\tonFocus(event)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tonCountryBlur = (event) => {\r\n\t\tthis._onBlur()\r\n\t\t// this.setState({ countrySelectFocused: false })\r\n\t\tconst { countrySelectProps } = this.props\r\n\t\tif (countrySelectProps) {\r\n\t\t\tconst { onBlur } = countrySelectProps\r\n\t\t\tif (onBlur) {\r\n\t\t\t\tonBlur(event)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tgetInputRef() {\r\n\t\tconst { inputRef } = this.props\r\n\t\treturn inputRef || this.inputRef\r\n\t}\r\n\r\n\t// `state` holds previous props as `props`, and also:\r\n\t// * `country` — The currently selected country, e.g. `\"RU\"`.\r\n\t// * `value` — The currently entered phone number (E.164), e.g. `+78005553535`.\r\n\t// * `parsedInput` — The parsed `` value, e.g. `8005553535`.\r\n\t// (and a couple of other less significant properties)\r\n\tstatic getDerivedStateFromProps(props, state) {\r\n\t\tconst {\r\n\t\t\tcountry,\r\n\t\t\thasUserSelectedACountry,\r\n\t\t\tvalue,\r\n\t\t\tprops: {\r\n\t\t\t\tdefaultCountry: prevDefaultCountry,\r\n\t\t\t\tvalue: prevValue,\r\n\t\t\t\treset: prevReset\r\n\t\t\t}\r\n\t\t} = state\r\n\r\n\t\tconst {\r\n\t\t\tmetadata,\r\n\t\t\tcountries,\r\n\t\t\tdefaultCountry: newDefaultCountry,\r\n\t\t\tvalue: newValue,\r\n\t\t\treset: newReset,\r\n\t\t\tinternational\r\n\t\t} = props\r\n\r\n\t\tconst newState = {\r\n\t\t\t// Emulate `prevProps` via `state.props`.\r\n\t\t\tprops,\r\n\t\t\t// If the user has already manually selected a country\r\n\t\t\t// then don't override that already selected country\r\n\t\t\t// if the `defaultCountry` property changes.\r\n\t\t\t// That's what `hasUserSelectedACountry` flag is for.\r\n\t\t\thasUserSelectedACountry\r\n\t\t}\r\n\r\n\t\t// Some users requested a way to reset the component\r\n\t\t// (both number `` and country ``\r\n\t\t// and country ``.\r\n\t\t// It's also not replaced with just resetting `country` on\r\n\t\t// external `value` reset, because a user could select a country\r\n\t\t// and then not input any `value`, and so the selected country\r\n\t\t// would be \"stuck\", if not using this `reset` property.\r\n\t\t// https://github.com/catamphetamine/react-phone-number-input/issues/300\r\n\t\tif (newReset !== prevReset) {\r\n\t\t\treturn {\r\n\t\t\t\t...newState,\r\n\t\t\t\tparsedInput: undefined,\r\n\t\t\t\tvalue: undefined,\r\n\t\t\t\tcountry: newDefaultCountry,\r\n\t\t\t\thasUserSelectedACountry: undefined\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If the default country changed.\r\n\t\t// (e.g. in case of ajax GeoIP detection after page loaded)\r\n\t\t// then select it but only if the user hasn't already manually\r\n\t\t// selected a country and no phone number has been entered so far.\r\n\t\t// Because if the user has already started inputting a phone number\r\n\t\t// then he's okay with no country being selected at all (\"International\")\r\n\t\t// and doesn't want to be disturbed, doesn't want his input to be screwed, etc.\r\n\t\tif (newDefaultCountry !== prevDefaultCountry &&\r\n\t\t\t!hasUserSelectedACountry && (\r\n\t\t\t\t(!value && !newValue) ||\r\n\t\t\t\t(international &&\r\n\t\t\t\t\tvalue === getInitialParsedInput(undefined, prevDefaultCountry, international, metadata) &&\r\n\t\t\t\t\tvalue === getInitialParsedInput(undefined, newDefaultCountry, international, metadata)\r\n\t\t\t\t)\r\n\t\t\t)\r\n\t\t) {\r\n\t\t\treturn {\r\n\t\t\t\t...newState,\r\n\t\t\t\tcountry: isCountrySupportedWithError(newDefaultCountry, metadata) ? newDefaultCountry : prevDefaultCountry,\r\n\t\t\t\t// If `parsedInput` is empty, then automatically select the new `country`\r\n\t\t\t\t// and set `parsedInput` to `+{getCountryCallingCode(newCountry)}`.\r\n\t\t\t\tparsedInput: generateInitialParsedInput(newValue, undefined, props)\r\n\t\t\t\t// `value` is `undefined`.\r\n\t\t\t\t// `parsedInput` is `undefined` because `value` is `undefined`.\r\n\t\t\t}\r\n\t\t}\r\n\t\t// If a new `value` is set externally.\r\n\t\t// (e.g. as a result of an ajax API request\r\n\t\t// to get user's phone after page loaded)\r\n\t\t// The first part — `newValue !== prevValue` —\r\n\t\t// is basically `props.value !== prevProps.value`\r\n\t\t// so it means \"if value property was changed externally\".\r\n\t\t// The second part — `newValue !== value` —\r\n\t\t// is for ignoring the `getDerivedStateFromProps()` call\r\n\t\t// which happens in `this.onChange()` right after `this.setState()`.\r\n\t\t// If this `getDerivedStateFromProps()` call isn't ignored\r\n\t\t// then the country flag would reset on each input.\r\n\t\telse if (newValue !== prevValue && newValue !== value) {\r\n\t\t\tconst phoneNumber = parsePhoneNumber(newValue, metadata)\r\n\t\t\tlet parsedCountry\r\n\t\t\tif (phoneNumber) {\r\n\t\t\t\tconst countries = getSupportedCountries(props.countries, metadata)\r\n\t\t\t\tif (!countries || countries.indexOf(phoneNumber.country) >= 0) {\r\n\t\t\t\t\tparsedCountry = phoneNumber.country\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (!newValue) {\r\n\t\t\t\tnewState.hasUserSelectedACountry = undefined\r\n\t\t\t}\r\n\t\t\treturn {\r\n\t\t\t\t...newState,\r\n\t\t\t\tparsedInput: generateInitialParsedInput(newValue, phoneNumber, props),\r\n\t\t\t\tvalue: newValue,\r\n\t\t\t\tcountry: newValue ? parsedCountry : newDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// `defaultCountry` didn't change.\r\n\t\t// `value` didn't change.\r\n\t\t// `parsedInput` didn't change, because `value` didn't change.\r\n\t\t//\r\n\t\t// So no need to update state here really.\r\n\t\t// Could as well return `null` explicitly\r\n\t\t// to indicate that the `state` hasn't changed.\r\n\t\t// But just in case, returns `newState`.\r\n\t\t// (who knows if someone adds something\r\n\t\t// changing `newState` above in some future)\r\n\t\treturn newState\r\n\t}\r\n\r\n\trender() {\r\n\t\tconst {\r\n\t\t\t// Generic HTML attributes.\r\n\t\t\tname,\r\n\t\t\tdisabled,\r\n\t\t\tautoComplete,\r\n\t\t\tstyle,\r\n\t\t\tclassName,\r\n\r\n\t\t\t// Number `` properties.\r\n\t\t\tinputRef,\r\n\t\t\tinputComponent,\r\n\t\t\tnumberInputProps,\r\n\t\t\tsmartCaret,\r\n\r\n\t\t\t// Country ``).\r\n\t\t\tdefaultCountry,\r\n\t\t\tcountries,\r\n\t\t\tcountryOptionsOrder,\r\n\t\t\tlabels,\r\n\t\t\tflags,\r\n\t\t\tflagComponent,\r\n\t\t\tflagUrl,\r\n\t\t\taddInternationalOption,\r\n\t\t\tinternationalIcon,\r\n\t\t\tdisplayInitialValueAsLocalNumber,\r\n\t\t\tonCountryChange,\r\n\t\t\tlimitMaxLength,\r\n\t\t\treset,\r\n\t\t\tmetadata,\r\n\t\t\tinternational,\r\n\t\t\t...rest\r\n\t\t} = this.props\r\n\r\n\t\tconst {\r\n\t\t\tcountry,\r\n\t\t\tparsedInput,\r\n\t\t\tisFocused\r\n\t\t} = this.state\r\n\r\n\t\tconst InputComponent = smartCaret ? InputSmart : InputBasic\r\n\r\n\t\tconst countrySelectOptions = useMemoCountrySelectOptions(() => {\r\n\t\t\treturn sortCountryOptions(\r\n\t\t\t\tgetCountrySelectOptions(\r\n\t\t\t\t\tcountries || getCountries(metadata),\r\n\t\t\t\t\tlabels,\r\n\t\t\t\t\taddInternationalOption\r\n\t\t\t\t),\r\n\t\t\t\tgetSupportedCountryOptions(countryOptionsOrder, metadata)\r\n\t\t\t)\r\n\t\t}, [\r\n\t\t\tcountries,\r\n\t\t\tcountryOptionsOrder,\r\n\t\t\taddInternationalOption,\r\n\t\t\tlabels,\r\n\t\t\tmetadata\r\n\t\t])\r\n\r\n\t\treturn (\r\n\t\t\t\r\n\r\n\t\t\t\t{/* Country `` */}\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t)\r\n\t}\r\n}\r\n\r\n// This wrapper is only to `.forwardRef()` to the ``.\r\nconst PhoneNumberInput = React.forwardRef((props, ref) => (\r\n\t\r\n))\r\n\r\nPhoneNumberInput.propTypes = {\r\n\t/**\r\n\t * Phone number in `E.164` format.\r\n\t *\r\n\t * Example:\r\n\t *\r\n\t * `\"+12223333333\"`\r\n\t */\r\n\tvalue: PropTypes.string,\r\n\r\n\t/**\r\n\t * Updates the `value` as the user inputs the phone number.\r\n\t */\r\n\tonChange: PropTypes.func.isRequired,\r\n\r\n\t/**\r\n\t * Toggles the `--focus` CSS class.\r\n\t * @ignore\r\n\t */\r\n\tonFocus: PropTypes.func,\r\n\r\n\t/**\r\n\t * `onBlur` is usually passed by `redux-form`.\r\n\t * @ignore\r\n\t */\r\n\tonBlur: PropTypes.func,\r\n\r\n\t/**\r\n\t * `onKeyDown` handler (e.g. to handle Enter key press).\r\n\t * @ignore\r\n\t */\r\n\tonKeyDown: PropTypes.func,\r\n\r\n\t/**\r\n\t * Set to `true` to disable both the phone number ``\r\n\t * and the country ``.\r\n\t *\r\n\t * Web browser's \"autocomplete\" feature\r\n\t * remembers the phone number being input\r\n\t * and can also autofill the ``\r\n\t * with previously remembered phone numbers.\r\n\t *\r\n\t * https://developers.google.com\r\n\t * /web/updates/2015/06/checkout-faster-with-autofill\r\n\t *\r\n\t * For example, can be used to turn it off:\r\n\t *\r\n\t * \"So when should you use `autocomplete=\"off\"`?\r\n\t * One example is when you've implemented your own version\r\n\t * of autocomplete for search. Another example is any form field\r\n\t * where users will input and submit different kinds of information\r\n\t * where it would not be useful to have the browser remember\r\n\t * what was submitted previously\".\r\n\t */\r\n\t// (is `\"tel\"` by default)\r\n\tautoComplete: PropTypes.string.isRequired,\r\n\r\n\t/**\r\n\t * Set to `true` to show the initial `value` in\r\n\t * \"national\" format rather than \"international\".\r\n\t *\r\n\t * For example, if this flag is set to `true`\r\n\t * and the initial `value=\"+12133734253\"` is passed\r\n\t * then the `` value will be `\"(213) 373-4253\"`.\r\n\t *\r\n\t * By default, this flag is set to `false`,\r\n\t * meaning that if the initial `value=\"+12133734253\"` is passed\r\n\t * then the `` value will be `\"+1 213 373 4253\"`.\r\n\t *\r\n\t * The reason for such default behaviour is that\r\n\t * the newer generation grows up when there are no stationary phones\r\n\t * and therefore everyone inputs phone numbers in international format\r\n\t * in their smartphones so people gradually get more accustomed to\r\n\t * writing phone numbers in international format rather than in local format.\r\n\t * Future people won't be using \"national\" format, only \"international\".\r\n\t */\r\n\t// (is `false` by default)\r\n\tdisplayInitialValueAsLocalNumber: PropTypes.bool.isRequired,\r\n\r\n\t/**\r\n\t * The country to be selected by default.\r\n\t * For example, can be set after a GeoIP lookup.\r\n\t *\r\n\t * Example: `\"US\"`.\r\n\t */\r\n\t// A two-letter country code (\"ISO 3166-1 alpha-2\").\r\n\tdefaultCountry: PropTypes.string,\r\n\r\n\t/**\r\n\t * If specified, only these countries will be available for selection.\r\n\t *\r\n\t * Example:\r\n\t *\r\n\t * `[\"RU\", \"UA\", \"KZ\"]`\r\n\t */\r\n\tcountries: PropTypes.arrayOf(PropTypes.string),\r\n\r\n\t/**\r\n\t * Custom country `` `aria-label`.\r\n\t *\r\n\t * Example:\r\n\t *\r\n\t * `{ \"ZZ\": \"Международный\", RU: \"Россия\", US: \"США\", ... }`\r\n\t *\r\n\t * See the `locales` directory for examples.\r\n\t */\r\n\tlabels: labelsPropType.isRequired,\r\n\r\n\t/**\r\n\t * A URL template of a country flag, where\r\n\t * \"{XX}\" is a two-letter country code in upper case,\r\n\t * or where \"{xx}\" is a two-letter country code in lower case.\r\n\t * By default it points to `country-flag-icons` gitlab pages website.\r\n\t * I imagine someone might want to download those country flag icons\r\n\t * and host them on their own servers instead\r\n\t * (all flags are available in the `country-flag-icons` library).\r\n\t * There's a catch though: new countries may be added in future,\r\n\t * so when hosting country flag icons on your own server\r\n\t * one should check the `CHANGELOG.md` every time before updating this library,\r\n\t * otherwise there's a possibility that some new country flag would be missing.\r\n\t */\r\n\tflagUrl: PropTypes.string.isRequired,\r\n\r\n\t/**\r\n\t * Custom country flag icon components.\r\n\t * These flags will be used instead of the default ones.\r\n\t * The the \"Flags\" section of the readme for more info.\r\n\t *\r\n\t * The shape is an object where keys are country codes\r\n\t * and values are flag icon components.\r\n\t * Flag icon components receive the same properties\r\n\t * as `flagComponent` (see below).\r\n\t *\r\n\t * Example:\r\n\t *\r\n\t * `{ \"RU\": (props) => }`\r\n\t *\r\n\t * Example:\r\n\t *\r\n\t * `import flags from 'country-flag-icons/react/3x2'`\r\n\t *\r\n\t * `import PhoneInput from 'react-phone-number-input'`\r\n\t *\r\n\t * ``\r\n\t */\r\n\tflags: PropTypes.objectOf(PropTypes.elementType),\r\n\r\n\t/**\r\n\t * Country flag icon component.\r\n\t *\r\n\t * Takes properties:\r\n\t *\r\n\t * * `country: string` — The country code.\r\n\t * * `countryName: string` — The country name.\r\n\t * * `flagUrl: string` — The `flagUrl` property (see above).\r\n\t * * `flags: object` — The `flags` property (see above).\r\n\t */\r\n\tflagComponent: PropTypes.elementType.isRequired,\r\n\r\n\t/**\r\n\t * Set to `false` to remove the \"International\" option from country `` options.\r\n\t *\r\n\t * * `\"|\"` — inserts a separator.\r\n\t * * `\"...\"` — means \"the rest of the countries\" (can be omitted, in which case it will automatically be added at the end).\r\n\t *\r\n\t * Example:\r\n\t *\r\n\t * `[\"US\", \"CA\", \"AU\", \"|\", \"...\"]`\r\n\t */\r\n\tcountryOptionsOrder: PropTypes.arrayOf(PropTypes.string),\r\n\r\n\t/**\r\n\t * `` component CSS style object.\r\n\t */\r\n\tstyle: PropTypes.object,\r\n\r\n\t/**\r\n\t * `` component CSS class.\r\n\t */\r\n\tclassName: PropTypes.string,\r\n\r\n\t/**\r\n\t * Country `` component props.\r\n\t * Along with the usual DOM properties such as `aria-label` and `tabIndex`,\r\n\t * some custom properties are supported, such as `arrowComponent` and `unicodeFlags`.\r\n\t */\r\n\tcountrySelectProps: PropTypes.object,\r\n\r\n\t/**\r\n\t * Phone number `` component.\r\n\t *\r\n\t * Receives properties:\r\n\t *\r\n\t * * `value: string` — The formatted `value`.\r\n\t * * `onChange(event: Event)` — Updates the formatted `value` from `event.target.value`.\r\n\t * * `onFocus()` — Is used to toggle the `--focus` CSS class.\r\n\t * * `onBlur()` — Is used to toggle the `--focus` CSS class.\r\n\t * * Other properties like `type=\"tel\"` or `autoComplete=\"tel\"` that should be passed through to the DOM ``.\r\n\t *\r\n\t * Must also either use `React.forwardRef()` to \"forward\" `ref` to the `` or implement `.focus()` method.\r\n\t */\r\n\tinputComponent: PropTypes.elementType.isRequired,\r\n\r\n\t/**\r\n\t * Wrapping `
` component.\r\n\t *\r\n\t * Receives properties:\r\n\t *\r\n\t * * `style: object` — A component CSS style object.\r\n\t * * `className: string` — Classes to attach to the component, typically changes when component focuses or blurs.\r\n\t */\r\n\tcontainerComponent: PropTypes.elementType.isRequired,\r\n\r\n\t/**\r\n\t * Phone number `` component props.\r\n\t */\r\n\tnumberInputProps: PropTypes.object,\r\n\r\n\t/**\r\n\t * By default, the caret position is being \"intelligently\" managed\r\n\t * while a user inputs a phone number.\r\n\t * This \"smart\" caret behavior can be turned off\r\n\t * by passing `smartCaret={false}` property.\r\n\t * This is just an \"escape hatch\" for any possible caret position issues.\r\n\t */\r\n\t// Is `true` by default.\r\n\tsmartCaret: PropTypes.bool.isRequired,\r\n\r\n\t/**\r\n\t * Set to `true` to force \"international\" phone number format.\r\n\t */\r\n\tinternational: PropTypes.bool,\r\n\r\n\t/**\r\n\t * If set to `true`, the phone number input will get trimmed\r\n\t * if it exceeds the maximum length for the country.\r\n\t */\r\n\tlimitMaxLength: PropTypes.bool.isRequired,\r\n\r\n\t/**\r\n\t * `libphonenumber-js` metadata.\r\n\t *\r\n\t * Can be used to pass custom `libphonenumber-js` metadata\r\n\t * to reduce the overall bundle size for those who compile \"custom\" metadata.\r\n\t */\r\n\tmetadata: metadataPropType.isRequired,\r\n\r\n\t/**\r\n\t * Is called every time the selected country changes:\r\n\t * either programmatically or when user selects it manually from the list.\r\n\t */\r\n\t// People have been asking for a way to get the selected country.\r\n\t// @see https://github.com/catamphetamine/react-phone-number-input/issues/128\r\n\t// For some it's just a \"business requirement\".\r\n\t// I guess it's about gathering as much info on the user as a website can\r\n\t// without introducing any addional fields that would complicate the form\r\n\t// therefore reducing \"conversion\" (that's a marketing term).\r\n\t// Assuming that the phone number's country is the user's country\r\n\t// is not 100% correct but in most cases I guess it's valid.\r\n\tonCountryChange: PropTypes.func\r\n}\r\n\r\nPhoneNumberInput.defaultProps = {\r\n\t/**\r\n\t * Remember (and autofill) the value as a phone number.\r\n\t */\r\n\tautoComplete: 'tel',\r\n\r\n\t/**\r\n\t * Flag icon component.\r\n\t */\r\n\tflagComponent: Flag,\r\n\r\n\t/**\r\n\t * By default, uses icons from `country-flag-icons` gitlab pages website.\r\n\t */\r\n\t// Must be equal to `flagUrl` in `./CountryIcon.js`.\r\n\tflagUrl: 'https://catamphetamine.gitlab.io/country-flag-icons/3x2/{XX}.svg',\r\n\r\n\t/**\r\n\t * Default \"International\" country `` component.\r\n\t */\r\n\tinputComponent: 'input',\r\n\r\n\t/**\r\n\t * Wrapping `
` component.\r\n\t */\r\n\tcontainerComponent: 'div',\r\n\r\n\t/**\r\n\t * Some users requested a way to reset the component:\r\n\t * both number `` and country ``\r\n\t * and country ``.\r\n\t * It's also not replaced with just resetting `country` on\r\n\t * external `value` reset, because a user could select a country\r\n\t * and then not input any `value`, and so the selected country\r\n\t * would be \"stuck\", if not using this `reset` property.\r\n\t */\r\n\t// https://github.com/catamphetamine/react-phone-number-input/issues/300\r\n\treset: PropTypes.any,\r\n\r\n\t/**\r\n\t * Don't convert the initially passed phone number `value`\r\n\t * to a national phone number for its country.\r\n\t * The reason is that the newer generation grows up when\r\n\t * there are no stationary phones and therefore everyone inputs\r\n\t * phone numbers with a `+` in their smartphones\r\n\t * so phone numbers written in international form\r\n\t * are gradually being considered more natural than local ones.\r\n\t */\r\n\tdisplayInitialValueAsLocalNumber: false,\r\n\r\n\t/**\r\n\t * Set to `false` to use \"basic\" caret instead of the \"smart\" one.\r\n\t */\r\n\tsmartCaret: true,\r\n\r\n\t/**\r\n\t * Whether to add the \"International\" option\r\n\t * to the list of countries.\r\n\t */\r\n\taddInternationalOption: true,\r\n\r\n\t/**\r\n\t * If set to `true` the phone number input will get trimmed\r\n\t * if it exceeds the maximum length for the country.\r\n\t */\r\n\tlimitMaxLength: false\r\n}\r\n\r\nexport default PhoneNumberInput\r\n\r\n/**\r\n * Gets initial `parsedInput` value.\r\n * @param {string} [value]\r\n * @param {PhoneNumber} [phoneNumber]\r\n * @param {boolean} [options.international]\r\n * @param {string} [options.defaultCountry]\r\n * @param {boolean} options.displayInitialValueAsLocalNumber\r\n * @param {object} options.metadata\r\n * @return {string} [parsedInput]\r\n */\r\nfunction generateInitialParsedInput(value, phoneNumber, {\r\n\tinternational,\r\n\tdefaultCountry,\r\n\tmetadata,\r\n\tdisplayInitialValueAsLocalNumber\r\n}) {\r\n\t// If the `value` (E.164 phone number)\r\n\t// belongs to the currently selected country\r\n\t// and `displayInitialValueAsLocalNumber` property is `true`\r\n\t// then convert `value` (E.164 phone number)\r\n\t// to a local phone number digits.\r\n\t// E.g. '+78005553535' -> '88005553535'.\r\n\tif (displayInitialValueAsLocalNumber && phoneNumber && phoneNumber.country) {\r\n\t\treturn generateNationalNumberDigits(phoneNumber)\r\n\t}\r\n\treturn getInitialParsedInput(value, defaultCountry, international, metadata)\r\n}\r\n\r\nlet countrySelectOptionsMemo\r\nlet countrySelectOptionsMemoDependencies\r\nfunction useMemoCountrySelectOptions(generator, dependencies) {\r\n\tif (!countrySelectOptionsMemoDependencies ||\r\n\t\t!areEqualArrays(dependencies, countrySelectOptionsMemoDependencies)) {\r\n\t\tcountrySelectOptionsMemo = generator()\r\n\t\tcountrySelectOptionsMemoDependencies = dependencies\r\n\t}\r\n\treturn countrySelectOptionsMemo\r\n}\r\n\r\nfunction areEqualArrays(a, b) {\r\n\tif (a.length !== b.length) {\r\n\t\treturn false\r\n\t}\r\n\tlet i = 0\r\n\twhile (i < a.length) {\r\n\t\tif (a[i] !== b[i]) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\ti++\r\n\t}\r\n\treturn true\r\n}"],"file":"PhoneInputWithCountry.js"}