Phone Input

Champ de numero de telephone avec selecteur d'indicatif pays. Installez Phone Input depuis le registre VLLNT UI avec la CLI shadcn.

Signaler un bug

Champ de numero de telephone avec selecteur d'indicatif pays. Fait partie de la famille form dans VLLNT UI, il est publie comme entree de registre lisible par machine — copiez la source directement dans votre application avec la CLI shadcn et possedez-la, sans dependance d'execution a une bibliotheque de composants.

Apercu

Basculez entre clair et sombre pour inspecter l'apercu Storybook integre.

Installation

Ajoutez Phone Input a votre projet avec la CLI shadcn. La source arrive dans votre code, prete a etre adaptee :

pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/phone-input.json

Source

"use client"; import * as React from "react"; import { cn } from "../../lib/utils"; /** Country option rendered in the dialing-code selector. */ export type PhoneCountry = { code: string; dialCode: string; label: string; }; const defaultCountries: PhoneCountry[] = [ { code: "US", dialCode: "+1", label: "United States" }, { code: "GB", dialCode: "+44", label: "United Kingdom" }, { code: "CA", dialCode: "+1", label: "Canada" }, { code: "AU", dialCode: "+61", label: "Australia" }, { code: "DE", dialCode: "+49", label: "Germany" }, { code: "FR", dialCode: "+33", label: "France" }, { code: "IN", dialCode: "+91", label: "India" }, { code: "JP", dialCode: "+81", label: "Japan" }, ]; /** Phone number input with a leading country dialing-code selector. */ export type PhoneInputProps = Omit< React.ComponentPropsWithoutRef<"input">, "type" > & { countries?: PhoneCountry[]; defaultCountry?: string; onCountryChange?: (code: string) => void; }; const PhoneInput = ({ className, countries = defaultCountries, defaultCountry, onCountryChange, ref, ...props }: PhoneInputProps & { ref?: React.Ref<HTMLInputElement> }) => { const [country, setCountry] = React.useState( defaultCountry ?? countries[0]?.code ?? "", ); return ( <div className={cn( "flex h-10 w-full items-center rounded-md border border-input bg-background text-sm ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2", className, )} > <select aria-label="Country dialing code" className="h-full rounded-l-md border-0 border-r border-input bg-transparent py-2 pl-3 pr-2 text-sm focus-visible:outline-none disabled:cursor-not-allowed" onChange={(event) => { setCountry(event.target.value); onCountryChange?.(event.target.value); }} value={country} > {countries.map((item) => ( <option key={item.code} value={item.code}> {item.dialCode} </option> ))} </select> <input {...props} className="h-full w-full flex-1 rounded-r-md bg-transparent px-3 py-2 placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed" ref={ref} type="tel" /> </div> ); }; PhoneInput.displayName = "PhoneInput"; export { PhoneInput };

Stories

Explorez chaque variante et etat dans le Storybook interactif :

Apercu

Basculez entre clair et sombre pour inspecter l'apercu Storybook integre.

Dependances

  • @vllnt/ui@^0.3.0