gitscope
← marzneshin / v0.5.1 / dashboard/src/components/ui/button/index.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/components/ui/button/index.tsx · TypeScript
Blame Raw
 1import * as React from "react"
 2import { Slot } from "@radix-ui/react-slot"
 3import { cva, type VariantProps } from "class-variance-authority"
 4
 5import { cn } from "@marzneshin/utils"
 6
 7const buttonVariants = cva(
 8    "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",
 9    {
10        variants: {
11            variant: {
12                default: "bg-primary text-primary-foreground hover:bg-primary/90",
13                destructive:
14                    "bg-destructive text-destructive-foreground hover:bg-destructive/90",
15                success:
16                    "bg-success text-success-foreground hover:bg-success/80",
17                outline:
18                    "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
19                secondary:
20                    "bg-secondary text-secondary-foreground 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-10 px-4 py-2",
26                sm: "h-9 rounded-md px-3",
27                lg: "h-11 rounded-md px-8",
28                icon: "h-10 w-10",
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, ...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)
56Button.displayName = "Button"
57
58export { Button, buttonVariants }