# Rokkit Button Component
> Versatile button component with variants, icons, and accessibility support.
The Button component provides a flexible, accessible button with support for multiple variants, left/right icons, and custom content through snippets.
## Quick Start
```svelte
console.log('clicked')} />
```
## Core Concepts
### Variants
Button supports multiple visual variants:
```svelte
```
### Icons
Add icons to either side of the button:
```svelte
{#snippet leftIcon()}
{/snippet}
```
### Custom Content
Use children snippet for full control:
```svelte
Bold and italic
```
## Props
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `string` | `null` | Button text |
| `variant` | `string` | `'default'` | Visual variant |
| `type` | `string` | `'button'` | HTML button type |
| `leftIcon` | `string \| Snippet` | `null` | Icon on left side |
| `rightIcon` | `string \| Snippet` | `null` | Icon on right side |
| `disabled` | `boolean` | `false` | Disables the button |
| `description` | `string` | `null` | Aria-label override |
| `class` | `string` | `''` | CSS class names |
| `children` | `Snippet` | `null` | Custom button content |
| `onclick` | `function` | `undefined` | Click handler |
### Variant Options
| Variant | Use Case |
|---------|----------|
| `'default'` | Standard actions |
| `'primary'` | Main call-to-action |
| `'secondary'` | Alternative actions |
| `'tertiary'` | Low-emphasis actions |
### Type Options
| Type | Use Case |
|------|----------|
| `'button'` | Standard button (default) |
| `'submit'` | Form submission |
| `'reset'` | Form reset |
## Component Structure
```
├── // Left icon (if provided)
├── {label} // Label text or children
└── // Right icon (if provided)
```
## Data Attributes for Styling
| Attribute | Element | Purpose |
|-----------|---------|---------|
| `data-button-root` | button | Main button element |
| `data-variant` | button | Current variant |
| `data-disabled` | button | Disabled state |
### Styling Example
```css
[data-button-root] {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 16px;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s, transform 0.1s;
}
[data-button-root]:active {
transform: scale(0.98);
}
[data-button-root][data-disabled="true"] {
opacity: 0.5;
cursor: not-allowed;
}
/* Variants */
[data-button-root][data-variant="default"] {
background: var(--surface-100);
color: var(--surface-900);
border: 1px solid var(--border-color);
}
[data-button-root][data-variant="primary"] {
background: var(--primary-500);
color: white;
border: none;
}
[data-button-root][data-variant="secondary"] {
background: var(--secondary-500);
color: white;
border: none;
}
[data-button-root][data-variant="tertiary"] {
background: transparent;
color: var(--primary-600);
border: none;
}
[data-button-root][data-variant="primary"]:hover {
background: var(--primary-600);
}
```
## Accessibility
- Uses native `` element
- `aria-label` from `description` or `label` prop
- `disabled` attribute properly set
- Keyboard accessible (Enter/Space)
## Import
```javascript
// Named import
import { Button } from '@rokkit/ui'
// Default import
import Button from '@rokkit/ui/button'
```
## TypeScript Types
```typescript
interface ButtonProps {
label?: string
variant?: 'default' | 'primary' | 'secondary' | 'tertiary'
type?: 'button' | 'submit' | 'reset'
leftIcon?: string | Snippet
rightIcon?: string | Snippet
disabled?: boolean
description?: string
class?: string
children?: Snippet
onclick?: (event: MouseEvent) => void
}
```
## Examples
### Basic Buttons
```svelte
```
### With Icons
```svelte
```
### Icon-Only Button
```svelte
```
### Form Buttons
```svelte
```
### Disabled State
```svelte
```
### Custom Content
```svelte
⭐
Upgrade to Pro Get unlimited access
>
```
### Button Group
```svelte
```
## Related Components
- **Icon** - Icon rendering used in buttons
- **Toggle** - For boolean toggle actions
- **FloatingAction** - Floating action buttons