# Button

> Starts an action, such as saving a form or opening a dialog.

A button starts an action on the current page; use a link when the action takes the person somewhere else.

## When to use

- Use one `default` button for the main action of a form, card or dialog.
- Use `secondary` or `outline` for the other actions next to it.
- Use `ghost` in toolbars and dense rows, and `link` inside running text.
- Use `destructive` only for actions that delete or cancel something.
- Don't use a button to navigate to another page; use a link.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/button/_

### Do and don't

- **Do:** Use one default button for the main action; the others are outline or secondary.
- **Don't:** Don't give two actions the same weight; people can't tell which one moves them forward.

## Anatomy

1. Container, on the control radius
2. Label
3. Outline variant for a second action

A button is a label, with an optional icon before or after it. It sits on the control radius (`radius-md`, 8px) and is never a pill.

## Variants

| Variant | Looks | Use it for |
| --- | --- | --- |
| `default` | `primary` fill, `primary-foreground` text | The main action. One per area. |
| `secondary` | `secondary` fill | A second action with less weight. |
| `outline` | `border` outline on `background` | Neutral actions next to the main one. |
| `ghost` | No fill until hover | Toolbars, table rows, icon buttons. |
| `destructive` | `destructive` text on a soft destructive fill | Delete, reject or cancel. |
| `link` | `primary` text, underlined on hover | Actions inside a sentence. |

Sizes: `xs`, `sm`, `default`, `lg`, and square `icon`, `icon-xs`, `icon-sm`, `icon-lg` for icon-only buttons.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `variant` | `variant` | named constructor (`ShadButton.outline`) | see Variants | `default` | Visual weight. |
| `size` | `size` | `size` (`ShadButtonSize`) | see Variants | `default` | Height and padding. |
| `disabled` | `disabled` | `enabled: false` | boolean | `false` | Blocks the action. |
| `onClick` | `@click` | `onPressed` | function | none | Runs the action. |

## Code

**React**
```tsx
import { Button } from "@/components/ui/button"

export default function ButtonDemo() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <Button>Simpan</Button>
      <Button variant="secondary">Simpan draf</Button>
      <Button variant="outline">Lihat detail</Button>
      <Button variant="ghost">Batal</Button>
      <Button variant="destructive">Hapus</Button>
      <Button variant="link">Pelajari lebih lanjut</Button>
    </div>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Button } from "@/components/ui/button"
</script>

<template>
  <div class="flex flex-wrap items-center gap-2">
    <Button>Simpan</Button>
    <Button variant="secondary">Simpan draf</Button>
    <Button variant="outline">Lihat detail</Button>
    <Button variant="ghost">Batal</Button>
    <Button variant="destructive">Hapus</Button>
    <Button variant="link">Pelajari lebih lanjut</Button>
  </div>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class ButtonDemo extends StatelessWidget {
  const ButtonDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return Wrap(
      spacing: 8,
      runSpacing: 8,
      children: [
        ShadButton(onPressed: () {}, child: const Text('Simpan')),
        ShadButton.secondary(onPressed: () {}, child: const Text('Simpan draf')),
        ShadButton.outline(onPressed: () {}, child: const Text('Lihat detail')),
        ShadButton.ghost(onPressed: () {}, child: const Text('Batal')),
        ShadButton.destructive(onPressed: () {}, child: const Text('Hapus')),
        ShadButton.link(onPressed: () {}, child: const Text('Pelajari lebih lanjut')),
      ],
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/button.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/button.json
```

## Accessibility

- Renders a native `button`, so Enter and Space trigger it.
- Every icon-only button needs an `aria-label`.
- The focus ring uses `ring` and shows only for keyboard focus.
- Keep the label to the action itself: "Simpan", not "Klik di sini".
