Skip to content
Design From Labs
ComponentactionsLabs examplesMIT

Button

A button with five variants, four sizes and a loading state that keeps focus and announces progress, on Radix, Base UI or React Aria.

Primitive
Icons
Direction

Install

Item button-radix-lucide · registry JSON

npx shadcn@latest add https://labs.designfrom.com/r/button-radix-lucide.json

Source

Comments are kept. The header lists provenance, license and install commands for people and coding assistants.

components/ui/button.tsx
import { cva, type VariantProps } from "class-variance-authority";
import { LoaderCircle } from "lucide-react";
import { Slot } from "radix-ui";
import type * as React from "react";

import { cn } from "@/lib/utils";

/**
 * @dfl-header: v1, generated by labs.designfrom.com at build time
 * Item: button-radix-lucide (Button: Radix, Lucide)
 * What: A button with five variants, four sizes and a loading state that
 *    keeps focus and announces progress, on Radix, Base UI or React Aria.
 * Status: ready. License: MIT. Author: Design From Labs
 *    <https://labs.designfrom.com>
 * Source: https://github.com/Design-from-labs/labs @ 803b92c1a30e (examples/button)
 * Credits: S-003 React (MIT); S-004 shadcn/ui and its registry schema (MIT);
 *    S-005 Lucide icons (ISC); S-006 Phosphor Icons (MIT); S-008
 *    Tailwind CSS (MIT); S-018 class-variance-authority (Apache-2.0);
 *    S-032 Radix Primitives (the unified radix-ui package) (MIT);
 *    S-033 Base UI (@base-ui/react) (MIT); S-034 React Aria Components
 *    (react-aria-components) (Apache-2.0)
 * Install: npx shadcn@latest add https://labs.designfrom.com/r/button-radix-lucide.json
 *   npx shadcn@latest add @designfrom/button-radix-lucide
 *   npx designfrom add button
 *   npm i @designfrom/react, then import { Button, buttonVariants } from "@designfrom/react/radix/button";
 * Requires: class-variance-authority, radix-ui, lucide-react, registry: utils
 * Docs: https://labs.designfrom.com/ui/button (index: https://labs.designfrom.com/llms.txt)
 */

// Every color comes from the shared token layer (primary, accent, ring...),
// so the button follows whatever theme the host project defines.
const buttonVariants = cva(
  "inline-flex shrink-0 select-none items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium text-sm outline-none transition-[color,background-color,box-shadow] duration-150 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 aria-busy:cursor-progress motion-reduce:transition-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
  {
    variants: {
      variant: {
        default: "bg-primary text-primary-foreground hover:bg-primary/90",
        secondary:
          "bg-secondary text-secondary-foreground hover:bg-secondary/80",
        outline:
          "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
        ghost: "hover:bg-accent hover:text-accent-foreground",
        destructive:
          "bg-destructive text-destructive-foreground hover:bg-destructive/90",
      },
      size: {
        sm: "h-8 px-3 text-xs",
        md: "h-9 px-4",
        lg: "h-10 px-6",
        icon: "size-9",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "md",
    },
  },
);

export interface ButtonProps
  extends React.ComponentProps<"button">,
    VariantProps<typeof buttonVariants> {
  /** Render the child element instead of a button (Radix Slot), e.g. a link. */
  asChild?: boolean;
  /** Shows a spinner, sets aria-busy and ignores clicks while true. */
  loading?: boolean;
}

function Button({
  className,
  variant,
  size,
  asChild = false,
  loading = false,
  type,
  onClick,
  children,
  ...props
}: ButtonProps) {
  const Comp = asChild ? Slot.Root : "button";
  return (
    <Comp
      data-slot="button"
      // A Slot child keeps its own semantics; only a real button gets a type.
      type={asChild ? undefined : (type ?? "button")}
      {...props}
      // aria-disabled (not disabled) keeps keyboard focus on the button
      // while the action runs; the click guard below does the blocking.
      aria-busy={loading || undefined}
      aria-disabled={loading || props["aria-disabled"] || undefined}
      className={cn(buttonVariants({ variant, size }), className)}
      onClick={(event: React.MouseEvent<HTMLButtonElement>) => {
        if (loading) {
          event.preventDefault();
          return;
        }
        onClick?.(event);
      }}
    >
      {asChild ? (
        children
      ) : (
        <>
          {loading ? (
            <LoaderCircle
              aria-hidden="true"
              className="motion-safe:animate-spin"
            />
          ) : null}
          {children}
        </>
      )}
    </Comp>
  );
}

export { Button, buttonVariants };

Dependencies

Usage

<Button onClick={save} loading={saving}>Save changes</Button>

Props

PropTypeDefaultDescription
variant"default" | "secondary" | "outline" | "ghost" | "destructive""default"Visual weight. Use one default button per view.
size"sm" | "md" | "lg" | "icon""md"Height and padding. An icon button needs an aria-label.
loadingbooleanfalseShows a spinner and blocks activation while keeping focus: aria-disabled on Radix, focusableWhenDisabled on Base UI, isPending on React Aria.
asChildbooleanfalseRadix only: render the child element (for example a link) with button styles.
onPress(e: PressEvent) => voidReact Aria only: use onPress instead of onClick.
...propsReact.ComponentProps<"button">Every native button attribute.

Accessibility

Credits

License and source

License
MIT
Author
Design From Labs <https://labs.designfrom.com>
Source
github.com/Design-from-labs/labs
Commit
803b92c1a30e
Date
2026-10-12
Origin
labs-examples