Skip to content

Commit

Permalink
update & fix phone-input from latest modification from shadcn components
Browse files Browse the repository at this point in the history
  • Loading branch information
Jul Guga committed Nov 9, 2024
1 parent b3a61e2 commit 34f1477
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
56 changes: 28 additions & 28 deletions components/ui/phone-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command";
import { Input, InputProps } from "@/components/ui/input";
import { Input } from "@/components/ui/input";
import {
Popover,
PopoverContent,
Expand All @@ -36,38 +36,38 @@ type PhoneInputProps = Omit<
const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =
React.forwardRef<React.ElementRef<typeof RPNInput.default>, PhoneInputProps>(
({ className, onChange, ...props }, ref) => {
return (
return (
<RPNInput.default
ref={ref}
className={cn("flex", className)}
flagComponent={FlagComponent}
countrySelectComponent={CountrySelect}
inputComponent={InputComponent}
smartCaret={false}
/**
* Handles the onChange event.
*
* react-phone-number-input might trigger the onChange event as undefined
* when a valid phone number is not entered. To prevent this,
* the value is coerced to an empty string.
*
* @param {E164Number | undefined} value - The entered value
*/
ref={ref}
className={cn("flex", className)}
flagComponent={FlagComponent}
countrySelectComponent={CountrySelect}
inputComponent={InputComponent}
smartCaret={false}
/**
* Handles the onChange event.
*
* react-phone-number-input might trigger the onChange event as undefined
* when a valid phone number is not entered. To prevent this,
* the value is coerced to an empty string.
*
* @param {E164Number | undefined} value - The entered value
*/
onChange={(value) => onChange?.(value || ("" as RPNInput.Value))}
{...props}
/>
);
{...props}
/>
);
},
);
PhoneInput.displayName = "PhoneInput";

const InputComponent = React.forwardRef<HTMLInputElement, InputProps>(
({ className, ...props }, ref) => (
<Input
const InputComponent = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
({ className, ...props }, ref) => (
<Input
className={cn("rounded-e-lg rounded-s-none", className)}
{...props}
ref={ref}
/>
{...props}
ref={ref}
/>
),
);
InputComponent.displayName = "InputComponent";
Expand Down Expand Up @@ -100,7 +100,7 @@ const CountrySelect = ({
<Button
type="button"
variant={"outline"}
className={cn("flex gap-1 rounded-e-none rounded-s-lg px-3")}
className={cn("flex gap-1 rounded-e-none rounded-s-lg px-3 [&_svg]:h-4 [&_svg]:w-6")}
disabled={disabled}
>
<FlagComponent country={value} countryName={value} />
Expand All @@ -123,7 +123,7 @@ const CountrySelect = ({
.filter((x) => x.value)
.map((option) => (
<CommandItem
className="gap-2"
className="[&_svg]:h-4 [&_svg]:w-6"
key={option.value}
onSelect={() => handleSelect(option.value)}
>
Expand Down
64 changes: 32 additions & 32 deletions content/snippets/phone-input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command";
import { Input, InputProps } from "@/components/ui/input";
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";
import { ScrollArea } from "./scroll-area";

type PhoneInputProps = Omit<
React.InputHTMLAttributes<HTMLInputElement>,
Expand All @@ -42,38 +42,38 @@ type PhoneInputProps = Omit<
const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =
React.forwardRef<React.ElementRef<typeof RPNInput.default>, PhoneInputProps>(
({ className, onChange, ...props }, ref) => {
return (
return (
<RPNInput.default
ref={ref}
className={cn("flex", className)}
flagComponent={FlagComponent}
countrySelectComponent={CountrySelect}
inputComponent={InputComponent}
smartCaret={false}
/**
* Handles the onChange event.
*
* react-phone-number-input might trigger the onChange event as undefined
* when a valid phone number is not entered. To prevent this,
* the value is coerced to an empty string.
*
* @param {E164Number | undefined} value - The entered value
*/
onChange={(value) => onChange?.(value || "")}
{...props}
/>
);
ref={ref}
className={cn("flex", className)}
flagComponent={FlagComponent}
countrySelectComponent={CountrySelect}
inputComponent={InputComponent}
smartCaret={false}
/**
* Handles the onChange event.
*
* react-phone-number-input might trigger the onChange event as undefined
* when a valid phone number is not entered. To prevent this,
* the value is coerced to an empty string.
*
* @param {E164Number | undefined} value - The entered value
*/
onChange={(value) => onChange?.(value || ("" as RPNInput.Value))}
{...props}
/>
);
},
);
PhoneInput.displayName = "PhoneInput";

const InputComponent = React.forwardRef<HTMLInputElement, InputProps>(
({ className, ...props }, ref) => (
<Input
const InputComponent = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
({ className, ...props }, ref) => (
<Input
className={cn("rounded-e-lg rounded-s-none", className)}
{...props}
ref={ref}
/>
{...props}
ref={ref}
/>
),
);
InputComponent.displayName = "InputComponent";
Expand Down Expand Up @@ -106,7 +106,7 @@ const CountrySelect = ({
<Button
type="button"
variant={"outline"}
className={cn("flex gap-1 rounded-e-none rounded-s-lg px-3")}
className={cn("flex gap-1 rounded-e-none rounded-s-lg px-3 [&_svg]:h-4 [&_svg]:w-6")}
disabled={disabled}
>
<FlagComponent country={value} countryName={value} />
Expand All @@ -129,7 +129,7 @@ const CountrySelect = ({
.filter((x) => x.value)
.map((option) => (
<CommandItem
className="gap-2"
className="[&_svg]:h-4 [&_svg]:w-6"
key={option.value}
onSelect={() => handleSelect(option.value)}
>
Expand All @@ -139,7 +139,7 @@ const CountrySelect = ({
/>
<span className="flex-1 text-sm">{option.label}</span>
{option.value && (
<span className="text-foreground/50 text-sm">
<span className="text-sm text-foreground/50">
{`+${RPNInput.getCountryCallingCode(option.value)}`}
</span>
)}
Expand All @@ -164,7 +164,7 @@ const FlagComponent = ({ country, countryName }: RPNInput.FlagProps) => {
const Flag = flags[country];

return (
<span className="bg-foreground/20 flex h-4 w-6 overflow-hidden rounded-sm">
<span className="flex h-4 w-6 overflow-hidden rounded-sm bg-foreground/20">
{Flag && <Flag title={countryName} />}
</span>
);
Expand Down

0 comments on commit 34f1477

Please sign in to comment.