ShakibDShy

Button

A versatile button component with multiple variants and features

Button

A highly customizable button component that supports multiple variants, sizes, colors, and states.

Features

Multiple Variants

Solid, outline, flat, light, ghost, and text variants

Color Options

Primary, secondary, neutral, info, success, warning, and error colors

Flexible Sizing

XS to 2XL size options with consistent spacing

Loading States

Built-in loading states with customizable spinners

Import

import { Button } from 'react-button-pro';

Basic Usage

Disabled State

Props

Common Props

PropTypeDefaultDescription
variant'solid' | 'outline' | 'flat' | 'light' | 'ghost' | 'text''solid'The visual style variant of the button
color'primary' | 'secondary' | 'neutral' | 'info' | 'error' | 'warning' | 'success''primary'The color scheme of the button
size'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl''md'The size of the button
rounded'none' | 'sm' | 'md' | 'lg' | 'full''md'The border radius of the button
isDisabledbooleanfalseWhether the button is disabled
isLoadingbooleanfalseWhether the button is in a loading state
spinnerReactNode-Custom spinner component for loading state
spinnerColor'primary' | 'secondary' | 'info' | 'neutral' | 'error' | 'warning' | 'success' | 'white'-Color of the loading spinner
classNamestring-Additional CSS classes

Button-specific Props

PropTypeDefaultDescription
type'button' | 'submit' | 'reset''button'The type of the button
as'button' | 'a''button'Render as a button or anchor element

Anchor-specific Props

When as="a", the button accepts all anchor (<a>) element props plus the common props above.

Examples

For more examples, check out:

Accessibility

The Button component follows WAI-ARIA guidelines:

  • Uses native <button> element by default
  • Supports keyboard navigation
  • Maintains focus states
  • Includes proper ARIA attributes
  • Handles disabled states correctly

Best Practices

  1. Use appropriate colors for different actions:

    • Primary for main actions
    • Secondary for alternative actions
    • Danger/Error for destructive actions
  2. Choose the right variant:

    • Solid for primary actions
    • Outline for secondary actions
    • Ghost/Text for tertiary actions
  3. Size considerations:

    • Use consistent sizes within the same context
    • Consider touch targets for mobile
    • Match size with surrounding elements
  4. Loading states:

    • Show loading state during async operations
    • Maintain button width during loading
    • Provide visual feedback

Last updated on

On this page