Components
Phone input
NativeA country calling code and a formatted national number with a combined form value.
The courier will only call if they need help finding your address.
Installation
npx nook-ui@latest add phone-inputPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Phone input" component to this project, exactly as Nook ships it.
A country calling code and a formatted national number with a combined form value.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add phone-input`. It writes `components/ui/phone-input.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/phone-input.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { PhoneInput } from "@/components/ui/phone-input";
export default function Example() {
return (
<div className="grid w-full max-w-md gap-2">
<PhoneInput
label="Delivery contact"
name="phone"
defaultValue={{ country: "SG", nationalNumber: "81234567" }}
/>
<p className="text-xs text-muted-foreground">
The courier will only call if they need help finding your address.
</p>
</div>
);
}
```
API
- `PhoneInput`: A country calling code and a formatted national number with a combined form value.
- `value / defaultValue` (`PhoneValue`): Country ID and national number digits.
- `onValueChange` (`(value: PhoneValue) => void`): Receives digits and country.
- `countries` (`PhoneCountry[]`): Calling codes and formatting groups.
- `name` (`string`): Submits the combined international number.
- `label` (`string`): Visible phone number label.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Separate labels identify the country code and phone number; uses tel input mode and autocomplete.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { PhoneInput } from "@/components/ui/phone-input";
export default function Example() {
return (
<div className="grid w-full max-w-md gap-2">
<PhoneInput
label="Delivery contact"
name="phone"
defaultValue={{ country: "SG", nationalNumber: "81234567" }}
/>
<p className="text-xs text-muted-foreground">
The courier will only call if they need help finding your address.
</p>
</div>
);
}Props
PhoneInput
A country calling code and a formatted national number with a combined form value.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue | PhoneValue | – | Country ID and national number digits. |
| onValueChange | (value: PhoneValue) => void | – | Receives digits and country. |
| countries | PhoneCountry[] | – | Calling codes and formatting groups. |
| name | string | – | Submits the combined international number. |
| label | string | – | Visible phone number label. |
Accessibility
Separate labels identify the country code and phone number; uses tel input mode and autocomplete.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.