-
Notifications
You must be signed in to change notification settings - Fork 0
[REFACTOR] 공용 버튼 컴포넌트 재사용성 향상 #218
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
base: develop
Are you sure you want to change the base?
Changes from 8 commits
f525dff
d638896
755274c
18dd1df
c6e7b7d
6abdf55
f8b6c97
97511d6
b8a80ef
6da04c6
beab41d
6cc7e83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,52 @@ | ||
| import Pencil from "../../assets/icons/pencil-primary-500.svg"; | ||
| import type { ReactElement } from "react"; | ||
| import { twMerge } from "tailwind-merge"; | ||
|
|
||
| interface ButtonProps { | ||
| onClick?: () => void; | ||
| text: string; | ||
| type: "button" | "submit" | "reset"; | ||
| interface ButtonType { | ||
| children: ReactElement | string; | ||
| size: "Btn_L" | "Btn_M" | "Btn_S"; | ||
| variant: "primary" | "gray" | "transparent"; | ||
| disabled?: boolean; | ||
| bgColor?: "primary" | "white"; | ||
| onClick?: () => void; | ||
| type?: "button" | "submit" | "reset"; | ||
| className: string; | ||
| } | ||
|
Comment on lines
+4
to
8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
인터페이스에서 🛠️ 제안 수정안 interface ButtonType extends ButtonHTMLAttributes<HTMLButtonElement> {
children: ReactNode;
- size: "Btn_L" | "Btn_M" | "Btn_S";
- variant: "primary" | "gray" | "transparent";
+ size?: "Btn_L" | "Btn_M" | "Btn_S";
+ variant?: "primary" | "gray" | "transparent";
}🤖 Prompt for AI Agents |
||
|
|
||
| export default function Button({ | ||
| const SIZES = { | ||
| Btn_L: "px-[10px] py-[16px]", | ||
| Btn_S: "px-[24px] py-[6px]", | ||
| Btn_M: "px-[10px] py-[16px]", // padding을 className에 직접 지정 가능 | ||
| }; | ||
| const VARIANTS = { | ||
| primary: "bg-primary-700 text-white", | ||
| gray: "bg-gray-100", | ||
| transparent: "bg-transparent border-1 border-primary-700", | ||
| }; | ||
|
|
||
| const Button = ({ | ||
| children = "", | ||
| size = "Btn_M", | ||
|
jangmk05 marked this conversation as resolved.
Outdated
|
||
| variant = "primary", | ||
| disabled = false, | ||
| onClick, | ||
| text, | ||
| type, | ||
| disabled, | ||
| bgColor = "primary", | ||
| }: ButtonProps) { | ||
| className, | ||
| }: ButtonType) => { | ||
| const sizeClass = SIZES[size]; | ||
| const variantClass = VARIANTS[variant]; | ||
| const disabledClass = disabled && "opacity-50 cursor-not-allowed"; | ||
|
|
||
| return ( | ||
| <button | ||
| className={`w-[343px] px-[10px] py-[16px] flex items-center justify-center gap-[10px] rounded-xl font-semibold text-[20px] leading-[22px] text-center cursor-pointer | ||
| ${bgColor == "primary" ? "bg-primary-700 text-white" : "bg-white text-primary-500 border border-primary-500"}`} | ||
| onClick={onClick} | ||
| type={type} | ||
| disabled={disabled} | ||
| className={twMerge( | ||
| `rounded-xl flex justify-center items-center ${sizeClass} ${variantClass} ${disabledClass} ${className}`, | ||
| )} | ||
| > | ||
| {bgColor === "white" && <img src={Pencil} />} | ||
| {text} | ||
| {children} | ||
| </button> | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| export default Button; | ||
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.
이부분을 매튜님이 예시 보여주셨던 것 처럼
interface ButtonProp extends React.HTMLAttributes<HTMLButtonElement>이런식으로 선언해보는 건 어떨까 싶습니다.
disabled,onClick,type등이 props로 존재하는 걸로 압니다! 한번 적용해보면 좋을 것 같아요!참고할만한 블로그 첨부합니다
https://velog.io/@dongkyun/TS-HTMLElement의-type-상속받기