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