> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/button.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Button

Triggers an action when pressed with a mouse, touch or keyboard.

{% code title="button/demo.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";

export default function ButtonDemo() {
  return <Button intent="g-button">Create product</Button>;
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { Button } from '@rierino-open/core-ui';

<Button intent="g-button" onPress={() => save()}>
  Save
</Button>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { Button } = CoreUI;

<Button intent="g-button" onPress={() => save()}>
  Save
</Button>
```

{% endtab %}
{% endtabs %}

Handle presses with `onPress`, not `onClick`. It fires once for a mouse click, a tap or the Enter and Space keys.

## Examples

### Intents

`intent` sets the colour scheme. The `g-` intents use Rierino gradients. Use `g-button` for the main action on a screen, such as Create or Save, and `danger` for destructive actions.

{% code title="button/intents.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";

export default function ButtonIntents() {
  return (
    <>
      <Button intent="primary">Primary</Button>
      <Button intent="secondary">Secondary</Button>
      <Button intent="danger">Danger</Button>
      <Button intent="warning">Warning</Button>
      <Button intent="g-button">g-button</Button>
      <Button intent="g-button2">g-button2</Button>
      <Button intent="g-heliotrope">g-heliotrope</Button>
      <Button intent="g-violet">g-violet</Button>
      <Button intent="g-fill">g-fill</Button>
      <Button intent="g-list">g-list</Button>
      <Button intent="g-mauve">g-mauve</Button>
      <Button intent="g-manatee">g-manatee</Button>
      <Button intent="g-hawkes-blue">g-hawkes-blue</Button>
    </>
  );
}
```

{% endcode %}

### Appearances

`appearance` controls the fill. `solid` is the default. Use `outline` or `plain` for secondary actions next to a solid button.

{% code title="button/appearances.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";

export default function ButtonAppearances() {
  return (
    <>
      <Button appearance="solid">Solid</Button>
      <Button appearance="outline">Outline</Button>
      <Button appearance="plain">Plain</Button>
    </>
  );
}
```

{% endcode %}

### Sizes

{% code title="button/sizes.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";

export default function ButtonSizes() {
  return (
    <>
      <Button size="extra-small">Extra small</Button>
      <Button size="small">Small</Button>
      <Button size="medium">Medium</Button>
      <Button size="large">Large</Button>
    </>
  );
}
```

{% endcode %}

### Shapes

{% code title="button/shapes.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";

export default function ButtonShapes() {
  return (
    <>
      <Button shape="square">Square</Button>
      <Button shape="circle">Circle</Button>
    </>
  );
}
```

{% endcode %}

### With icons

Mark an icon with `data-slot="icon"` so the button sizes it and colours it to match the intent. The button doesn't space its children, so add a gap between the icon and the label (here `gap-2`). For an icon-only button, use `size="square-petite"` and give the button an `aria-label`.

{% code title="button/icons.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";
import { Plus, Trash2 } from "lucide-react";

export default function ButtonIcons() {
  return (
    <>
      <Button intent="g-button" className="gap-2">
        <Plus data-slot="icon" />
        Create
      </Button>
      <Button intent="danger" size="square-petite" aria-label="Delete">
        <Trash2 data-slot="icon" />
      </Button>
      <Button intent="g-button" size="square-petite" shape="circle" aria-label="Add">
        <Plus data-slot="icon" />
      </Button>
    </>
  );
}
```

{% endcode %}

### Disabled

{% code title="button/disabled.tsx" %}

```tsx
import { Button } from "@rierino-open/core-ui";

export default function ButtonDisabled() {
  return (
    <>
      <Button intent="g-button" isDisabled>
        Save
      </Button>
      <Button appearance="outline" isDisabled>
        Cancel
      </Button>
    </>
  );
}
```

{% endcode %}

### Handling presses

{% code title="button/events.tsx" %}

```tsx
import { useState } from "react";
import { Button } from "@rierino-open/core-ui";

export default function ButtonEvents() {
  const [count, setCount] = useState(0);

  return (
    <>
      <Button intent="g-button" onPress={() => setCount((c) => c + 1)}>
        Press me
      </Button>
      <span>Pressed {count} times</span>
    </>
  );
}
```

{% endcode %}

## Accessibility

* Renders a native `<button>`, so it works in forms and with assistive technology. Set `type="submit"` to submit a form.
* **Keyboard:** `Enter` and `Space` press the button. The focus ring appears only when focus comes from the keyboard.
* **Icon-only buttons need a label.** Without visible text, pass `aria-label` so screen readers can announce the button.
* `isDisabled` removes the button from the tab order and ignores presses. `isPending` keeps it focusable but ignores presses, for actions in progress.

## Styling

The button sets these attributes for state styling. See [Styling components](https://docs.rierino.com/sdk-core-ui/foundations/styling.md) for how to use them.

| Attribute            | Present when                   |
| -------------------- | ------------------------------ |
| `data-hovered`       | The pointer is over the button |
| `data-pressed`       | The button is being pressed    |
| `data-focus-visible` | The button has keyboard focus  |
| `data-disabled`      | `isDisabled` is set            |
| `data-pending`       | `isPending` is set             |

To recolour a single solid button, set `--btn-bg`. `--btn-icon` sets the colour of icons marked `data-slot="icon"`:

```tsx
<Button style={{ '--btn-bg': 'var(--color-eucalyptus)' } as React.CSSProperties}>
  Approve
</Button>
```

## API reference

| Prop         | Type                                                                                                                                                                                    | Default     | Description                                                                                                                                                                        |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `intent`     | `"danger" \| "g-button" \| "g-button2" \| "g-fill" \| "g-hawkes-blue" \| "g-heliotrope" \| "g-list" \| "g-manatee" \| "g-mauve" \| "g-violet" \| "primary" \| "secondary" \| "warning"` | `"primary"` | The colour scheme. `g-*` intents use Rierino gradients; `g-button` is the primary action button used for actions such as Create and Save.                                          |
| `size`       | `"extra-small" \| "large" \| "medium" \| "small" \| "square-petite"`                                                                                                                    | `"medium"`  | The padding and text size. `square-petite` is a 36px square for icon-only buttons.                                                                                                 |
| `shape`      | `"circle" \| "square"`                                                                                                                                                                  | `"square"`  | The corner style: rounded corners, or fully round ends.                                                                                                                            |
| `appearance` | `"outline" \| "plain" \| "solid"`                                                                                                                                                       | `"solid"`   | `solid` fills the button with the intent's colour, `outline` draws a border, and `plain` has no border or shadow, for secondary and toolbar actions.                               |
| `aria-label` | `string`                                                                                                                                                                                |             | Defines a string value that labels the current element.                                                                                                                            |
| `onPress`    | `((e: PressEvent) => void)`                                                                                                                                                             |             | Handler that is called when the press is released over the target.                                                                                                                 |
| `autoFocus`  | `boolean`                                                                                                                                                                               |             | Whether the element should receive focus on render.                                                                                                                                |
| `isDisabled` | `boolean`                                                                                                                                                                               |             | Whether the button is disabled.                                                                                                                                                    |
| `type`       | `"button" \| "reset" \| "submit"`                                                                                                                                                       | `'button'`  | The behavior of the button when used in an HTML form.                                                                                                                              |
| `className`  | `string \| ((state) => string)`                                                                                                                                                         |             | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `style`      | `CSSProperties \| ((state) => CSSProperties)`                                                                                                                                           |             | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state.  |
| `children`   | `ReactNode \| ((state) => ReactNode)`                                                                                                                                                   |             | The children of the component. A function may be provided to alter the children based on component state.                                                                          |
| `isPending`  | `boolean`                                                                                                                                                                               |             | Whether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers.                    |

`Button` also accepts the other props of React Aria's [Button](https://react-spectrum.adobe.com/react-aria/Button.html#props), such as `onPressStart`, `onHoverChange` and `form`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/button.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
