Inputs & controlsstable

    Buttons

    A button component that can be used to trigger an action or event. It supports multiple styles, sizes, and disabled states.

    Follow the installation and quick start below to use Buttons in your project, or read the complete setup guide.

    Accessible by designLight & darkCopy. Customize. Ship.
    On this page
    Live previewFluid
    Interactive exampleReact / TypeScript / Tailwind CSS
    ADD TO YOUR PROJECT

    Installation

    1. Initialize once

    Run from an existing React project with Node.js 18 or later. Skip this step if the project already has u-lib.json. Initialization copies the shared stylesheet and adds its import to your application entry.

    npx @scriptwithahmad/u-lib@0.2.2 init

    2. Add Buttons and example components

    This command includes the UI components used by this page's usage examples. The CLI copies editable source into your components directory and installs each component's dependencies. Existing source files are preserved.

    npx @scriptwithahmad/u-lib@0.2.2 add button

    3. Install example dependencies

    These packages are imported directly by the examples. Some may already have been installed by the CLI.

    npm install lucide-react

    Choose the tab for your package manager. Yarn commands require modern Yarn; Yarn Classic users can use npx. Use --dry-run to preview changes. See the installation guide for custom paths, JavaScript output and package-import alternatives.

    USE IN YOUR APP

    Quick start

    Copy this example into src/Example.tsx (or Example.tsx at the project root when you do not use src). Imports assume the default CLI paths. From a nested file such as src/app/page.tsx, adjust ./components to ../components. Keep the client directive in Next.js when using state or event handlers.

    button-example.tsx
    "use client";
    
    import { Button } from "./components/ui/button";
    
    export default function UsageDemo() {
      return (
        <>
    <Button>Click me</Button>
        </>
      );
    }

    Keep the shared stylesheet imported once. Replace sample image URLs and data with your own. Examples may use layout utilities beyond the precompiled component styles; compile added Tailwind classes in your app or replace them with your own CSS. Customize local source or className, and preserve accessible names and keyboard behavior.

    BUILD WITH IT

    Usage examples

    5 examples

    Try each example, then switch to Code to copy its complete implementation. These catalog snippets use the website's @/components/ui alias; replace it with your local generated path as shown in Quick start.

    01

    Basic Usage

    Use the Button component for user interactions

    Basic Usage

    Loading example…

    02

    Button Variants

    Different styles for different purposes

    Button Variants

    Loading example…

    03

    Button Sizes

    Available in different sizes

    Button Sizes

    Loading example…

    04

    With Icons

    Combine with icons for better visual hierarchy

    With Icons

    Loading example…

    05

    Icon Only

    Use iconOnly for a square button containing an icon. Add an aria-label so its action has an accessible name.

    Icon Only

    Loading example…

    THE API

    Props & configuration

    Reference

    Everything you need to fine-tune this component.

    Props and configuration
    PropTypeDefaultDescription
    variant'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link'—The visual style of the button
    size'default' | 'sm' | 'lg' | 'icon'—The size of the button
    asChildboolean—Whether to render as a child component
    iconOnlybooleanfalseUse a square, padding-free button for a single icon child. Supports all variants and sizes. Supply aria-label or aria-labelledby for its accessible name.