11import React from "react" ;
22
3- type ButtonVariant = "primary" | "white" | "disabled" ;
3+ type ButtonVariant = "primary" | "white" ;
44type ButtonTextSize = "lg" | "md" | "sm" ;
55
66interface ButtonProps extends React . ButtonHTMLAttributes < HTMLButtonElement > {
77 variant ?: ButtonVariant ;
88 textSize ?: ButtonTextSize ;
99 fullWidth ?: boolean ;
10+ disabled ?: boolean ;
1011}
1112
1213const textSizeClassMap : Record < ButtonTextSize , string > = {
@@ -15,28 +16,26 @@ const textSizeClassMap: Record<ButtonTextSize, string> = {
1516 sm : "text-xs font-normal leading-4" ,
1617} ;
1718
19+ const variantClassMap : Record < ButtonVariant , string > = {
20+ primary : "bg-[#EA3C12] text-white hover:bg-[#ca3f2a] active:bg-[#aa3523]" ,
21+ white :
22+ "bg-white text-[#EA3C12] border border-[#EA3C12] hover:bg-[#fff5f3] active:bg-[#ffe5e0]" ,
23+ } ;
24+
25+ const disabledClass = "bg-gray-40 text-white cursor-not-allowed" ;
26+
1827export default function Button ( {
1928 variant = "primary" ,
2029 textSize = "md" ,
2130 fullWidth = false ,
31+ disabled = false ,
2232 className,
2333 children,
2434 ...props
2535} : ButtonProps ) {
2636 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-
3937 const fullWidthClass = fullWidth ? "w-full" : "" ;
38+ const variantClass = disabled ? disabledClass : variantClassMap [ variant ] ;
4039 const textSizeClass = textSizeClassMap [ textSize ] ;
4140
4241 const finalClassName = [
@@ -50,11 +49,7 @@ export default function Button({
5049 . join ( " " ) ;
5150
5251 return (
53- < button
54- className = { finalClassName }
55- disabled = { variant === "disabled" || props . disabled }
56- { ...props }
57- >
52+ < button className = { finalClassName } disabled = { disabled } { ...props } >
5853 { children }
5954 </ button >
6055 ) ;
0 commit comments