Skip to content

Commit 8d2496a

Browse files
committed
feat: 버튼 컴포넌트 생성
1 parent d7a5afe commit 8d2496a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/components/Button.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from "react";
2+
3+
type ButtonVariant = "primary" | "white" | "disabled";
4+
type ButtonTextSize = "lg" | "md" | "sm";
5+
6+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
7+
variant?: ButtonVariant;
8+
textSize?: ButtonTextSize;
9+
fullWidth?: boolean;
10+
}
11+
12+
const textSizeClassMap: Record<ButtonTextSize, string> = {
13+
lg: "text-base font-bold leading-5",
14+
md: "text-sm font-bold leading-none",
15+
sm: "text-xs font-normal leading-4",
16+
};
17+
18+
export default function Button({
19+
variant = "primary",
20+
textSize = "md",
21+
fullWidth = false,
22+
className,
23+
children,
24+
...props
25+
}: ButtonProps) {
26+
const baseClasses = "rounded-md";
27+
28+
let variantClass = "";
29+
if (variant === "primary") {
30+
variantClass =
31+
"bg-[#EA3C12] text-white hover:bg-[#ca3f2a] active:bg-[#aa3523]";
32+
} else if (variant === "white") {
33+
variantClass =
34+
"bg-white text-[#EA3C12] border border-[#EA3C12] hover:bg-[#fff5f3] active:bg-[#ffe5e0]";
35+
} else if (variant === "disabled") {
36+
variantClass = "bg-gray-40 text-white cursor-not-allowed";
37+
}
38+
39+
const fullWidthClass = fullWidth ? "w-full" : "";
40+
const textSizeClass = textSizeClassMap[textSize];
41+
42+
const finalClassName = [
43+
baseClasses,
44+
variantClass,
45+
textSizeClass,
46+
fullWidthClass,
47+
className,
48+
]
49+
.filter(Boolean)
50+
.join(" ");
51+
52+
return (
53+
<button
54+
className={finalClassName}
55+
disabled={variant === "disabled" || props.disabled}
56+
{...props}
57+
>
58+
{children}
59+
</button>
60+
);
61+
}

0 commit comments

Comments
 (0)