Phone Input
In Windows, flag emojis may not be visible due to a lack of native support from the OS. For a solution, consider checking out the
Coutry Flag Emoji Polyfill
.
Examples
AutoFocus
PhoneInput
accepts an autoFocus
prop. For information on its behaviour, check Input's autoFocus example.
As with many of our components, there is also an uncontrolled version, StatefulPhoneInput
, which manages its own state.
Note that, default selected country will be the first country passed in countries
.
Supported Countries
The following countries are available in the country selector dropdown.
You can import these as an object COUNTRIES
from spaceweb/phone-input
.
Note, the country objects are formatted for ease of use with our Select
component.
COUNTRIES: {id: string, // Country ISOlabel: string, // Country NamedialCode: string // Country Dial Code}
API
Phone Input props
Name | Type | Default | Description |
---|---|---|---|
autoFocus | string | Takes "start" | "end" | number | boolean values and sets the position of the cursor on mount. | |
clearable | boolean | false | Adds clear icon to the input. |
countries | array | By default all countries will be visible in dropdown. Provide Country[] to selectively display countries. | |
disabled | boolean | false | Renders component in disabled state. |
id | string | Id attribute value to be added to the input element and as a label's for attribute value. | |
intent | 'default' | 'success' | 'warning' | 'error' | Defines the intent of the Input. | |
mapIsoToLabel | function | Function for mapping ISO codes to country names. Useful for localization of the country select dropdown. | |
maxDropdownHeight | string | Sets the max height of the country select dropdown. | |
maxDropdownWidth | string | Sets the max width of the country select dropdown. | |
onChange | function | Called when value is changed. | |
onInputChange | function | Called when input value is changed. | |
overrides | custom | Lets you customize all aspects of the component. | |
placeholder | string | Input's placeholder. | |
size | 'xs' | 'sm' | 'md' | Input's size. SPACIOUS | COMFORTABLE -> md, COMPACT -> xxxs, DEFAULT -> md | |
value | object | Object which comprises the country set and phoneNumber entered. | |
variant | 'default' | 'line' | Input's variant - default, line |
Phone Input exports
You can import this module like so:
import {COUNTRIES} from 'spaceweb/phone-input'
It exports the following components or utility functions:
- COUNTRIES
- COUNTRY_SELECT_OPTIONS
- DEFAULT_MAX_DROPDOWN_HEIGHT
- DEFAULT_MAX_DROPDOWN_WIDTH
- EMPTY_LIST_HEIGHT
- ISO_REGEX
- ISO_TO_FLAG_OFFSET
- LIST_ITEM_HEIGHT
- OVERSCAN_COUNT
- PhoneInput
- STATE_CHANGE_TYPE
- StatefulPhoneInput
- getPhoneNumberWithCountryDialCode