Overview
The Button component is built with reka-ui’sPrimitive 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:- Preview
- Code
Default
Primary action button with filled background:Destructive
For dangerous or destructive actions: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:Link
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:[&_svg:not([class*='size-'])]:size-4 selector.
Loading State
Show loading indicator with disabled state:resources/js/pages/system/auth/Login.vue:89-98:
Disabled State
Buttons can be disabled:pointer-events-none- Prevents clicksopacity-50- Visual indication of disabled state
As Child (Polymorphic)
Render the button as a different element:- 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
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link' | 'default' | Visual style variant |
size | 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm' | 'icon-lg' | 'default' | Size variant |
as | string | Component | 'button' | Element or component to render as |
asChild | boolean | false | Render as child component |
disabled | boolean | false | Disable button |
class | string | - | Additional CSS classes |
Accessibility
- Use descriptive text or
aria-labelfor icon-only buttons - Disabled buttons have
pointer-events-noneand reduced opacity - Focus states have visible ring indicators
- Proper
typeattribute for form buttons (submit,button,reset)
Best Practices
- Use the right variant -
destructivefor dangerous actions,outlinefor secondary actions - Add loading states - Prevent double-clicks during async operations
- Disable when needed - Disable buttons during form submission
- Icon accessibility - Always provide aria-label for icon-only buttons
- Consistent sizing - Use the same size for related buttons in a group