langfuse

Форк
0
84 строки · 2.3 Кб
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 "@/src/utils/tailwind";
6
import { Loader2 } from "lucide-react";
7

8
const buttonVariants = cva(
9
  "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",
10
  {
11
    variants: {
12
      variant: {
13
        default: "bg-primary text-primary-foreground hover:bg-primary/90",
14
        destructive:
15
          "bg-destructive text-destructive-foreground hover:bg-destructive/90",
16
        outline:
17
          "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
18
        secondary:
19
          "bg-secondary text-secondary-foreground hover:bg-secondary/80",
20
        ghost: "hover:bg-accent hover:text-accent-foreground",
21
        link: "text-primary underline-offset-4 hover:underline",
22
      },
23
      size: {
24
        default: "h-10 px-4 py-2",
25
        xs: "h-6 px-1 rounded-sm",
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

38
export interface ButtonProps
39
  extends React.ButtonHTMLAttributes<HTMLButtonElement>,
40
    VariantProps<typeof buttonVariants> {
41
  asChild?: boolean;
42
  loading?: boolean;
43
}
44

45
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
46
  (
47
    {
48
      className,
49
      variant,
50
      size,
51
      asChild = false,
52
      loading = false,
53
      disabled,
54
      onClick,
55
      children,
56
      ...props
57
    },
58
    ref,
59
  ) => {
60
    const Comp = asChild ? Slot : "button";
61
    return (
62
      <Comp
63
        className={cn(buttonVariants({ variant, size, className }))}
64
        ref={ref}
65
        disabled={disabled || loading}
66
        onClick={loading || disabled ? undefined : onClick}
67
        {...props}
68
      >
69
        {loading ? <Spinner /> : children}
70
      </Comp>
71
    );
72
  },
73
);
74
Button.displayName = "Button";
75

76
export { Button, buttonVariants };
77

78
function Spinner() {
79
  return (
80
    <div className="flex h-1/2 items-center justify-center">
81
      <Loader2 className="h-full w-full animate-spin" />
82
    </div>
83
  );
84
}
85

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.