PhoneInput component is a specialized input field for international phone numbers that offers country selection and automatic formatting. It includes a searchable dropdown with country flags and applies region-specific formatting masks.tsx
import { PhoneInput } from "@arkyn/components";
name property.tsx
<PhoneInput name="phone" />
defaultCountry property (it will only take effect when a phone number is not available in the defaultValue property), using the country's ISO code (e.g., "BR" for Brazil, "US" for the USA).defaultCountry. However, the number must begin with the country code (e.g., +55 for Brazil, +1 for the USA), following the international E.164 format. The phone number format should be: +[countryCode]-[countryPrefixCode][countryNumber].tsx
<PhoneInputname="auto-detect"label="Phone"defaultValue="+55 11999999999" // Brazil/>
tsx
<PhoneInputname="phone-search"label="Phone with custom search"searchCountryPlaceholder="Enter the country name..."notFoundCountryText="Country not found"/>
md and lg, following the pattern for other input components.tsx
<PhoneInputname="phone-md"label="Phone (medium)"size="md"/><PhoneInputname="phone-lg"label="Phone (large)"size="lg"/>
solid and outline, providing different visual styles.tsx
<PhoneInputname="phone-solid"label="Phone (solid)"variant="solid"/><PhoneInputname="phone-outline"label="Phone (outline)"variant="outline"/>
tsx
<PhoneInputname="phone-disabled"label="Disabled phone"defaultValue="+1-408 9876543"disabled/>
tsx
<PhoneInputname="phone-readonly-display"label="Phone"defaultCountry="GB"defaultValue="+44 2012345678"readOnlyvariant="outline"/>
rightIcon.tsx
<PhoneInputname="phone-loading-value"label="Validating phone number..."defaultCountry="US"defaultValue="+1-408 0000000"isLoading/>
errorMessage property, it will take precedence over messages from the form provider.tsx
<PhoneInputname="phone-invalid"label="Phone"defaultCountry="BR"errorMessage="Invalid phone number"showAsterisk/>
onChange fornece o número formatado completo com código do país:tsx
const handlePhoneChange = (formattedPhone: string) => {// formattedPhone: string - número formatado com código do paísconsole.log("Número completo:", formattedPhone); // "+55 11999999999"// Use para salvar no estado ou enviar para APIsetPhoneNumber(formattedPhone);};<PhoneInputname="user-phone"label="Seu Telefone"defaultCountry="BR"onChange={handlePhoneChange}/>;
name - string (required)
Field name for form manipulation and identificationlabel - string
Label text to display above the inputshowAsterisk - boolean
Whether to display an asterisk in the label for required fieldserrorMessage - string
Error message to display below the inputsize - "md" | "lg" (default: "md")
Input size variantvariant - "solid" | "outline" (default:solid`)
Visual variant of the inputdefaultValue - string
Default phone number valuedefaultCountry - string
ISO code of the default country to selectdisabled - boolean (default: false)
If the input is disabledreadOnly - boolean (default: false)
If the input is read-onlyisLoading - boolean (default: false)
If the input is in the loading stateclassName - string
Additional CSS classes for stylingid - string
Optional unique identifier for the inputsearchCountryPlaceholder - string (default: `Search Country``)
Text Placeholder for the country search fieldnotFoundCountryText - string (default: "No country found")
Text displayed when no country matches the searchonChange - (formattedPhone: string) => void
Callback function called when the number changes, receives the value formatted with the country code<input> are also supported, except type (which is fixed as tel).@arkyn/templates