import { CheckIcon, ChevronsUpDown } from "lucide-react"; import * as React from "react"; import * as RPNInput from "react-phone-number-input"; import flags from "react-phone-number-input/flags"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Input } from "@/components/ui/input"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { ScrollArea } from "@/components/ui/scroll-area"; import { cn } from "@/lib/utils"; type PhoneInputProps = Omit< React.ComponentProps<"input">, "onChange" | "value" | "ref" > & Omit, "onChange"> & { onChange?: (value: RPNInput.Value) => void; }; const PhoneInput: React.ForwardRefExoticComponent = React.forwardRef, PhoneInputProps>( ({ className, onChange, ...props }, ref) => { return ( onChange?.(value || ("" as RPNInput.Value))} {...props} /> ); }, ); PhoneInput.displayName = "PhoneInput"; const InputComponent = React.forwardRef< HTMLInputElement, React.ComponentProps<"input"> >(({ className, ...props }, ref) => ( )); InputComponent.displayName = "InputComponent"; type CountryEntry = { label: string; value: RPNInput.Country | undefined }; type CountrySelectProps = { disabled?: boolean; value: RPNInput.Country; options: CountryEntry[]; onChange: (country: RPNInput.Country) => void; }; const CountrySelect = ({ disabled, value: selectedCountry, options: countryList, onChange, }: CountrySelectProps) => { return ( No country found. {countryList.map(({ value, label }) => value ? ( ) : null, )} ); }; interface CountrySelectOptionProps extends RPNInput.FlagProps { selectedCountry: RPNInput.Country; onChange: (country: RPNInput.Country) => void; } const CountrySelectOption = ({ country, countryName, selectedCountry, onChange, }: CountrySelectOptionProps) => { return ( onChange(country)}> {countryName} {`+${RPNInput.getCountryCallingCode(country)}`} ); }; const FlagComponent = ({ country, countryName }: RPNInput.FlagProps) => { const Flag = flags[country]; return ( {Flag && } ); }; export { PhoneInput };