phone-input
domain-ui/phone-inputFreeComponent
domain-ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/teurons/domain-ui/main/apps/web/public/r/phone-input.jsonSource
1import * as React from "react";2import { CheckIcon, ChevronsUpDown } from "lucide-react";3import * as RPNInput from "react-phone-number-input";4import flags from "react-phone-number-input/flags";56import { Button } from "@/components/ui/button";7import {8 Command,9 CommandEmpty,10 CommandGroup,11 CommandInput,12 CommandItem,13 CommandList,14} from "@/components/ui/command";15import { Input } from "@/components/ui/input";16import {17 Popover,18 PopoverContent,19 PopoverTrigger,20} from "@/components/ui/popover";21import { ScrollArea } from "@/components/ui/scroll-area";22import { cn } from "@/lib/utils";2324type PhoneInputProps = Omit<25 React.ComponentProps<"input">,26 "onChange" | "value" | "ref"27> &28 Omit<RPNInput.Props<typeof RPNInput.default>, "onChange"> & {29 onChange?: (value: RPNInput.Value) => void;30 };3132const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =33 React.forwardRef<React.ElementRef<typeof RPNInput.default>, PhoneInputProps>(34 ({ className, onChange, value, ...props }, ref) => {35 return (36 <RPNInput.default37 ref={ref}38 className={cn("flex", className)}39 flagComponent={FlagComponent}40 countrySelectComponent={CountrySelect}41 inputComponent={InputComponent}42 smartCaret={false}43 value={value || undefined}44 /**45 * Handles the onChange event.46 *47 * react-phone-number-input might trigger the onChange event as undefined48 * when a valid phone number is not entered. To prevent this,49 * the value is coerced to an empty string.50 *51 * @param {E164Number | undefined} value - The entered value52 */53 onChange={(value) => onChange?.(value || ("" as RPNInput.Value))}54 {...props}55 />56 );57 },58 );59PhoneInput.displayName = "PhoneInput";6061const InputComponent = React.forwardRef<62 HTMLInputElement,63 React.ComponentProps<"input">64>(({ className, ...props }, ref) => (65 <Input66 className={cn("rounded-e-lg rounded-s-none", className)}67 {...props}68 ref={ref}69 />70));71InputComponent.displayName = "InputComponent";7273type CountryEntry = { label: string; value: RPNInput.Country | undefined };7475type CountrySelectProps = {76 disabled?: boolean;77 value: RPNInput.Country;78 options: CountryEntry[];79 onChange: (country: RPNInput.Country) => void;80};8182const CountrySelect = ({83 disabled,84 value: selectedCountry,85 options: countryList,86 onChange,87// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from domain-ui
All 16 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| pan-inputpan-input | domain-ui | Components | Free | no deps | |
| pan-input-incrementalpan-input-incremental | domain-ui | Components | Free | no deps | |
| passport-inputpassport-input | domain-ui | Components | Free | no deps | |
| passport-input-incrementalpassport-input-incremental | domain-ui | Components | Free | no deps | |
| portfolio-chartportfolio-chart | domain-ui | Components | Free | no deps | |
| regex-inputregex-input | domain-ui | Components | Free | no deps · 2 files | |
| regex-input-incrementalregex-input-incremental | domain-ui | Components | Free | no deps · 5 files | |
| responsive-resizable-previewresponsive-resizable-preview | domain-ui | Components | Free | no deps · 3 files |
