'use client'; import * as React from 'react'; import { Slot } from 'radix-ui'; import { cva, type VariantProps } from '@/lib/cva'; import { cn } from '@/lib/utils'; import { disabledState, focusRing, iconSizing, invalidState } from '@/lib/cva-presets'; const buttonVariants = cva( cn( "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium shrink-0", 'transition-[color,box-shadow,background-color] duration-(--ui-duration-fast) ease-(--ui-ease-standard)', focusRing, disabledState, invalidState, iconSizing ), { variants: { variant: { /** Primary call to action. One per view, ideally. */ default: 'bg-primary text-primary-foreground shadow-xs hover:bg-primary/90', /** Irreversible or data-losing actions. */ destructive: 'bg-destructive text-destructive-foreground shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/40', /** Secondary action that still needs an obvious hit area. */ outline: 'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:hover:bg-input/50', /** Neutral action sitting next to a primary one. */ secondary: 'bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80', /** Low-emphasis action inside dense UI (toolbars, table rows). */ ghost: 'hover:bg-accent hover:text-accent-foreground', /** Reads as a link but behaves as a button. */ link: 'text-primary underline-offset-4 hover:underline', }, size: { sm: 'h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5', md: 'h-9 px-4 py-2 has-[>svg]:px-3', lg: 'h-10 rounded-md px-6 has-[>svg]:px-4', /** Square button for a lone icon — always pair with `aria-label`. */ icon: 'size-9 rounded-md', }, }, defaultVariants: { variant: 'default', size: 'md', }, } ); export interface ButtonProps extends React.ComponentProps<'button'>, VariantProps { /** * Render the child element instead of a ` * * ``` */ function Button({ className, variant, size, asChild = false, ...props }: ButtonProps) { const Comp = asChild ? Slot.Root : 'button'; return ( ); } export { Button, buttonVariants };