@mshafiqyajid/react-phone-input

Headless phone input hook and styled component. Country selector with flag emoji, dial code, 30+ countries, E.164 output.

Playground #

Props
TSX
import { PhoneInputStyled } from "@mshafiqyajid/react-phone-input/styled";
import "@mshafiqyajid/react-phone-input/styles.css";

<PhoneInputStyled
  value={value}
  onChange={setValue}
/>

Install #

npm install @mshafiqyajid/react-phone-input

Quick start #

import { PhoneInputStyled } from "@mshafiqyajid/react-phone-input/styled";
import "@mshafiqyajid/react-phone-input/styles.css";

const [phone, setPhone] = useState("");
<PhoneInputStyled
  value={phone}
  onChange={setPhone}
  defaultCountry="US"
  label="Phone number"
  tone="primary"
/>

API #

PropTypeDefaultDescription
valuestringβ€”Controlled phone number value
defaultValuestring""Uncontrolled initial value
onChange(v) => voidβ€”Called on change
defaultCountrystring"US"ISO-2 country code default
showFlagbooleantrueShow flag emoji in selector
labelstringβ€”Visible label
hintstringβ€”Helper text below input
errorstringβ€”Error message (overrides hint)
size"sm" | "md" | "lg""md"Input size
tone"neutral" | "primary" | "success" | "danger""neutral"Color tone
disabledbooleanfalseDisable interaction
countriesstring[]β€”Whitelist of ISO-2 country codes
onCountryChange(country) => voidβ€”Country change callback
outputFormat"national" | "international" | "e164""national"Output format for onChange value
readOnlybooleanfalseRead-only input
Edit this page on GitHub