Skip to content

A simple react phone input component with calling code dropdown🤷

License

NotificationsYou must be signed in to change notification settings

siamahnaf/react-simple-phone-input

Repository files navigation

Siam Ahnaf

React Simple Phone Input

A simple and customizable react phone number dropdown component. It can mix up with your designed theme and give a fluent vibe able dropdown area in your next project.

npm versionnpm downloadsPRs WelcomeMIT licensed

  • SSR Friendly
  • Customizable
  • Multi Design
  • Search Country
  • Smallest Bundle Size (About 98kb)
  • Typescript support

Installation

$ npm i react-simple-phone-input --save

Usage

import { PhoneInput, PhoneInputResponseType } from "react-simple-phone-input";
import "react-simple-phone-input/dist/style.css";

<PhoneInput
    country="US"
    placeholder="Add your phone"
    onChange={(data: PhoneInputResponseType) => console.log(data)}
/>

Options

NameTypeDescriptionIs RequiredExample
countrystringinitial countryrequired"BD"
placeholderstringInput Field Placeholder TextrequiredType your phone number
valuestringInput field state value or default valueoptional
iconComponentReactNodeDropdown Icon component for changing default iconoptional<Icon icon="icon-name" />
inputPropsInputHTMLAttributesProps to pass into the input fieldoptional
onlyCountriesarrayShow only country in dropdown menu with Country Codesoptional["BD", "US", "AF", "AL"]
excludeCountriesarrayIf you want to remove some country to the list. If you give excludeCountries then onlyCountries not worksoptional["AF", "AL"]
preferredCountriesarrayCountry codes to show on the top of the dropdown menuoptional["BD", "US"]
searchPlaceholderstringSearch input field placeholderoptional
searchIconComponentReactNodeIf search enabled, custom search icon to show on search baroptional<Icon icon="icon-name" />
searchPropsInputHTMLAttributesProps to pass into the search input fieldoptional
searchNotFoundstringError message when search result is empty!optional

Other Options

NameDefaultDescription
showDropdownIcontrueShow or Hide dropdown icon
dialCodeInputFieldfalseShow calling code into into field or show beside country flag. For more, see example
searchtrueShow or Hide search input field
showSearchIcontrueShow or Hide search icon
disableDropdownOnlyfalseDisable dropdown menu list
disableInputfalseDisable input field

Event

Event NameDescriptionExample
onChangeTo get the value from component. You get following field
  • country
  • code
  • dialCode
  • value
  • valueWithoutPlus
onChange={(data: PhoneInputResponseType) => console.log(data)}

ClassName

NameTypeDescription
containerClassstringclass name for container
buttonClassstringclass name for dropdown button
dropdownClassstringclass name for dropdown area/menu
dropdownListClassstringclass name for dropdown list
dropdownIconClassstringclass name for dropdown icon
searchContainerClassstringclass name for search bar container
searchInputClassstringclass name for search input field
searchIconClassstringclass name for search icon
inputClassstringclass name for search icon

Customize styles

NameDescription
containerStylephone Input Container style
buttonStylestyle for dropdown button
dropdownStylestyle for dropdown menu/area
dropdownListStylestyle for dropdown list
dropdownIconStylestyle for dropdown icon
searchContainerStylesearch container style
searchInputStylesearch input field style
searchIconStylesearch icon style
inputStyleinput field style

note: version 5 released. see the changelogs

Contributing

  • Code style changes not allowed
  • Do not create issues about incorrect or missing country data

Issues or correction

If you face any issues, missing data or wrong data about country, you are welcome to create an issue.

Stay in touch

License

MIT licensed