Files
portabase/src/components/wrappers/Button/ButtonWithLoading/ButtonWithLoading.tsx
T

49 lines
1.4 KiB
TypeScript
Raw Normal View History

"use client"
import {Button} from "@/components/ui/button";
2024-11-17 21:01:05 +01:00
import {ButtonHTMLAttributes, useState} from "react";
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>) => {
return(
<Button
onClick={() => {
2024-11-17 21:01:05 +01:00
onClick()
}}
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 21:01:05 +01:00
{isPending && <Loader2 className="animate-spin mr-4" size={16}/>}
{text}
<>
2024-11-17 21:01:05 +01:00
{icon ? icon : null}
</>
</Button>
)
}