Skip to main content

Overview

The Button component is built with reka-ui’s Primitive component and uses class-variance-authority (CVA) to manage variants. It supports multiple visual styles and sizes.

Basic Usage

Button Variants

The button component supports 6 visual variants:

Default

Primary action button with filled background:

Destructive

For dangerous or destructive actions:
Example from resources/js/components/DeleteUser.vue:42-44:

Outline

Button with border and transparent background:

Secondary

For secondary actions with muted styling:

Ghost

Minimal button without background until hover:
Styled like a text link:

Button Sizes

Buttons come in 6 different sizes:

Size Variants

  • sm - Small button (h-8)
  • default - Default size (h-9)
  • lg - Large button (h-10)
  • icon - Square icon button (size-9)
  • icon-sm - Small icon button (size-8)
  • icon-lg - Large icon button (size-10)

Icon Buttons

Buttons optimized for displaying only an icon:

Buttons with Icons

Combine text with icons:
Icons are automatically sized using the [&_svg:not([class*='size-'])]:size-4 selector.

Loading State

Show loading indicator with disabled state:
Example from resources/js/pages/system/auth/Login.vue:89-98:

Disabled State

Buttons can be disabled:
Disabled buttons automatically receive:
  • pointer-events-none - Prevents clicks
  • opacity-50 - Visual indication of disabled state

As Child (Polymorphic)

Render the button as a different element:
This is useful for:
  • Router links
  • Anchor tags
  • Custom interactive elements

Full Width Button

Make button take full container width:

Button Groups

Group related buttons:

Common Patterns

Form Submit Button

Dialog Trigger

Confirmation Actions

Toggle Components

For toggle functionality, use the Toggle component:

Toggle Group

For mutually exclusive toggles:

Button Props

Accessibility

  • Use descriptive text or aria-label for icon-only buttons
  • Disabled buttons have pointer-events-none and reduced opacity
  • Focus states have visible ring indicators
  • Proper type attribute for form buttons (submit, button, reset)

Best Practices

  1. Use the right variant - destructive for dangerous actions, outline for secondary actions
  2. Add loading states - Prevent double-clicks during async operations
  3. Disable when needed - Disable buttons during form submission
  4. Icon accessibility - Always provide aria-label for icon-only buttons
  5. Consistent sizing - Use the same size for related buttons in a group