gitscope
← marzneshin / v0.7.2 / dashboard/src/common/components/ui/button/index.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/common/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/common/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:
13                    "bg-primary text-primary-foreground hover:bg-primary/90",
14                destructive:
15                    "bg-destructive text-destructive-foreground hover:bg-destructive/90",
16                "secondary-destructive":
17                    "hover:bg-accent text-destructive hover:bg-destructive/20",
18                success:
19                    "bg-success text-success-foreground hover:bg-success/80",
20                outline:
21                    "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
22                secondary:
23                    "bg-secondary text-secondary-foreground hover:bg-secondary/80",
24                ghost: "hover:bg-accent hover:text-accent-foreground",
25                link: "text-primary underline-offset-4 hover:underline",
26            },
27            size: {
28                default: "h-10 px-4 py-2",
29                sm: "h-9 rounded-md px-3",
30                lg: "h-11 rounded-md px-8",
31                icon: "h-10 w-10",
32            },
33        },
34        defaultVariants: {
35            variant: "default",
36            size: "default",
37        },
38    },
39);
40
41export interface ButtonProps
42    extends React.ButtonHTMLAttributes<HTMLButtonElement>,
43    VariantProps<typeof buttonVariants> {
44    asChild?: boolean;
45}
46
47const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
48    ({ className, variant, size, asChild = false, ...props }, ref) => {
49        const Comp = asChild ? Slot : "button";
50        return (
51            <Comp
52                className={cn(buttonVariants({ variant, size, className }))}
53                ref={ref}
54                {...props}
55            />
56        );
57    },
58);
59Button.displayName = "Button";
60
61export { Button, buttonVariants };