import * as React from "react"; import { Slot } from "@radix-ui/react-slot"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "@/lib/utils"; import { Loader2 } from "lucide-react"; import { Button, buttonVariants } from "./button"; export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean; loading?: boolean; } const LoadingButton = React.forwardRef( ( { className, variant, size, asChild = false, loading, children, ...props }, ref ) => { if (asChild) { return ( <> {React.Children.map( children as React.ReactElement, (child: React.ReactElement) => { return React.cloneElement(child, { className: cn(buttonVariants({ variant, size }), className), children: ( <> {loading && ( )} {child.props.children} ), }); } )} ); } return ( ); } ); LoadingButton.displayName = "LoadingButton"; export { LoadingButton, buttonVariants };