# Phone Field (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-phone-field` · version 1.0.0 · component · pro (Pro)
- category: Inputs
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/lumen-phone-field`
- npm dependencies: libphonenumber-js@^1
- registry dependencies: utils, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-phone-field
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A phone number in one well: the country in its own compartment (search 240+ by name, code or dial code), the number formatting as you type, and three cells that light as it becomes possible, then valid. Paste +44… and the country follows; the value is E.164.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: `libphonenumber-js@^1`.
- Files: `components/ui/lumen/controls/phone-field.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `PhoneField`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-foreground`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-chart-accent`, `--lumen-chart-accent-foreground`, `--lumen-chart-accent-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { PhoneField } from "@/components/ui/lumen/controls/phone-field";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `PhoneField` | — | The well, the country picker and the meter. |

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/controls/phone-field.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- phone input, phone number field, country code picker, international phone, E.164, sign up phone, Lumen
- Sign-up, checkout and contact forms that need a number you can call or text

### Not when
- Collecting a free-form contact note: use Textarea

## Mistakes
- Validate on the server too: valid means well formed, not that it rings
- Store E.164, not the formatted text

## Usage

```tsx
"use client";

import * as React from "react";
import { PhoneField } from "@/components/ui/lumen/controls/phone-field";

export function SignUpPhone() {
  const [phone, setPhone] = React.useState<string | null>(null);
  return <PhoneField name="phone" defaultCountry="GB" preferredCountries={["GB", "US", "IN"]} onValueChange={setPhone} />;
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `defaultValue / value` | `string (E.164)` |  | Such as "+442071838750"; the field reads the country from it. |
| `onValueChange` | `(e164 \| null, details) => void` |  | E.164 once the number is possible, else null; details has country, national digits, possible and valid. |
| `defaultCountry / country / onCountryChange` | `CountryCode` | `"US"` | The starting or controlled country (ISO 3166 code). |
| `preferredCountries` | `CountryCode[]` |  | Listed first in the picker. |
| `locale` | `string` | `"en-US"` | The language for country names (Intl.DisplayNames). Pass your app's locale. |
| `name` | `string` |  | A hidden input sends E.164 with the form. |
| `labels` | `object` |  | Every word: country, search, noMatch, possible, valid, incomplete. |

Full docs: https://beautiful-ui.dev/components/lumen-phone-field

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Enter or Space (country) | Open the picker |
| Arrow keys, Enter | Choose a country |
| Escape | Close, back to the number |

## Motion inventory

| Interaction | What moves |
|---|---|
| Typing | Digits group as you type; the three cells light grey, then amber (possible), then green (valid) |

## Accessibility contract (preserve when editing)
- The country button names the country and code; its picker is a combobox with a listbox (arrows, Enter, Escape)
- Whether the number is incomplete, possible or valid is announced in words, not only with the cells

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/lumen-phone-field
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- libphonenumber-js (https://github.com/catamphetamine/libphonenumber-js)

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
