2025-05-16 15:54:17 +02:00
|
|
|
"use client";
|
2024-12-16 20:01:30 +01:00
|
|
|
|
2025-05-16 15:54:17 +02:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { ButtonHTMLAttributes } from "react";
|
|
|
|
|
import { Loader2 } from "lucide-react";
|
2024-11-17 16:31:34 +01:00
|
|
|
|
|
|
|
|
export type VariantButton = {
|
2025-05-16 15:54:17 +02:00
|
|
|
secondary: string;
|
|
|
|
|
default: string;
|
|
|
|
|
outline: string;
|
|
|
|
|
ghost: string;
|
|
|
|
|
link: string;
|
|
|
|
|
destructive: string;
|
|
|
|
|
};
|
2024-11-23 17:20:24 +01:00
|
|
|
export type sizeButton = {
|
2025-05-16 15:54:17 +02:00
|
|
|
default: string;
|
|
|
|
|
icon: string;
|
|
|
|
|
sm: string;
|
|
|
|
|
lg: string;
|
|
|
|
|
};
|
2024-11-17 16:31:34 +01:00
|
|
|
|
|
|
|
|
export type ButtonWithConfirmProps = {
|
2025-05-16 15:54:17 +02:00
|
|
|
icon?: any;
|
|
|
|
|
text: string;
|
|
|
|
|
variant?: keyof VariantButton;
|
|
|
|
|
className?: string;
|
|
|
|
|
onClick: () => void;
|
|
|
|
|
isPending?: boolean;
|
|
|
|
|
size: keyof sizeButton;
|
2024-11-17 16:31:34 +01:00
|
|
|
};
|
|
|
|
|
|
2024-11-17 21:01:05 +01:00
|
|
|
export const ButtonWithLoading = ({
|
2025-05-16 15:54:17 +02:00
|
|
|
icon,
|
|
|
|
|
text,
|
|
|
|
|
variant,
|
|
|
|
|
className,
|
|
|
|
|
onClick,
|
|
|
|
|
isPending,
|
|
|
|
|
size,
|
|
|
|
|
...props // catch all remaining props
|
|
|
|
|
}: ButtonWithConfirmProps & ButtonHTMLAttributes<HTMLButtonElement>) => {
|
2024-11-23 17:20:24 +01:00
|
|
|
return (
|
2024-11-17 16:31:34 +01:00
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
2025-05-16 15:54:17 +02:00
|
|
|
onClick();
|
2024-11-17 16:31:34 +01:00
|
|
|
}}
|
2024-11-17 21:01:05 +01:00
|
|
|
variant={variant ? variant : "default"}
|
|
|
|
|
className={className}
|
|
|
|
|
{...props} // forward the remaining props to the Button component
|
2024-11-23 17:20:24 +01:00
|
|
|
size={size || "default"}
|
2024-11-17 16:31:34 +01:00
|
|
|
>
|
2025-05-16 15:54:17 +02:00
|
|
|
{isPending && <Loader2 className="animate-spin mr-4" size={16} />}
|
2024-11-17 21:01:05 +01:00
|
|
|
{text}
|
2025-05-16 15:54:17 +02:00
|
|
|
<>{icon ? icon : null}</>
|
2024-11-17 16:31:34 +01:00
|
|
|
</Button>
|
2025-05-16 15:54:17 +02:00
|
|
|
);
|
|
|
|
|
};
|