From 4b563b0d818607425ad8c2db7690680d40a581bc Mon Sep 17 00:00:00 2001 From: "Amir H. Khanjani" <72540492+ahkhanjani@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:17:54 +0330 Subject: [PATCH 01/10] remove unnecessary filter value is always truthy --- content/snippets/phone-input.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/content/snippets/phone-input.mdx b/content/snippets/phone-input.mdx index 83ba8c9..7518ae3 100644 --- a/content/snippets/phone-input.mdx +++ b/content/snippets/phone-input.mdx @@ -126,7 +126,6 @@ const CountrySelect = ({ No country found. {options - .filter((x) => x.value) .map((option) => ( Date: Mon, 11 Nov 2024 13:19:30 +0330 Subject: [PATCH 02/10] remove another unnecessary check --- content/snippets/phone-input.mdx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/content/snippets/phone-input.mdx b/content/snippets/phone-input.mdx index 7518ae3..4f93f3a 100644 --- a/content/snippets/phone-input.mdx +++ b/content/snippets/phone-input.mdx @@ -137,11 +137,9 @@ const CountrySelect = ({ countryName={option.label} /> {option.label} - {option.value && ( - - {`+${RPNInput.getCountryCallingCode(option.value)}`} - - )} + + {`+${RPNInput.getCountryCallingCode(option.value)}`} + Date: Mon, 11 Nov 2024 13:20:57 +0330 Subject: [PATCH 03/10] remove unnecessary displayName assignment --- content/snippets/phone-input.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/content/snippets/phone-input.mdx b/content/snippets/phone-input.mdx index 4f93f3a..64195c2 100644 --- a/content/snippets/phone-input.mdx +++ b/content/snippets/phone-input.mdx @@ -166,7 +166,6 @@ const FlagComponent = ({ country, countryName }: RPNInput.FlagProps) => { ); }; -FlagComponent.displayName = "FlagComponent"; export { PhoneInput }; ``` From af0247b4acab8fce718fae0fde5cc0bb3aad4c73 Mon Sep 17 00:00:00 2001 From: "Amir H. Khanjani" <72540492+ahkhanjani@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:30:36 +0330 Subject: [PATCH 04/10] cast a type --- content/snippets/phone-input.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/snippets/phone-input.mdx b/content/snippets/phone-input.mdx index 64195c2..516677c 100644 --- a/content/snippets/phone-input.mdx +++ b/content/snippets/phone-input.mdx @@ -59,7 +59,7 @@ const PhoneInput: React.ForwardRefExoticComponent = * * @param {E164Number | undefined} value - The entered value */ - onChange={(value) => onChange?.(value || "")} + onChange={(value) => onChange?.(value || ("" as RPNInput.Value))} {...props} /> ); From 5d1c721a3745b9be7d67ce2879fa6cd473533603 Mon Sep 17 00:00:00 2001 From: "Amir H. Khanjani" <72540492+ahkhanjani@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:38:37 +0330 Subject: [PATCH 05/10] use tailwind size instead of h and w + format --- content/snippets/phone-input.mdx | 49 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/content/snippets/phone-input.mdx b/content/snippets/phone-input.mdx index 516677c..6a91445 100644 --- a/content/snippets/phone-input.mdx +++ b/content/snippets/phone-input.mdx @@ -112,7 +112,7 @@ const CountrySelect = ({ @@ -125,29 +125,28 @@ const CountrySelect = ({ No country found. - {options - .map((option) => ( - handleSelect(option.value)} - > - - {option.label} - - {`+${RPNInput.getCountryCallingCode(option.value)}`} - - - - ))} + {options.map((option) => ( + handleSelect(option.value)} + > + + {option.label} + + {`+${RPNInput.getCountryCallingCode(option.value)}`} + + + + ))} @@ -161,7 +160,7 @@ const FlagComponent = ({ country, countryName }: RPNInput.FlagProps) => { const Flag = flags[country]; return ( - + {Flag && } ); From f345dffa88aac5304ed2d408234405b73465178c Mon Sep 17 00:00:00 2001 From: "Amir H. Khanjani" <72540492+ahkhanjani@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:29:13 +0330 Subject: [PATCH 06/10] some refactor and cleanup --- content/snippets/phone-input.mdx | 82 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/content/snippets/phone-input.mdx b/content/snippets/phone-input.mdx index 6a91445..ed3f14e 100644 --- a/content/snippets/phone-input.mdx +++ b/content/snippets/phone-input.mdx @@ -78,38 +78,34 @@ 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 (