|
| 1 | +import { Slot } from '@radix-ui/react-slot'; |
| 2 | +import { cva, type VariantProps } from 'class-variance-authority'; |
| 3 | +import * as React from 'react'; |
| 4 | + |
| 5 | +import { cn } from '@/lib/utils'; |
| 6 | + |
| 7 | +// TODO: Replace colors for button variants |
| 8 | +const buttonVariants = cva( |
| 9 | + 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', |
| 10 | + { |
| 11 | + variants: { |
| 12 | + variant: { |
| 13 | + default: 'bg-fuchsia-800 text-fuchsia-100 hover:bg-fuchsia-500', |
| 14 | + destructive: |
| 15 | + 'bg-destructive text-destructive-foreground hover:bg-destructive/90', |
| 16 | + outline: |
| 17 | + 'border border-input bg-background hover:bg-accent hover:text-accent-foreground', |
| 18 | + secondary: |
| 19 | + 'bg-secondary text-secondary-foreground hover:bg-secondary/80', |
| 20 | + ghost: 'hover:bg-accent hover:text-accent-foreground', |
| 21 | + link: 'text-primary underline-offset-4 hover:underline', |
| 22 | + }, |
| 23 | + size: { |
| 24 | + default: 'h-10 px-4 py-2', |
| 25 | + sm: 'h-9 rounded-md px-3', |
| 26 | + lg: 'h-11 rounded-md px-8', |
| 27 | + icon: 'h-10 w-10', |
| 28 | + }, |
| 29 | + }, |
| 30 | + defaultVariants: { |
| 31 | + variant: 'default', |
| 32 | + size: 'default', |
| 33 | + }, |
| 34 | + } |
| 35 | +); |
| 36 | + |
| 37 | +export interface ButtonProps |
| 38 | + extends React.ButtonHTMLAttributes<HTMLButtonElement>, |
| 39 | + VariantProps<typeof buttonVariants> { |
| 40 | + asChild?: boolean; |
| 41 | +} |
| 42 | + |
| 43 | +const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( |
| 44 | + ({ className, variant, size, asChild = false, ...props }, ref) => { |
| 45 | + const Comp = asChild ? Slot : 'button'; |
| 46 | + return ( |
| 47 | + <Comp |
| 48 | + className={cn(buttonVariants({ variant, size, className }))} |
| 49 | + ref={ref} |
| 50 | + {...props} |
| 51 | + /> |
| 52 | + ); |
| 53 | + } |
| 54 | +); |
| 55 | +Button.displayName = 'Button'; |
| 56 | + |
| 57 | +export { Button, buttonVariants }; |
0 commit comments