# Button

Source: https://ecosphere.dev/docs/actions/button (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

The one primary per region, with secondary, tertiary, danger and on-fill variants.

`import { EcoButton } from "vue-ecosphere"`

## Variants

One filled button per region. A danger button is the destructive primary and counts as that one: its label names the consequence, never “OK”.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" icon="add-line">New request</EcoButton>
<EcoButton>Browse all records</EcoButton>
<EcoButton variant="tertiary">Cancel</EcoButton>
<EcoButton variant="danger" icon="delete-bin-line">Delete request</EcoButton>
```

React (react-ecosphere):

```tsx
<EcoButton variant="primary" icon="add-line">New request</EcoButton>
<EcoButton>Browse all records</EcoButton>
<EcoButton variant="tertiary">Cancel</EcoButton>
<EcoButton variant="danger" icon="delete-bin-line">Delete request</EcoButton>
```

## Small

For actions inside rows, cards and toolbars.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" size="sm">View activity</EcoButton>
<EcoButton variant="danger" size="sm">Revoke access</EcoButton>
```

React (react-ecosphere):

```tsx
<EcoButton variant="primary" size="sm">View activity</EcoButton>
<EcoButton variant="danger" size="sm">Revoke access</EcoButton>
```

## Disabled

Always pair a disabled control with text that says why.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" icon="add-line" disabled>New request</EcoButton>
```

React (react-ecosphere):

```tsx
<EcoButton variant="primary" icon="add-line" disabled>New request</EcoButton>
```

## Loading

While the action runs, the spinner takes the leading icon's place and the label stays, so the button barely moves. It keeps its colour and focus, and ignores clicks.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" icon="save-line" :loading="saving" @click="save">Save changes</EcoButton>
<EcoButton variant="danger" size="sm" loading>Revoke access</EcoButton>
<EcoButton loading>Export</EcoButton>
```

React (react-ecosphere):

```tsx
const [saving, setSaving] = useState(false);

<EcoButton variant="primary" icon="save-line" loading={saving} onClick={save}>Save changes</EcoButton>
<EcoButton variant="danger" size="sm" loading>Revoke access</EcoButton>
<EcoButton loading>Export</EcoButton>
```

## Through the router

With vue-router installed, `to` renders an anchor with the resolved href and navigates without a page load. Middle-click and modifier-clicks still open a new tab.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" to="/docs/actions/link" icon-end="arrow-right-line">See links</EcoButton>
<EcoButton :to="{ name: 'request', params: { id } }">Open request</EcoButton>
```

React (react-ecosphere):

```tsx
import { Link } from "react-router";

<EcoButton variant="primary" as={Link} to="/docs/actions/link" iconEnd="arrow-right-line">See links</EcoButton>
<EcoButton as={Link} to={`/requests/${id}`}>Open request</EcoButton>
```

## Current page

The button for the route you are on carries aria-current="page", and a tertiary one shows it, so a row of them works as a topbar.

Vue (vue-ecosphere):

```vue
<nav aria-label="Actions">
  <EcoButton variant="tertiary" to="/docs/actions/button">Button</EcoButton>
  <EcoButton variant="tertiary" to="/docs/actions/link">Link</EcoButton>
</nav>
```

React (react-ecosphere):

```tsx
{/* With a router, pass the current page yourself: aria-current="page" */}
<nav aria-label="Actions">
  <EcoButton variant="tertiary" as={Link} to="/docs/actions/button" aria-current={path === "/docs/actions/button" ? "page" : undefined}>Button</EcoButton>
  <EcoButton variant="tertiary" as={Link} to="/docs/actions/link" aria-current={path === "/docs/actions/link" ? "page" : undefined}>Link</EcoButton>
</nav>
```

## On fill

Only on the hero wash: a white button and a glass ghost.

Vue (vue-ecosphere):

```vue
<div class="hero__cta">
  <EcoButton variant="onfill" icon-end="arrow-right-line">Message them</EcoButton>
  <EcoButton variant="ghostfill">Browse all records</EcoButton>
</div>
```

React (react-ecosphere):

```tsx
<div className="hero__cta">
  <EcoButton variant="onfill" iconEnd="arrow-right-line">Message them</EcoButton>
  <EcoButton variant="ghostfill">Browse all records</EcoButton>
</div>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"primary" \| "secondary" \| "tertiary" \| "danger" \| "onfill" \| "ghostfill"` | "secondary" | Visual weight. One primary (or danger) per region. |
| `size` | `"md" \| "sm"` | "md" | Small buttons sit inside rows and cards. |
| `icon` | `string` | — | Leading RemixIcon name without the ri- prefix. |
| `iconEnd` | `string` | — | Trailing icon, nudged on hover (use an arrow). |
| `label` | `string` | — | Text when you don't use the default slot. |
| `wide` | `boolean` | false | Stretch to the container width. |
| `href` | `string` | — | Render as an anchor. |
| `to` | `string \| RouteLocationRaw` | — | Navigate through vue-router's RouterLink (an anchor with the resolved href) when the app has it installed; a string falls back to a plain link. Disabled or loading renders a button. |
| `type` | `"button" \| "submit" \| "reset"` | "button" | Native button type. |
| `disabled` | `boolean` | false | Pair with text that explains why. |
| `loading` | `boolean` | false | The action is running: a spinner replaces the leading icon, the label stays, aria-busy is set and clicks (and form submits) are ignored. Keeps the variant colour and focus; an href button renders as a button meanwhile. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"primary" \| "secondary" \| "tertiary" \| "danger" \| "onfill" \| "ghostfill"` | "secondary" | Visual weight. One primary (or danger) per region. |
| `size` | `"md" \| "sm"` | "md" | Small buttons sit inside rows and cards. |
| `icon` | `string` | — | Leading RemixIcon name without the ri- prefix. |
| `iconEnd` | `string` | — | Trailing icon, nudged on hover (use an arrow). |
| `label` | `string` | — | Text when you don't pass children. |
| `wide` | `boolean` | false | Stretch to the container width. |
| `href` | `string` | — | Render as an anchor. Other anchor attributes (target, rel) pass through. |
| `to / as` | `string \| object / ElementType` | — | as is your router's link component (react-router's Link, Next.js's Link); it gets to (or href) and must render an a. Without as, a string to becomes the href. |
| `type` | `"button" \| "submit" \| "reset"` | "button" | Native button type. |
| `disabled` | `boolean` | false | Pair with text that explains why. |
| `loading` | `boolean` | false | The action is running: a spinner replaces the leading icon, the label stays, aria-busy is set and clicks (and form submits) are ignored. Keeps the variant colour and focus; an href button renders as a button meanwhile. |
