|
| 1 | +import * as React from "react"; |
| 2 | +import { Slot } from "@radix-ui/react-slot"; |
| 3 | +import { cva, type VariantProps } from "class-variance-authority"; |
| 4 | + |
| 5 | +import { cn } from "@/base/lib/utils"; |
| 6 | + |
| 7 | +const buttonVariants = cva( |
| 8 | + "rpr-inline-flex rpr-items-center rpr-justify-center rpr-gap-2 rpr-whitespace-nowrap rpr-rounded-md rpr-text-sm rpr-font-medium rpr-transition-colors focus-visible:rpr-outline-none focus-visible:rpr-ring-1 focus-visible:rpr-ring-ring disabled:rpr-pointer-events-none disabled:rpr-opacity-50 [&_svg]:rpr-pointer-events-none [&_svg]:rpr-size-4 [&_svg]:rpr-shrink-0", |
| 9 | + { |
| 10 | + variants: { |
| 11 | + variant: { |
| 12 | + default: |
| 13 | + "rpr-bg-primary rpr-text-primary-foreground rpr-shadow hover:rpr-bg-primary/90", |
| 14 | + destructive: |
| 15 | + "rpr-bg-destructive rpr-text-destructive-foreground rpr-shadow-sm hover:rpr-bg-destructive/90", |
| 16 | + outline: |
| 17 | + "rpr-border rpr-border-input rpr-bg-background rpr-shadow-sm hover:rpr-bg-accent hover:rpr-text-accent-foreground", |
| 18 | + secondary: |
| 19 | + "rpr-bg-secondary rpr-text-secondary-foreground rpr-shadow-sm hover:rpr-bg-secondary/80", |
| 20 | + ghost: "hover:rpr-bg-accent hover:rpr-text-accent-foreground", |
| 21 | + link: "rpr-text-primary rpr-underline-offset-4 hover:rpr-underline", |
| 22 | + }, |
| 23 | + size: { |
| 24 | + default: "rpr-h-9 rpr-px-4 rpr-py-2", |
| 25 | + sm: "rpr-h-8 rpr-rounded-md rpr-px-3 rpr-text-xs", |
| 26 | + lg: "rpr-h-10 rpr-rounded-md rpr-px-8", |
| 27 | + icon: "rpr-h-9 rpr-w-9", |
| 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