Button Component Documentation

A customizable button component supporting multiple variants, sizes, icons, loading states, and anchor links.

Complete Installation Guide

Comprehensive step-by-step instructions to install and use the Buttoncomponent in your React/Next.js project with TypeScript and JavaScript support.

Step 1: Install Component

Description: Install the component using our CLI tool

Type: cli

TypeScript Installation Command:

npx screenui add button --lang ts --path src/components

JavaScript Installation Command:

npx screenui add button --lang js --path src/components

Step 2: Usage Example

Description: Copy and use the component in your project

Type: usage

TypeScript Implementation

Complete TypeScript code examples for the Button component with full type safety, props interface, and implementation details.

File: Button.tsx

Language: tsx

File Type: TypeScript React Component


import { Button } from "@/components/button";

export function Example() {
  return (
    <Button className="bg-blue-500 text-white hover:bg-blue-600">
      Click Me
    </Button>

      <Button 
      variant="outline" 
      icon={<Trash />}
      className="border-red-500 text-red-500 hover:bg-red-50"
    >
      Delete
    </Button>
  );
}

JavaScript Implementation

Complete JavaScript code examples for the Button component with ES6+ syntax, modern React patterns, and compatibility notes.

File: Button.jsx

Language: jsx

File Type: JavaScript React Component


import { Button } from "@/components/button";

export function Example() {
  return (
    <Button className="bg-blue-500 text-white hover:bg-blue-600">
      Click Me
    </Button>

      <Button 
      variant="outline" 
      icon={<Trash />}
      className="border-red-500 text-red-500 hover:bg-red-50"
    >
      Delete
    </Button>
  );
}

Required Dependencies and Prerequisites

The following packages and tools are required to use this component. Ensure all dependencies are installed and properly configured.

  • react - Core React library for component functionality
  • tailwindcss - Utility-first CSS framework for styling
  • lucide-react - Icon library for visual elements

Usage Examples and Best Practices

Practical examples and recommended patterns for implementing and customizing the Button component in your React/Next.js application.

Basic Usage

Import and use the Button component in your React components. The component supports both TypeScript and JavaScript projects.

Advanced Configuration

Customize the component with props, styling, event handlers, and advanced patterns as shown in the code examples above.

Integration Notes

This component is designed to work seamlessly with Next.js, Tailwind CSS, and modern React patterns. It supports server-side rendering, static generation, and client-side hydration.

Accessibility Features

The component includes built-in accessibility features such as ARIA labels, keyboard navigation, screen reader support, and focus management.

Performance Considerations

Optimized for performance with React.memo, efficient re-rendering, and minimal bundle impact. Supports code splitting and lazy loading.

Frequently Asked Questions

How do I customize the styling?

Use Tailwind CSS classes via the className prop, or apply custom CSS using CSS modules or styled-components.

Is this component accessible?

Yes, the component follows WCAG guidelines and includes proper ARIA attributes, keyboard navigation, and screen reader support.

Can I use this with other frameworks?

This component is designed for React/Next.js, but the patterns can be adapted for other frameworks like Vue.js or Angular.

Versatile Button Component

UI Componentsv1.0.0

A customizable button component supporting multiple variants, sizes, icons, loading states, and anchor links.

Last updated: 2025-09-19

Go to Dashboard
Button Examples

Usage Notes

Variants

  • solid : Default variant for most actions.
  • outline : Adds a border and transparent background. Useful for secondary actions.
  • ghost : Minimal style with subtle hover feedback.
  • link : Renders like a text link with underline on hover.
  • soft : Lightweight background option with softer emphasis.

Sizes

  • sm : Compact size for tight layouts such as modals or sidebars.
  • md : Default balanced size suitable for most use cases.
  • lg : Larger size for important actions or more emphasis.
  • xl : Extra-large buttons for high visibility or call-to-actions.
  • icon : Square button optimized for icon-only actions.

With Icons

Place an icon before the label to improve clarity. Icons automatically adjust spacing with the button size.

<Button icon={<Plus />}>Add Item</Button>

Loading State

Set loading to true to show a spinner and disable the button automatically.

<Button loading>Submitting...</Button>

Full Width

Use fullWidth to make the button span its container.

<Button fullWidth>Continue</Button>

Anchor Links

Render the button as an anchor by setting as="a" with a valid href.

<Button as="a" href="/dashboard">Go to Dashboard</Button>