From 711ea928bea2bf34b0c54925778b535ae04f72d5 Mon Sep 17 00:00:00 2001 From: "Amir H. Khanjani" <72540492+ahkhanjani@users.noreply.github.com> Date: Sat, 16 Nov 2024 21:06:29 +0330 Subject: [PATCH] fix: snippet type, linting, and code refactor (#53) * remove unnecessary filter * remove unnecessary displayName assignment * remove another unnecessary check * use tailwind size instead of h and w + format * some refactor and cleanup * fix: update PhoneInputProps to omit "ref" in type definition --------- Co-Authored-By: omeralpi --- components/ui/phone-input.tsx | 97 ++++++++++++++++---------------- content/snippets/phone-input.mdx | 93 +++++++++++++++--------------- 2 files changed, 98 insertions(+), 92 deletions(-) diff --git a/components/ui/phone-input.tsx b/components/ui/phone-input.tsx index 05aa88f..261c12a 100644 --- a/components/ui/phone-input.tsx +++ b/components/ui/phone-input.tsx @@ -21,13 +21,13 @@ import { 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, - "onChange" | "value" + React.ComponentProps<"input">, + "onChange" | "value" | "ref" > & Omit, "onChange"> & { onChange?: (value: RPNInput.Value) => void; @@ -53,7 +53,7 @@ const PhoneInput: React.ForwardRefExoticComponent = * * @param {E164Number | undefined} value - The entered value */ - onChange={(value) => onChange?.(value || ("" as RPNInput.Value))} + onChange={(value) => onChange?.(value || "")} {...props} /> ); @@ -72,41 +72,37 @@ const InputComponent = React.forwardRef( ); InputComponent.displayName = "InputComponent"; -type CountrySelectOption = { label: string; value: RPNInput.Country }; +type CountryEntry = { label: string; value: RPNInput.Country | undefined }; type CountrySelectProps = { disabled?: boolean; value: RPNInput.Country; - onChange: (value: RPNInput.Country) => void; - options: CountrySelectOption[]; + options: CountryEntry[]; + onChange: (country: RPNInput.Country) => void; }; const CountrySelect = ({ disabled, - value, + value: selectedCountry, + options: countryList, onChange, - options, }: CountrySelectProps) => { - const handleSelect = React.useCallback( - (country: RPNInput.Country) => { - onChange(country); - }, - [onChange], - ); - return (