-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor : input components #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/gemini-code-assist ์ฝ๋ ๋ฆฌ๋ทฐ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
์ ๋ฐ์ ์ผ๋ก Input ์ปดํฌ๋ํธ๋ค์ ๋ฆฌํฉํ ๋งํ์ฌ ๊ตฌ์กฐ๋ฅผ ์ ๋ฆฌํ๊ณ ์ฌ์ฌ์ฉ์ฑ์ ๋์ธ ์ข์ PR์
๋๋ค. ํนํ InputField์์ useId๋ฅผ ์ฌ์ฉํ์ฌ ์ ๊ทผ์ฑ์ ๊ฐ์ ํ๊ณ , PasswordInput์ aria ์์ฑ์ ์ถ๊ฐํ ์ ์ด ์ธ์์ ์
๋๋ค. ์ฝ๋ ์ ๋ฐ์ ๊ฑธ์ณ ์ผ๊ด๋ ๊ตฌ์กฐ๋ฅผ ์ ์ฉํ๋ ค๋ ๋
ธ๋ ฅ์ด ๋๋ณด์
๋๋ค.
๋ค๋ง, ๋ช ๊ฐ์ง ๊ฐ์ ์ ์ ์ ์ํฉ๋๋ค.
Input์ปดํฌ๋ํธ๋forwardRef๋ฅผ ์ฌ์ฉํ๋๋ก ๋ฆฌํฉํ ๋งํ์ฌ React์ ํ์คref์ ๋ฌ ๋ฐฉ์์ ๋ฐ๋ฅด๋ ๊ฒ์ด ์ข์ต๋๋ค.InputField์ปดํฌ๋ํธ๊ฐchildrenprop์ ๋ฐ์ ๋,id๋ ์๋ฌ ์คํ์ผ๋ง๊ณผ ๊ฐ์ ์ค์ํ props๋ฅผ ์ ๋ฌํ์ง ์๋ ์ฌ๊ฐํ ๋ฒ๊ทธ๊ฐ ์์ด ์์ ์ ์ ์ํ์ต๋๋ค.PasswordInput์ ์์ด์ฝaltํ ์คํธ๋ฅผ ์ ๊ฑฐํ์ฌ ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ฌ์ฉ์์๊ฒ ์ค๋ณต๋ ์ ๋ณด๊ฐ ์ฝํ์ง ์๋๋ก ๊ฐ์ ํ ์ ์์ต๋๋ค.
์์ธํ ๋ด์ฉ์ ๊ฐ ํ์ผ์ ๋จ๊ธด ์ฝ๋ฉํธ๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
| {children ?? ( | ||
| <Input | ||
| id={id} | ||
| {...props} | ||
| className={clsx( | ||
| error | ||
| ? "border-red-500 focus:ring-red-500" | ||
| : "border-gray-200 focus:ring-primary-500", | ||
| className | ||
| )} | ||
| /> | ||
| )} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
children prop์ ์ฌ์ฉํ ๋, id, ...props ๋ฐ ์๋ฌ ์ํ์ ๋ฐ๋ฅธ className์ด children์ผ๋ก ์ ๋ฌ๋์ง ์์ label๊ณผ input์ ์ฐ๊ฒฐ์ด ๋์ด์ง๊ณ ์๋ฌ ์คํ์ผ๋ง ๋ฐ react-hook-form ์ฐ๋์ด ๋์ํ์ง ์๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ด๋ ์ ๊ทผ์ฑ๊ณผ ์ปดํฌ๋ํธ์ ํต์ฌ ๊ธฐ๋ฅ์ ์ ํดํ๋ ์ฌ๊ฐํ ๋ฌธ์ ์
๋๋ค. React.cloneElement๋ฅผ ์ฌ์ฉํ์ฌ children์๊ฒ ํ์ํ props๋ฅผ ์ฃผ์
ํด์ผ ํฉ๋๋ค. ๋ํ import { useId, ReactNode, cloneElement } from "react";์ ๊ฐ์ด cloneElement๋ฅผ importํด์ผ ํฉ๋๋ค.
{children ? (
cloneElement(children as React.ReactElement, {
id,
...props,
className: clsx(
error
? "border-red-500 focus:ring-red-500"
: "border-gray-200 focus:ring-primary-500",
(children as React.ReactElement).props.className,
className
),
})
) : (
<Input
id={id}
{...props}
className={clsx(
error
? "border-red-500 focus:ring-red-500"
: "border-gray-200 focus:ring-primary-500",
className
)}
/>
)}
| type InputProps = ComponentProps<"input"> & { | ||
| inputRef?: React.Ref<HTMLInputElement>; | ||
| }; | ||
|
|
||
| export function Input({ className, inputRef, ...props }: InputProps) { | ||
| return ( | ||
| <input {...props} className={clsx("border rounded px-3 py-2", className)} /> | ||
| <input | ||
| ref={inputRef} | ||
| {...props} | ||
| className={clsx( | ||
| "h-[54px] w-full rounded-[16px] border px-[20px] text-sm outline-none", | ||
| className | ||
| )} | ||
| /> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputRef prop์ ์ฌ์ฉํ๋ ๋์ React.forwardRef๋ฅผ ์ฌ์ฉํ์ฌ ref๋ฅผ ์ง์ ์ ๋ฌํ๋ ๊ฒ์ด ๋ ์ผ๋ฐ์ ์ธ React ํจํด์ด๋ฉฐ, ์ปดํฌ๋ํธ์ ์ฌ์ฌ์ฉ์ฑ๊ณผ ๊ฐ๋
์ฑ์ ๋์
๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ๋ถ๋ชจ ์ปดํฌ๋ํธ์์ useRef๋ฅผ ์ฌ์ฉํ ๋ ๋ ์ง๊ด์ ์ผ๋ก ref๋ฅผ ์ ๋ฌํ ์ ์์ต๋๋ค. import { ComponentProps, forwardRef } from "react";์ ๊ฐ์ด forwardRef๋ฅผ importํด์ผ ํฉ๋๋ค.
| type InputProps = ComponentProps<"input"> & { | |
| inputRef?: React.Ref<HTMLInputElement>; | |
| }; | |
| export function Input({ className, inputRef, ...props }: InputProps) { | |
| return ( | |
| <input {...props} className={clsx("border rounded px-3 py-2", className)} /> | |
| <input | |
| ref={inputRef} | |
| {...props} | |
| className={clsx( | |
| "h-[54px] w-full rounded-[16px] border px-[20px] text-sm outline-none", | |
| className | |
| )} | |
| /> | |
| ); | |
| } | |
| export const Input = forwardRef<HTMLInputElement, ComponentProps<"input">>( | |
| ({ className, ...props }, ref) => { | |
| return ( | |
| <input | |
| ref={ref} | |
| {...props} | |
| className={clsx( | |
| "h-[54px] w-full rounded-[16px] border px-[20px] text-sm outline-none", | |
| className | |
| )} | |
| /> | |
| ); | |
| } | |
| ); | |
| Input.displayName = "Input"; |
components/input/passwordinput.tsx
Outdated
| <Image | ||
| src={visible ? "/icon_active_on.svg" : "/icon_active_off.svg"} | ||
| alt={visible ? "๋น๋ฐ๋ฒํธ ์จ๊ธฐ๊ธฐ" : "๋น๋ฐ๋ฒํธ ๋ณด๊ธฐ"} | ||
| alt={visible ? "๋น๋ฐ๋ฒํธ ์จ๊ธฐ๊ธฐ ์์ด์ฝ" : "๋น๋ฐ๋ฒํธ ๋ณด๊ธฐ ์์ด์ฝ"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฒํผ์ aria-label์ด ์ด๋ฏธ "๋น๋ฐ๋ฒํธ ์จ๊ธฐ๊ธฐ" / "๋น๋ฐ๋ฒํธ ํ์"๋ก ๋ช
ํํ๊ฒ ์ค์ ๋์ด ์์ผ๋ฏ๋ก, ๋ด๋ถ์ ์๋ ์์ด์ฝ์ ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ฌ์ฉ์์๊ฒ ์ค๋ณต๋ ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค. ์ด๋ฐ ๊ฒฝ์ฐ, ์ฅ์์ฉ ์ด๋ฏธ์ง๋ก ์ทจ๊ธํ์ฌ alt ์์ฑ์ ๋น ๋ฌธ์์ด("")๋ก ์ค์ ํ๋ ๊ฒ์ด ์ ๊ทผ์ฑ ๋ชจ๋ฒ ์ฌ๋ก์
๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์คํฌ๋ฆฐ ๋ฆฌ๋๊ฐ ์์ด์ฝ์ ๋ถํ์ํ๊ฒ ์ฝ์ง ์๊ฒ ๋ฉ๋๋ค.
| alt={visible ? "๋น๋ฐ๋ฒํธ ์จ๊ธฐ๊ธฐ ์์ด์ฝ" : "๋น๋ฐ๋ฒํธ ๋ณด๊ธฐ ์์ด์ฝ"} | |
| alt="" |
๐ฏ ์์ ๋ด์ฉ
โ ์ฒดํฌ๋ฆฌ์คํธ
๐ธ ์คํฌ๋ฆฐ์ท (์ ํ์ฌํญ)
(ํ์ ์ ํ๋ฉด ์บก์ฒ ์ฒจ๋ถ)
๐ฌ ์ถ๊ฐ ์ค๋ช