2024-11-17 16:31:34 +01:00
|
|
|
"use client"
|
|
|
|
|
import {Button} from "@/components/ui/button";
|
2024-11-17 21:01:05 +01:00
|
|
|
import {ButtonHTMLAttributes, useState} from "react";
|
2024-11-17 16:31:34 +01:00
|
|
|
import {Loader2} from "lucide-react";
|
|
|
|
|
|
|
|
|
|
export type VariantButton = {
|
|
|
|
|
secondary: string
|
|
|
|
|
default: string
|
|
|
|
|
outline: string
|
|
|
|
|
ghost: string
|
|
|
|
|
link: string
|
|
|
|
|
destructive: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ButtonWithConfirmProps = {
|
|
|
|
|
icon?: any,
|
|
|
|
|
text: string,
|
|
|
|
|
variant?: keyof VariantButton ,
|
|
|
|
|
className?: string,
|
|
|
|
|
onClick: () => void,
|
|
|
|
|
isPending? : boolean
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-17 21:01:05 +01:00
|
|
|
export const ButtonWithLoading = ({
|
|
|
|
|
icon,
|
|
|
|
|
text,
|
|
|
|
|
variant,
|
|
|
|
|
className,
|
|
|
|
|
onClick,
|
|
|
|
|
isPending,
|
|
|
|
|
...props // catch all remaining props
|
|
|
|
|
}: ButtonWithConfirmProps & ButtonHTMLAttributes<HTMLButtonElement>) => {
|
2024-11-17 16:31:34 +01:00
|
|
|
return(
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
2024-11-17 21:01:05 +01: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-17 16:31:34 +01:00
|
|
|
>
|
2024-11-17 21:01:05 +01:00
|
|
|
{isPending && <Loader2 className="animate-spin mr-4" size={16}/>}
|
|
|
|
|
{text}
|
2024-11-17 16:31:34 +01:00
|
|
|
<>
|
2024-11-17 21:01:05 +01:00
|
|
|
{icon ? icon : null}
|
2024-11-17 16:31:34 +01:00
|
|
|
</>
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
}
|