# Button

A labeled action in a few sizes and levels of emphasis.

- **Use it for**: An action: save, submit, open, run; or, with href, a call to action that navigates.
- **Not for**: Text links inside sentences. Try [IconButton](https://unseenui.com/components/icon-button/), [Card](https://unseenui.com/components/card/).

## Installation

```bash
npm install @stackunseen/ui
```

## Usage

```tsx
import { Button } from '@stackunseen/ui';
import '@stackunseen/ui/styles.css';

<Button variant="primary" onClick={saveChanges}>Save changes</Button>
```

## Props

- `children` (`ReactNode (optional)`): The visible button label.
- `onClick` (`(event: MouseEvent<HTMLButtonElement>) => void (optional)`): Handles activation. Track pending, success and failure in your application.
- `type` (`'button' | 'submit' | 'reset' (optional)`): Defaults to button. Set submit when it should submit a form.
- `variant` (`'primary' | 'secondary' | 'outline' | 'ghost' | 'danger' | 'link' (optional)`): Visual emphasis. Defaults to primary; danger suits a destructive action.
- `size` (`'default' | 'sm' (optional)`): Use sm for a compact secondary action. Omit it for the regular size.
- `disabled` (`boolean (optional)`): Prevents activation. Explain unavailable actions near the button.

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `asChild` | `boolean` | Render the single child element instead of a button, passing it the button's presentation. |
| `href` | `string` | Renders a link with Button's presentation, for calls to action that navigate. |
| `rel` | `string` | With href. |
| `size` | `"default" \| "sm"` |  |
| `target` | `string` | With href. |
| `variant` | `"link" \| "primary" \| "secondary" \| "outline" \| "ghost" \| "danger"` |  |

## Keyboard

Tab focuses an available button; Enter or Space activates it. Native disabled buttons are not focusable. This component defaults to type="button"; opt into type="submit" for forms.

## Works with

[Field](https://unseenui.com/components/field/), [Input](https://unseenui.com/components/input/), [Textarea](https://unseenui.com/components/textarea/), [Select](https://unseenui.com/components/select/), [Checkbox](https://unseenui.com/components/checkbox/), [Switch](https://unseenui.com/components/switch/), [Alert](https://unseenui.com/components/alert/), [ToggleGroup](https://unseenui.com/components/toggle-group/), [Chip](https://unseenui.com/components/chip/), [CopyButton](https://unseenui.com/components/copy-button/), [AppearanceToggle](https://unseenui.com/components/appearance-toggle/), [IconButton](https://unseenui.com/components/icon-button/)

Page: https://unseenui.com/components/button/
