systeme.io-task
57 строк · 1.8 Кб
1import * as React from "react";
2import { Slot } from "@radix-ui/react-slot";
3import { cva, type VariantProps } from "class-variance-authority";
4
5import { cn } from "~/shared/lib/utils";
6
7const buttonVariants = cva(
8"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",
9{
10variants: {
11variant: {
12default:
13"bg-primary text-primary-foreground shadow hover:bg-primary/90",
14destructive:
15"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
16outline:
17"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
18secondary:
19"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
20ghost: "hover:bg-accent hover:text-accent-foreground",
21link: "text-primary underline-offset-4 hover:underline",
22},
23size: {
24default: "h-9 px-4 py-2",
25sm: "h-8 rounded-md px-3 text-xs",
26lg: "h-10 rounded-md px-8",
27icon: "h-9 w-9",
28},
29},
30defaultVariants: {
31variant: "default",
32size: "default",
33},
34},
35);
36
37export interface ButtonProps
38extends React.ButtonHTMLAttributes<HTMLButtonElement>,
39VariantProps<typeof buttonVariants> {
40asChild?: boolean;
41}
42
43const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
44({ className, variant, size, asChild = false, ...props }, ref) => {
45const Comp = asChild ? Slot : "button";
46return (
47<Comp
48className={cn(buttonVariants({ variant, size, className }))}
49ref={ref}
50{...props}
51/>
52);
53},
54);
55Button.displayName = "Button";
56
57export { Button, buttonVariants };
58