1- import { twMerge } from 'tailwind-merge' ;
21import { forwardRef } from 'react' ;
2+ import { cva } from 'class-variance-authority' ;
3+ import { cn } from '@/utils' ;
34
45interface ButtonProps extends React . ButtonHTMLAttributes < HTMLButtonElement > {
56 variant ?: 'primary' | 'secondary' | 'disabled' ;
67}
78
8- const buttonStyle = {
9- primary : 'bg-primary-normal hover:bg-primary-hover' ,
10- secondary : 'bg-white border border-primary-active text-primary-active hover:bg-gray-5' ,
11- disabled : 'bg-gray-30 cursor-not-allowed' ,
12- } ;
9+ export const buttonVariants = cva (
10+ 'flex justify-center items-center w-full rounded-lg h-[38px] text-white transition body-m cursor-pointer' ,
11+ {
12+ variants : {
13+ variant : {
14+ primary : 'bg-primary-normal hover:bg-primary-hover' ,
15+ secondary : 'bg-white border border-primary-active text-primary-active hover:bg-gray-5' ,
16+ disabled : 'bg-gray-30 cursor-not-allowed' ,
17+ } ,
18+ } ,
19+ defaultVariants : {
20+ variant : 'primary' ,
21+ } ,
22+ } ,
23+ ) ;
1324
1425const Button = forwardRef < HTMLButtonElement , ButtonProps > (
15- ( { children, variant = 'primary' , type = 'button' , className , disabled , ...props } , ref ) => {
26+ ( { children, variant = 'primary' , type = 'button' , disabled , className , ...props } , ref ) => {
1627 return (
1728 < button
1829 ref = { ref }
1930 type = { type }
20- className = { twMerge (
21- 'flex justify-center items-center w-full rounded-lg h-[38px] text-white transition body-m cursor-pointer' ,
22- buttonStyle [ variant ] ,
23- className ,
24- ) }
25- disabled = { variant === 'disabled' }
31+ disabled = { variant === 'disabled' || disabled }
32+ className = { cn ( buttonVariants ( { variant } ) , className ) }
2633 { ...props }
2734 >
2835 { children }
@@ -31,9 +38,6 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
3138 } ,
3239) ;
3340
34- export default Button ;
41+ Button . displayName = ' Button' ;
3542
36- // 사용 예시
37- // <Button variant="secondary" className="w-40 py-3 text-lg">
38- // Secondary 버튼
39- // </Button>
43+ export default Button ;
0 commit comments