Skip to content
العربية
Saudi forms and dates

PhoneInput

GCC phone number with a country menu. Accepts Arabic digits, spaces and +966; store normalizePhone(). The country names come from the strings (countries). With a name, the form also posts the country code as <name>-country (or countryName), also without JavaScript.

import { PhoneInput, normalizePhone } from "@percentsa/ui";

Examples

Stored as: —

Code
export function PhoneInputExample() {
  const t = useT();
  const [draft, setDraft] = useState("");
  const [country, setCountry] = useState<PhoneCountryCode>("SA");
  return (
    <Stack gap={3} className="w-full max-w-sm">
      <Field label={t("Mobile number", "رقم الجوال")}>
        <PhoneInput value={draft} onValueChange={setDraft} country={country} onCountryChange={setCountry} />
      </Field>
      <Text size="sm" tone="subtle">
        {t("Stored as: ", "يُحفظ كالتالي: ")}
        <span dir="ltr">{normalizePhone(draft, country) ?? "—"}</span>
      </Text>
    </Stack>
  );
}