File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments