2025-04-27 09:31:24 +07:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { Slot } from '@radix-ui/react-slot';
|
|
|
|
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
|
|
|
import * as React from 'react';
|
2025-05-30 11:57:17 +07:00
|
|
|
import { cn } from '../lib';
|
2025-04-27 09:31:24 +07:00
|
|
|
|
|
|
|
|
const buttonVariants = cva(
|
2025-05-30 11:57:17 +07:00
|
|
|
'inline-flex items-center justify-center font-[600] rounded-md px-[16px] py-[10px] transition-colors duration-200 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed',
|
2025-04-27 09:31:24 +07:00
|
|
|
{
|
|
|
|
|
variants: {
|
|
|
|
|
variant: {
|
2025-05-30 11:57:17 +07:00
|
|
|
primary: 'bg-primary-500 hover:bg-primary-600 text-white shadow-md',
|
2025-04-27 09:31:24 +07:00
|
|
|
secondary:
|
2025-05-30 11:57:17 +07:00
|
|
|
'bg-white hover:text-primary-600 hover:bg-gray-50 text-primary-500 shadow-md',
|
|
|
|
|
text: 'bg-transparent hover:text-primary-600 hover:bg-gray-50 text-primary-500',
|
|
|
|
|
bordered:
|
|
|
|
|
'border border-primary-500 hover:border-primary-600 bg-transparent hover:text-primary-600 hover:bg-gray-50 text-primary-500',
|
|
|
|
|
success: 'bg-success-500 hover:bg-success-600 text-white shadow-md',
|
|
|
|
|
danger: 'bg-danger-100 hover:bg-danger-200 text-danger-500 shadow-md',
|
2025-04-27 09:31:24 +07:00
|
|
|
},
|
|
|
|
|
size: {
|
|
|
|
|
default: 'h-9 px-4 py-2',
|
|
|
|
|
sm: 'h-8 rounded-md px-3 text-xs',
|
|
|
|
|
lg: 'h-10 rounded-md px-8',
|
|
|
|
|
icon: 'h-9 w-9',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
defaultVariants: {
|
2025-05-30 11:57:17 +07:00
|
|
|
variant: 'primary',
|
2025-04-27 09:31:24 +07:00
|
|
|
size: 'default',
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export interface ButtonProps
|
|
|
|
|
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
|
|
|
VariantProps<typeof buttonVariants> {
|
|
|
|
|
asChild?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
|
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
|
|
|
const Comp = asChild ? Slot : 'button';
|
|
|
|
|
return (
|
|
|
|
|
<Comp
|
|
|
|
|
className={cn(buttonVariants({ variant, size, className }))}
|
|
|
|
|
ref={ref}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
Button.displayName = 'Button';
|
|
|
|
|
|
|
|
|
|
export { Button, buttonVariants };
|