- Primary
- Success
- Danger
- Ghost
Button Component
TheButton component is a versatile, styled button built on top of the native HTML button element. It supports multiple variants, sizes, icons, and loading states.
Import
Basic Usage
API Reference
Props
TheButton component extends all standard HTML button attributes and adds the following custom props:
The visual style variant of the button.Options:
primary- Blue background, white text with shadowsecondary- Light gray background with bordersuccess- Green background with hover lift effectdanger- Red background for destructive actionsghost- Transparent background, visible on hoveroutline- Transparent with border
The size of the button.Options:
sm- Small (px-3 py-1.5 text-xs)md- Medium (px-4 py-2.5 text-sm)lg- Large (px-5 py-3 text-base)xl- Extra Large (px-6 py-4 text-lg h-16)
An optional icon element to display before the button text.
When
true, displays a spinning loader icon and disables the button.When
true, the button takes up the full width of its container.Additional CSS classes to apply to the button.
When
true, disables the button (also disabled when isLoading is true).The content to display inside the button.
Inherited Props
The component also accepts all standardButtonHTMLAttributes<HTMLButtonElement> props including:
onClicktype(button, submit, reset)formnamevalue- And all other native button attributes
Examples
Variant Examples
Size Examples
With Icon
Loading State
Full Width
Custom Styling
Styling Details
Base Styles
All buttons include these base styles:- Flexbox centering for content
- Bold font weight
- Rounded corners (rounded-lg)
- Smooth transitions
- Focus ring for accessibility
- Disabled state styling (50% opacity, not-allowed cursor)
Variant Color Schemes
| Variant | Background | Text | Hover | Focus Ring |
|---|---|---|---|---|
| primary | Blue 600 | White | Blue 700 | Blue 500 |
| secondary | Slate 100 | Slate 700 | Slate 200 | Slate 500 |
| success | Emerald 600 | White | Emerald 700 | Emerald 500 |
| danger | Red 500 | White | Red 600 | Red 500 |
| ghost | Transparent | Slate 600 | Slate 100 | Slate 500 |
| outline | Transparent | Slate 700 | Slate 50 | Slate 500 |
Accessibility
- Supports keyboard navigation (Tab, Enter, Space)
- Includes focus ring for visibility
- Properly handles disabled state
- Loading state prevents multiple submissions
Source Code
Location:/home/daytona/workspace/source/src/components/ui/Button.tsx:1