import { Slot } from "@radix-ui/react-slot"; import { cva, type VariantProps } from "class-variance-authority"; import { type ComponentProps, forwardRef } from "react"; import { cn } from "../hooks"; export const buttonVariants = cva( [ "inline-flex", "cursor-pointer", "items-center", "justify-center", "shrink-0", "whitespace-nowrap", "transition-all", "[&_svg]:shrink-0 ", "[&_svg]:pointer-events-none", "outline-none", "disabled:pointer-events-none", "disabled:bg-bg-tertiary", "disabled:text-text-tertiary", "focus-visible:bg-brand-tertiary", ], { variants: { variant: { primary: [ "bg-brand-primary", "text-text-withbg", "hover:bg-brand-hover", "active:bg-brand-pressed", ], secondary: [ "bg-alt-primary", "text-text-highlight", "hover:bg-alt-hover", "active:bg-alt-pressed", ], destructive: [ "bg-danger-primary", "text-text-withbg", "hover:bg-danger-secondary", "active:bg-danger-tertiary", ], ghost: [ "text-text-primary", "hover:text-text-highlight", "hover:bg-alt-primary", "active:bg-bg-secondary", // "active:text-brand-primary", // todo: add state sensitivity (can do via toggle button) // "[value]:text-brand-primary", ], link: ["text-text-primary", "underline-offset-4", "hover:underline"], }, size: { sm: [ "rounded-uk-md", "text-uk-sm", "py-sm", "gap-xxs", "px-md", "leading-4", "[&_svg:not([class*='size-'])]:size-3", ], md: [ "rounded-uk-md", "text-uk-md", "py-sm", "gap-xs", "px-lg", "leading-5", "[&_svg:not([class*='size-'])]:size-4", ], lg: [ "rounded-uk-lg", "text-uk-lg", "py-sm", "gap-xs", "px-xl", "leading-6", "[&_svg:not([class*='size-'])]:size-5", ], }, icon: { false: null, true: null }, value: { false: null, true: ["text-brand-primary", "[&_svg]:text-brand-primary"], }, }, compoundVariants: [ { size: "sm", icon: true, class: ["px-xs", "py-xs", " size-6"] }, { size: "md", icon: true, class: ["px-sm", "py-sm", "size-8"] }, { size: "lg", icon: true, class: ["px-md", "py-md", " size-9"] }, ], defaultVariants: { variant: "primary", size: "md", icon: false, value: false, }, }, ); interface ButtonProps extends Omit, "value">, VariantProps { asChild?: boolean; value?: boolean; } /** * Button component with variant and size styling. * Wraps a native `button` or a child element when `asChild` is true. * * @param variant - Visual style variant (e.g. "primary", "secondary", "destructive", "ghost", "link") * @param size - Control size ("sm" | "md" | "lg") * @param icon - If true, adjusts paddings to present as an icon button * @param asChild - When true, renders the child element instead of a button using Slot */ const Button = forwardRef(function Button( { className, variant, size, icon, value, asChild = false, ...props }, ref, ) { const Comp = asChild ? Slot : "button"; return ( ); }); export { Button }; export type { ButtonProps };