Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Forms

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
01

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.

AstroCode target · live preview uses Astro
Check this contact number.
+576015550123
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.
astro
---
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>
Edit PhoneInput in browser

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.

02

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.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add PhoneInput

API 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.

AttributeValuesDefaultDescription
id / input-idstringGeneratedAssociates a visible label with the number input; Web Components use input-id.
inputPropsinput attributes-Passes native number-input attributes without DOM patches.
inputRefReact ref-Exposes the native number-input ref.
disabled / readOnly / requiredbooleanfalseLocks both controls when disabled or read-only and supports native required validation.
errorMessage / showValidationErrorstring / boolean- / trueShows an associated field error or metadata validation feedback.
countryOptionsLumenPhoneCountry[]Generated metadataRestricts 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.
countryNamestring"country"Sets the name of the country dial-code select.
countryLabelstring"Country code"Sets the accessible label for the dial-code select.
countryValue / defaultCountryValue / countryISO region or calling code"US"Selects the initial country by region or calling code: countryValue in Astro, defaultCountryValue in React, and country in Elements.
localestring | string[]Runtime localeLocalizes generated country names.
namestring"phone"Sets the name of the telephone number input.
placeholderstring"Phone number"Sets the placeholder for the number input.
valuestring (Astro / Elements) | LumenPhoneNumber (React)UncontrolledSets 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, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML 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.

cssScoped theme overrides
.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.

HookValuesDefaultContract
class, classNamestring""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


Web docsFull catalog