Button Component

A versatile button component with multiple variants and sizes, built with accessibility in mind.

  • Supports multiple variants: primary, secondary, outline, and ghost.
  • Available in various sizes: small, medium, and large.
  • Fully accessible with ARIA attributes.

Installation

The Button component is part of our UI library. You can import it directly from the components directory.


Usage

Here is how to use the button in your project.

React TSX
1import { Button } from "@/components/modern-ui/button"

React TSX
1<Button variant="outline">Button</Button>

Examples

Default Button

Secondary Button

Outline Button

Destructive Button

Ghost Button

Button Sizes

Button with Icon

Icon Button

Loading Button

API Reference

Button Component Props

PropTypeDefaultDescription
variant'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link' | 'icon''default'Controls the visual style of the button
size'default' | 'sm' | 'lg' | 'icon''default'Controls the size of the button
asChildbooleanfalseWhen true, the component will render its child as the button
iconReactNode-Optional icon to display alongside the button text
loadingbooleanfalseWhen true, displays a loading spinner and disables the button
classNamestring-Additional CSS classes to apply to the button
childrenReactNode-The content of the button
disabledbooleanfalseWhen true, disables the button

Additionally, the Button component accepts all standard HTML button attributes.

CSS Classes

The button uses the following CSS class variants:

Variant Classes

  • default: Primary button with background color
  • destructive: Red/danger button for destructive actions
  • outline: Button with a border and transparent background
  • secondary: Alternative button style with different background
  • ghost: Button with no background until hovered
  • link: Button that appears as a text link
  • icon: Special variant optimized for icon-only buttons

Size Classes

  • default: Standard button size (h-9 px-4 py-2)
  • sm: Small button size (h-8 rounded-md px-3 text-xs)
  • lg: Large button size (h-10 rounded-md px-8)
  • icon: Square button size for icon-only buttons (h-9 w-9)