Button
A versatile button component with multiple variants, sizes, icon support, and loading states.
Button
Displays a button or a component that looks like a button with extensive customization options.
Installation
Download the Button component using the Frontfriend CLI:
This will install the Button component along with its dependencies (Icon, Spinner components).
Usage
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'main' | 'destructive' | 'tertiary' | 'secondary' | 'ghost' | 'ghostmain' | 'link' | 'linkDestructive' | 'main' | Visual style variant |
size | 'default' | 'sm' | 'lg' | 'default' | Button size |
icon | keyof typeof icons | undefined | Icon to display |
iconPosition | 'prefix' | 'suffix' | 'default' | 'default' | Icon position. Use 'default' for icon-only buttons |
loading | boolean | false | Show loading spinner |
loadingText | string | undefined | Custom text to show during loading |
asChild | boolean | false | Compose with child element using Radix Slot |
| ...rest | React.ButtonHTMLAttributes | - | All standard button HTML attributes |
Examples
Variants
The Button component supports 8 different visual variants to match different use cases.
Sizes
Three size options are available: small, default, and large.
With Icons
Buttons can display icons in three different positions: prefix (before text), suffix (after text), or default (icon-only).
Icon Prefix
Icon Suffix
Icon Only
Loading State
Display a loading spinner and optional loading text while an async action is in progress.
As Child (Composition)
Use the asChild prop to compose the Button with other components, such as links.
Disabled State
Design Tokens
The Button component uses design tokens from @frontfriend/tailwind for consistent theming. All colors, spacing, and typography are controlled through the design token system, ensuring consistency across your application.
Accessibility
- Button includes proper ARIA attributes
- Icon-only buttons should include an
aria-labelfor screen readers - Disabled state is properly communicated to assistive technologies
- Loading state maintains button focus and communicates status
Related Components
- Icon: Used internally for displaying icons
- Spinner: Used for loading states