import type { VariantProps } from 'class-variance-authority' import { Button as BaseButton } from '@base-ui/react/button' import { cva } from 'class-variance-authority' import * as React from 'react' import { cn } from '@/utils/classnames' import Spinner from '../spinner' const buttonVariants = cva( 'btn', { variants: { variant: { 'primary': 'btn-primary', 'warning': 'btn-warning', 'secondary': 'btn-secondary', 'secondary-accent': 'btn-secondary-accent', 'ghost': 'btn-ghost', 'ghost-accent': 'btn-ghost-accent', 'tertiary': 'btn-tertiary', }, size: { small: 'btn-small', medium: 'btn-medium', large: 'btn-large', }, destructive: { true: 'btn-destructive', }, }, defaultVariants: { variant: 'secondary', size: 'medium', }, }, ) export type ButtonProps = { loading?: boolean spinnerClassName?: string ref?: React.Ref render?: React.ReactElement focusableWhenDisabled?: boolean } & React.ButtonHTMLAttributes & VariantProps const Button = ({ className, variant, size, destructive, loading, children, spinnerClassName, ref, render, focusableWhenDisabled, disabled, type = 'button', ...props }: ButtonProps) => { const isDisabled = disabled || loading return ( {children} {loading && } ) } Button.displayName = 'Button' export default Button export { Button, buttonVariants }