2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-09-18 15:51:30 +03:00
|
|
|
import {
|
|
|
|
Tooltip,
|
|
|
|
TooltipContent,
|
|
|
|
TooltipProvider,
|
|
|
|
TooltipTrigger,
|
|
|
|
} from "@radix-ui/react-tooltip";
|
2023-05-26 14:56:29 +03:00
|
|
|
import { cva, type VariantProps } from "class-variance-authority";
|
2023-09-18 15:51:30 +03:00
|
|
|
import { ButtonHTMLAttributes, LegacyRef, forwardRef } from "react";
|
2023-05-21 02:20:55 +03:00
|
|
|
import { FaSpinner } from "react-icons/fa";
|
2023-05-18 14:37:03 +03:00
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
2023-05-18 14:37:03 +03:00
|
|
|
const ButtonVariants = cva(
|
2023-05-21 02:20:55 +03:00
|
|
|
"px-8 py-3 text-sm disabled:opacity-80 text-center font-medium rounded-md focus:ring ring-primary/10 outline-none flex items-center justify-center gap-2 transition-opacity",
|
2023-05-18 14:37:03 +03:00
|
|
|
{
|
|
|
|
variants: {
|
|
|
|
variant: {
|
|
|
|
primary:
|
2023-05-26 11:57:29 +03:00
|
|
|
"bg-black border border-black dark:border-white disabled:bg-gray-500 disabled:hover:bg-gray-500 text-white dark:bg-white dark:text-black hover:bg-gray-700 dark:hover:bg-gray-200 transition-colors",
|
2023-06-02 17:01:24 +03:00
|
|
|
tertiary:
|
|
|
|
"text-black dark:text-white bg-transparent py-2 px-4 disabled:opacity-25",
|
2023-05-18 14:37:03 +03:00
|
|
|
secondary:
|
2023-09-27 10:50:27 +03:00
|
|
|
"border border-black dark:border-white bg-white dark:bg-black text-black dark:text-white focus:bg-black dark:focus:bg-white hover:bg-black dark:hover:bg-white hover:text-white dark:hover:text-black focus:text-white dark:focus:text-black transition-colors shadow-none",
|
2023-05-23 09:15:13 +03:00
|
|
|
danger:
|
|
|
|
"border border-red-500 hover:bg-red-500 hover:text-white transition-colors",
|
2023-05-18 14:37:03 +03:00
|
|
|
},
|
|
|
|
brightness: {
|
|
|
|
dim: "",
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
defaultVariants: {
|
|
|
|
variant: "primary",
|
|
|
|
brightness: "default",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
export interface ButtonProps
|
|
|
|
extends ButtonHTMLAttributes<HTMLButtonElement>,
|
|
|
|
VariantProps<typeof ButtonVariants> {
|
|
|
|
isLoading?: boolean;
|
2023-09-18 15:51:30 +03:00
|
|
|
tooltip?: string;
|
2023-05-18 14:37:03 +03:00
|
|
|
}
|
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
const Button = forwardRef(
|
2023-05-21 02:20:55 +03:00
|
|
|
(
|
2023-06-15 12:52:46 +03:00
|
|
|
{
|
|
|
|
className,
|
|
|
|
children,
|
|
|
|
variant,
|
|
|
|
brightness,
|
|
|
|
isLoading,
|
2023-09-18 15:51:30 +03:00
|
|
|
tooltip,
|
2023-06-15 12:52:46 +03:00
|
|
|
...props
|
|
|
|
}: ButtonProps,
|
2023-05-21 02:20:55 +03:00
|
|
|
forwardedRef
|
2023-06-15 12:52:46 +03:00
|
|
|
): JSX.Element => {
|
2023-09-18 15:51:30 +03:00
|
|
|
const buttonElement = (
|
2023-05-21 02:20:55 +03:00
|
|
|
<button
|
|
|
|
className={cn(ButtonVariants({ variant, brightness, className }))}
|
|
|
|
disabled={isLoading}
|
|
|
|
{...props}
|
|
|
|
ref={forwardedRef as LegacyRef<HTMLButtonElement>}
|
|
|
|
>
|
|
|
|
{children} {isLoading && <FaSpinner className="animate-spin" />}
|
|
|
|
</button>
|
|
|
|
);
|
2023-09-18 15:51:30 +03:00
|
|
|
|
|
|
|
if (tooltip !== undefined) {
|
|
|
|
return (
|
|
|
|
<TooltipProvider>
|
|
|
|
<Tooltip>
|
|
|
|
<TooltipTrigger>{buttonElement}</TooltipTrigger>
|
|
|
|
<TooltipContent className="bg-gray-100 rounded-md p-1">
|
|
|
|
{tooltip}
|
|
|
|
</TooltipContent>
|
|
|
|
</Tooltip>
|
|
|
|
</TooltipProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buttonElement;
|
2023-05-21 02:20:55 +03:00
|
|
|
}
|
|
|
|
);
|
2023-05-18 14:37:03 +03:00
|
|
|
|
2023-05-23 09:15:13 +03:00
|
|
|
Button.displayName = "Button";
|
2023-05-18 14:37:03 +03:00
|
|
|
export default Button;
|