phone-input
9ui/phone-inputFreeComponent
9ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by 9ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://9ui.dev/r/phone-input.jsonSource
1import * as React from "react"2import { ChevronsUpDown } from "lucide-react"3import * as BasePhoneInput from "react-phone-number-input"4import flags from "react-phone-number-input/flags"56import { Button } from "@/components/ui/button"7import {8 Combobox,9 ComboboxContent,10 ComboboxEmpty,11 ComboboxInput,12 ComboboxItem,13 ComboboxList,14 ComboboxTrigger,15} from "@/components/ui/combobox"16import { Input } from "@/components/ui/input"1718import { cn } from "@/lib/utils"1920type PhoneInputProps = Omit<21 React.ComponentProps<"input">,22 "onChange" | "value" | "ref"23> &24 Omit<BasePhoneInput.Props<typeof BasePhoneInput.default>, "onChange"> & {25 onChange?: (value: BasePhoneInput.Value) => void26 }2728function PhoneInput({ className, onChange, value, ...props }: PhoneInputProps) {29 return (30 <BasePhoneInput.default31 className={cn(32 "flex",33 props["aria-invalid"] &&34 "[&_*[data-slot=combobox-trigger]]:border-destructive [&_*[data-slot=combobox-trigger]]:ring-destructive/50",35 className36 )}37 flagComponent={FlagComponent}38 countrySelectComponent={CountrySelect}39 inputComponent={InputComponent}40 smartCaret={false}41 value={value || undefined}42 onChange={(value) => onChange?.(value || ("" as BasePhoneInput.Value))}43 {...props}44 />45 )46}4748function InputComponent({49 className,50 ...props51}: React.ComponentProps<typeof Input>) {52 return <Input className={cn("rounded-s-none", className)} {...props} />53}5455type CountryEntry = { label: string; value: BasePhoneInput.Country | undefined }5657type CountrySelectProps = {58 disabled?: boolean59 value: BasePhoneInput.Country60 options: CountryEntry[]61 onChange: (country: BasePhoneInput.Country) => void62}6364function CountrySelect({65 disabled,66 value: selectedCountry,67 options: countryList,68 onChange,69}: CountrySelectProps) {70 return (71 <Combobox items={countryList} value={selectedCountry || ""}>72 <ComboboxTrigger73 render={(props) => (74 <Button75 {...props}76 type="button"77 variant="outline"78 className="flex gap-1 rounded-s-md rounded-e-none border-r-0 px-3 focus:z-10"79 disabled={disabled}80 >81 <FlagComponent82 country={selectedCountry}83 countryName={selectedCountry}84 />85 <ChevronsUpDown className={cn("-mr-1", disabled && "hidden")} />86 </Button>87 )}88 />89 <ComboboxContent className="max-h-[20rem] w-[300px] [--input-container-height:4rem]">90 <ComboboxInput91 className="focus-visible:ring-0"92 inputContainerClassName="mb-2"93// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from 9ui
All 56 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | 9ui | Components | Free | no deps | |
| alertalert | 9ui | Components | Free | no deps | |
| alert-dialogalert-dialog | 9ui | Components | Free | no deps | |
| aspect-ratioaspect-ratio | 9ui | Components | Free | no deps | |
| autocompleteautocomplete | 9ui | Components | Free | no deps | |
| avataravatar | 9ui | Components | Free | no deps | |
| badgebadge | 9ui | Components | Free | no deps | |
| breadcrumbsbreadcrumbs | 9ui | Components | Free | no deps |
