Phone Input
An international phone number input with country selection and formatting.
Overview
PhoneInput combines a country selector and phone number field into one attached input group. It uses Cubitt Button, Input, and Combobox primitives under the hood, with international formatting from react-phone-number-input.
Usage
import { PhoneInput } from "@tilt-legal/cubitt-components/phone-input";<PhoneInput placeholder="Enter phone number" />Examples
States
Default, error, disabled, and readonly states.
import { PhoneInput } from "@tilt-legal/cubitt-components/phone-input";
const states = ["default", "error", "disabled", "readonly"] as const;
const [state, setState] =
useState<"default" | "error" | "disabled" | "readonly">("default");
<>
<PhoneInput
aria-invalid={state === "error" ? true : undefined}
disabled={state === "disabled"}
placeholder={
state === "readonly"
? "Readonly"
: `${state[0]?.toUpperCase()}${state.slice(1)}`
}
readOnly={state === "readonly"}
/>
<PreviewFooter>
<ToggleGroup
aria-label="Phone input state"
groupVariant="segmented"
multiple={false}
onValueChange={(value) => {
if (states.includes(value as (typeof states)[number])) {
setState(value as (typeof states)[number]);
}
}}
value={state}
>
<ToggleGroupItem value="default">Default</ToggleGroupItem>
<ToggleGroupItem value="error">Error</ToggleGroupItem>
<ToggleGroupItem value="disabled">Disabled</ToggleGroupItem>
<ToggleGroupItem value="readonly">Readonly</ToggleGroupItem>
</ToggleGroup>
</PreviewFooter>
</>;Basic
A standard phone input with country selection.
import { PhoneInput } from "@tilt-legal/cubitt-components/phone-input";
<PhoneInput placeholder="Enter phone number" />;Sizes
Phone input in different sizes.
import { Label } from "@tilt-legal/cubitt-components/label";
import { PhoneInput } from "@tilt-legal/cubitt-components/phone-input";
<Label>
Small
<PhoneInput placeholder="Enter phone number" size="sm" />
</Label>
<Label>
Medium
<PhoneInput placeholder="Enter phone number" />
</Label>
<Label>
Large
<PhoneInput placeholder="Enter phone number" size="lg" />
</Label>API Reference
PhoneInput
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Phone number value in E.164 format. |
onChange | (value: string) => void | – | Callback when the phone number changes. |
size | "sm" | "md" | "lg" | "md" | Input size. |
placeholder | string | – | Placeholder text for the phone number field. |
disabled | boolean | false | Disables the country selector and phone number field. |
readOnly | boolean | false | Makes the number readonly and prevents country selector changes. |
defaultCountry | Country | "AU" | Default country code, such as "US", "GB", or "AU". |
countries | Country[] | – | Country codes to display. Shows all countries when omitted. |
popupClassName | string | – | Additional classes for the country selection popup. |
className | string | – | Additional classes for the phone number input element. |
aria-invalid | boolean | – | Applies error styling to the phone number input. |
Types
import type { PhoneCountry } from "@tilt-legal/cubitt-components/phone-input";PhoneCountry is the Country type from react-phone-number-input.