Loader Button
Seamless loading with a customizable Loader Button.
Installation
- 1
Install Dependencies
npm i lucide-react
- 2
Install Shadcn Components
npx shadcn@latest add button
- 3
Copy the source code
@/components/ui/loaderButton.tsx
"use client"; import * as React from "react"; import { LoaderCircle } from "lucide-react"; import { Button } from "@/components/ui/button"; type LoaderButtonProps = { isLoading: boolean; className?: string; buttonVariant?: | "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined; children: React.ReactNode; onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void; }; const LoaderButton: React.FC<LoaderButtonProps> = ({ buttonVariant, isLoading, className, children, onClick, }) => { return ( <Button variant={buttonVariant} className={className} onClick={onClick} disabled={isLoading} > {isLoading && <LoaderCircle className="mr-2 h-4 w-4 animate-spin" />} {children} </Button> ); }; export default LoaderButton; // Visit https://voxlet-ui.vercel.app/ for more components like this
Props
Prop | Type | Default | Description |
---|---|---|---|
className | string | undefined | Optional class names to style the button component. |
isLoading | boolean | false | A boolean indicating whether the loader animation should be displayed. |
buttonVariant | "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined | "default" | Defines the style variant of the button, can be one of the provided Tailwind-based variants like 'default', 'destructive', etc. |
children | React.ReactNode | undefined | The content to be rendered inside the button, typically text or icons. |
onClick | (event: React.MouseEvent<HTMLButtonElement>) => void | undefined | Optional onClick event handler that gets triggered when the button is clicked. |