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