# Button

Displays a button or a link that looks like a button.

> Every page: https://constella.aayush.cv/llms.txt

## Installation

```bash
npx shadcn@latest add @constella/button
```

## Usage

```tsx
import { Button } from "@/components/primitives/button";
```

```tsx
<Button variant="outline">Button</Button>
```

## Variant

Use the `variant` prop to set how much the button stands out. Use one `primary` per view.

| Variant     | Use for                                    |
| ----------- | ------------------------------------------ |
| `primary`   | The main action of the view                |
| `secondary` | Everything else. The default.              |
| `outline`   | Actions on busy surfaces                   |
| `ghost`     | Repeated actions in toolbars, lists, menus |
| `link`      | Actions inside a sentence                  |

## Color

Use `color="danger"` for an action that deletes or destroys. Every variant takes it without changing its shape; `primary` draws the same tint as `secondary`.

```tsx
<Button color="danger">Delete</Button>
<Button color="danger" variant="ghost">Delete</Button>
```

## Size

Use the `size` prop to change the size of the button.

```tsx
<Button size="xs">Extra small</Button>
<Button size="sm">Small</Button>
<Button>Default</Button>
<Button size="lg">Large</Button>
```

## Icon Only

Use an `icon-*` size for a button with only an icon. Add an `aria-label`.

```tsx
<Button size="icon" aria-label="Search">
  <HugeiconsIcon icon={Search01Icon} size={sizes.icon} aria-hidden />
</Button>
```

## With Icon

Add `data-icon="inline-start"` or `data-icon="inline-end"` to the icon for the correct spacing. Use `sizes.iconXs` at `xs`, `sizes.iconSm` at `sm` and `sizes.icon` otherwise.

```tsx
<Button>
  <HugeiconsIcon
    icon={Add01Icon}
    size={sizes.icon}
    data-icon="inline-start"
    aria-hidden
  />
  New project
</Button>
```

## Corners

Buttons are pills by default. Use `corners="rounded"` for the theme's control corner, `radii.sm`.

```tsx
<Button corners="rounded">Get started</Button>
```

## As Link

Use `buttonStyles` to make a link look like a button.

**Don't use `<Button render={<a />} nativeButton={false} />` for links.** Base UI's `Button` always sets `role="button"`, so screen readers announce it as a button, not a link.

```tsx
import * as stylex from "@stylexjs/stylex";

import { buttonStyles } from "@/components/primitives/button";

<a href="/settings" {...stylex.props(buttonStyles({ variant: "outline" }))}>
  Settings
</a>;
```

## Disabled

Use `disabled` when the action isn't available. It fades the button and shows a not-allowed cursor.

```tsx
<Button disabled>Disabled</Button>
```

## Busy

Add `aria-busy` while something runs. It shows a busy cursor, so working reads differently from unavailable. What goes inside is up to you.

- With `disabled`, it's loading: it fades less than disabled and can't be pressed twice.
- Alone, it stays pressable at full strength, for a button that acts on the running work: press Generate, and the same button becomes Stop generating.

```tsx
<Button aria-busy disabled>
  <Spinner data-icon="inline-start" />
  Saving
</Button>
<Button aria-busy={generating} onClick={() => setGenerating(!generating)}>
  {generating && <Spinner data-icon="inline-start" />}
  {generating ? "Stop generating" : "Generate"}
</Button>
```

## API Reference

### Button

Takes every prop of [Base UI's Button](https://base-ui.com/react/components/button), plus:

| Prop | Type | Default |
| --- | --- | --- |
| `variant` | `"primary" \| "secondary" \| "outline" \| "ghost" \| "link"` | `"secondary"` |
| `color` | `"danger"` | - |
| `size` | `"xs" \| "sm" \| "default" \| "lg" \| "icon-xs" \| "icon-sm" \| "icon" \| "icon-lg"` | `"default"` |
| `corners` | `"rounded" \| "pill"` | `"pill"` |
| `sx` | `Sx`, applied last |  |

### buttonStyles

Returns the button's styles for `stylex.props`. Takes `variant`, `color`, `size` and `corners`, with the same defaults.
