PhoneInput
Combines localized country metadata, calling codes, formatting, validation, and E.164 output.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add PhoneInput- Interaction
- Enhanced runtime
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View PhoneInput code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import { Label, PhoneInput, PhoneNumber } from '@santi020k/lumen-astro'
import { getLumenPhoneCountry, resolveLumenPhoneNumber } from '@santi020k/lumen-core'
const colombia = getLumenPhoneCountry('CO', { locale: 'en-US' })
if (!colombia) throw new Error('Missing Colombia phone metadata')
const contact = resolveLumenPhoneNumber(colombia, '+576015550123')
---
<div style="display: grid; gap: 1rem; width: 100%; max-width: 24rem;">
<div>
<Label for="ex-phone">Phone number</Label>
<PhoneInput countryValue="CO" id="ex-phone" name="phone" placeholder="601 5550123" locale="en-US" required />
</div>
<div>
<Label for="ex-phone-sm">Small</Label>
<PhoneInput countryValue="GB" id="ex-phone-sm" name="phone-sm" placeholder="Mobile number" visualSize="sm" />
</div>
<div>
<Label for="ex-phone-lg">Large</Label>
<PhoneInput countryValue="ES" id="ex-phone-lg" name="phone-lg" placeholder="Work number" visualSize="lg" value="612345678" />
</div>
<div>
<Label for="ex-phone-disabled">Disabled</Label>
<PhoneInput countryValue="CO" disabled id="ex-phone-disabled" name="phone-disabled" value="6015550123" />
</div>
<div>
<Label for="ex-phone-readonly">Read only</Label>
<PhoneInput countryValue="CO" id="ex-phone-readonly" name="phone-readonly" readOnly value="6015550123" />
</div>
<div>
<Label for="ex-phone-error">Field error</Label>
<PhoneInput countryValue="CO" errorMessage="Check this contact number." id="ex-phone-error" name="phone-error" value="601" />
</div>
<PhoneNumber value={contact} link />
</div>import { Label, PhoneInput, PhoneNumber } from '@santi020k/lumen-react'
import { getLumenPhoneCountry, resolveLumenPhoneNumber } from '@santi020k/lumen-core'
const colombia = getLumenPhoneCountry('CO', { locale: 'en-US' })
if (!colombia) throw new Error('Missing Colombia phone metadata')
const contact = resolveLumenPhoneNumber(colombia, '+576015550123')
export const Example = () => (
<>
<div style={{ "display": "grid", "gap": "1rem", "width": "100%", "maxWidth": "24rem" }}>
<div>
<Label htmlFor="ex-phone">Phone number</Label>
<PhoneInput defaultCountryValue="CO" id="ex-phone" name="phone" placeholder="601 5550123" locale="en-US" required />
</div>
<div>
<Label htmlFor="ex-phone-sm">Small</Label>
<PhoneInput defaultCountryValue="GB" id="ex-phone-sm" name="phone-sm" placeholder="Mobile number" visualSize="sm" />
</div>
<div>
<Label htmlFor="ex-phone-lg">Large</Label>
<PhoneInput defaultCountryValue="ES" id="ex-phone-lg" name="phone-lg" placeholder="Work number" visualSize="lg" defaultValue="612345678" />
</div>
<div>
<Label htmlFor="ex-phone-disabled">Disabled</Label>
<PhoneInput defaultCountryValue="CO" disabled id="ex-phone-disabled" name="phone-disabled" defaultValue="6015550123" />
</div>
<div>
<Label htmlFor="ex-phone-readonly">Read only</Label>
<PhoneInput defaultCountryValue="CO" id="ex-phone-readonly" name="phone-readonly" readOnly defaultValue="6015550123" />
</div>
<div>
<Label htmlFor="ex-phone-error">Field error</Label>
<PhoneInput defaultCountryValue="CO" errorMessage="Check this contact number." id="ex-phone-error" name="phone-error" defaultValue="601" />
</div>
<PhoneNumber value={contact} link />
</div>
</>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-field>
<lumen-label for="contact-phone">Phone number</lumen-label>
<lumen-phone-input
country="CO"
input-id="contact-phone"
locale="en-US"
name="phone"
placeholder="601 5550123"
required
visual-size="default"
></lumen-phone-input>
</lumen-field>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let mut phone = use_signal(|| None::<PhoneInputNumber>);
rsx! {
PhoneInput {
default_country_value: "CO",
on_value_change: move |number| phone.set(Some(number)),
}
if let Some(number) = phone() {
PhoneNumber { link: true, value: number }
}
}
}Framework differences
React: Use defaultCountryValue and defaultValue for initial values. Controlled value and onValueChange use the structured LumenPhoneNumber contract.
Elements: Set country for the initial country and input-id for the labeled number input. The element builds its country list from generated metadata; the Astro/React countryOptions prop is not an Elements attribute.
Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add PhoneInputpnpm add @santi020k/lumen-reactlumen add PhoneInput --target reactpnpm add @santi020k/lumen-elementslumen add PhoneInput --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| id / input-id | string | Generated | Associates a visible label with the number input; Web Components use input-id. |
| inputProps | input attributes | - | Passes native number-input attributes without DOM patches. |
| inputRef | React ref | - | Exposes the native number-input ref. |
| disabled / readOnly / required | boolean | false | Locks both controls when disabled or read-only and supports native required validation. |
| errorMessage / showValidationError | string / boolean | - / true | Shows an associated field error or metadata validation feedback. |
| countryOptions | LumenPhoneCountry[] | Generated metadata | Restricts or reorders the picker to these localized countries while retaining formatting and E.164 behavior. Replaces the removed countries prop in v6; build entries with getLumenPhoneCountry. |
| countryName | string | "country" | Sets the name of the country dial-code select. |
| countryLabel | string | "Country code" | Sets the accessible label for the dial-code select. |
| countryValue / defaultCountryValue / country | ISO region or calling code | "US" | Selects the initial country by region or calling code: countryValue in Astro, defaultCountryValue in React, and country in Elements. |
| locale | string | string[] | Runtime locale | Localizes generated country names. |
| name | string | "phone" | Sets the name of the telephone number input. |
| placeholder | string | "Phone number" | Sets the placeholder for the number input. |
| value | string (Astro / Elements) | LumenPhoneNumber (React) | Uncontrolled | Sets the national input value; React accepts the structured phone-number contract. |
| onValueChange | (value: LumenPhoneNumber) => void | - | Receives formatting, validity, and E.164 changes in React. |
| visualSize / visual-size | "default" | "sm" | "lg" | "default" | Controls the height and font size of both controls. Elements uses visual-size; size is not a visual-size alias. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize PhoneInput
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-phone-input {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-phone-input through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
| Hook | Values | Default | Contract |
|---|---|---|---|
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope