'use client'
import { forwardRef, ButtonHTMLAttributes } from 'react'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import { twMerge } from 'tailwind-merge'
const buttonVariants = cva('btn', {
variants: {
themes: {
primary: 'btn-primary',
danger: 'btn-danger',
outline: 'btn-outline',
secondary: 'btn-secondary',
secondaryBlue: 'btn-secondary-blue',
secondaryDanger: 'btn-secondary-danger',
ghost: 'btn-ghost',
success: 'btn-success',
},
size: {
sm: 'btn-sm',
md: 'btn-md',
lg: 'btn-lg',
},
block: {
true: 'w-full',
},
loading: {
true: 'btn-loading',
},
},
defaultVariants: {
themes: 'primary',
size: 'md',
},
})
export interface ButtonProps
extends ButtonHTMLAttributes,
VariantProps {
asChild?: boolean
}
const Button = forwardRef(
(
{
className,
themes,
size,
block,
loading,
asChild = false,
children,
...props
},
ref
) => {
const Comp = asChild ? Slot : 'button'
return (
{loading ? (
<>
{children}
>
) : (
children
)}
)
}
)
Button.displayName = 'Button'
export { Button, buttonVariants }