Skip to main content

Button Component

The Button component is a versatile, accessible button element that suppo rts multiple variants, sizes, and states for various use cases in your application. rts multiple variants, sizes, and states for various use cases in your application.

Basic Usage

Live Editor
<Button>Click me</Button>
Result
Loading...

Code:

<Button>Click me</Button>

Variants

Primary (Default)

Live Editor
<Button variant='primary'>Primary Button</Button>
Result
Loading...

Secondary

Live Editor
<Button variant='secondary'>Secondary Button</Button>
Result
Loading...

Success

Live Editor
<Button variant='success'>Success Button</Button>
Result
Loading...

Warning

Live Editor
<Button variant='warning'>Warning Button</Button>
Result
Loading...

Danger

Live Editor
<Button variant='danger'>Danger Button</Button>
Result
Loading...

Ghost

Live Editor
<Button variant='ghost'>Ghost Button</Button>
Result
Loading...

Sizes

Extra Small

Live Editor
<Button size='xs'>Extra Small</Button>
Result
Loading...

Small

Live Editor
<Button size='sm'>Small</Button>
Result
Loading...

Medium (Default)

Live Editor
<Button size='md'>Medium</Button>
Result
Loading...

Large

Live Editor
<Button size='lg'>Large</Button>
Result
Loading...

Extra Large

Live Editor
<Button size='xl'>Extra Large</Button>
Result
Loading...

States

Loading State

Live Editor
<Button loading>Loading...</Button>
Result
Loading...

Disabled State

Live Editor
<Button disabled>Disabled</Button>
Result
Loading...

With Icons

Left Icon

Live Editor
<Button leftIcon=''>Launch</Button>
Result
Loading...

Right Icon

Live Editor
<Button rightIcon=''>Continue</Button>
Result
Loading...

Full Width

Live Editor
<Button fullWidth>Full Width Button</Button>
Result
Loading...

Rounded Variant

<Button rounded>Rounded Button</Button>

Interactive Demo

Try clicking the buttons below to see them in action:

Live Editor
<div style={{ display: 'flex', gap: '8px', flexWrap: 'wrap' }}>
  <Button variant='primary' onClick={() => alert('Primary clicked!')}>
    Click Me
  </Button>
  <Button variant='secondary' onClick={() => alert('Secondary clicked!')}>
    Click Me
  </Button>
  <Button variant='success' onClick={() => alert('Success clicked!')}>
    Click Me
  </Button>
  <Button variant='warning' onClick={() => alert('Warning clicked!')}>
    Click Me
  </Button>
  <Button variant='danger' onClick={() => alert('Danger clicked!')}>
    Click Me
  </Button>
</div>
Result
Loading...

API Reference

Props

| Prop | Type | Default | Description | | ------------------------------------------------------------------------- | ---------------------------- | | children | ReactNode | - | Button content | | variant | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'ghost' | 'primary' | Button style variant | | size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Button size | | loading | boolean | false | Shows loading spinner | | disabled | boolean | false | Disables the button | | leftIcon | string | - | Icon to display on the left | | rightIcon | string | - | Icon to display on the right | | fullWidth | boolean | false | Makes button full width | | rounded | boolean | false | Applies rounded corners | | onClick | (event: MouseEvent) => void | - | Click handler | | type | 'button' | 'submit' | 'reset' | 'button' | HTML button type | | className | string | - | Additional CSS classes |

CSS Classes

The Button component uses the following CSS classes:

  • .btn - Base button class
  • .btn--{variant} - Variant-specific classes (e.g., .btn--primary)
  • .btn--{size} - Size-specific classes (e.g., .btn--lg)
  • .btn--loading - Loading state class
  • .btn--disabled - Disabled state class
  • .btn--full-width - Full width class
  • .btn--rounded - Rounded variant class

Accessibility

  • Proper ARIA labels and roles
  • Keyboard navigation support
  • Focus management
  • Screen reader compatibility
  • Loading state announcements

Best Practices

  1. Use semantic variants: Choose variants that match the button's purpose
  2. Provide clear labels: Button text should clearly indicate the action
  3. Handle loading states: Show loading indicators for async operations
  4. Consider button hierarchy: Use primary variants for main actions
  5. Test keyboard navigation: Ensure all buttons are accessible via keyboard

Implementation

Ready to use the Button component in your project?

  1. Install the package: pnpm add @react-superadmin/web
  2. Import and use:
    // Component is available in the live scope
    function MyComponent() {

return ; }

3. **Customize**: Use the props and variants shown above to match your design system