# Buttons

<figure><img src="https://3046942752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHfd391cB6wDC8S3yHcie%2Fuploads%2FoefF6hjtUbbeFYZQuyzE%2Fimage.png?alt=media&#x26;token=d6cb9601-dbca-4948-a949-5c248f87f62a" alt=""><figcaption></figcaption></figure>

Adds one or more clickable buttons to your layout.\
Use these for confirming actions, opening modals, or triggering logic through custom `on_action` handlers.

***

## Structure

```lua
buttons = {
    {
        id = "confirm_btn",
        label = "Confirm",
        on_action = function(data)
            -- Custom logic for confirming a purchase
        end,
        should_close = true,
        class = "primary"
    },
    {
        id = "cancel_btn",
        label = "Cancel",
        action = "close_builder",
        class = "danger"
    }
}
```

***

## Options

| Key            | Description                                                                 |
| -------------- | --------------------------------------------------------------------------- |
| `id`           | Unique identifier for the button.                                           |
| `label`        | Text shown on the button.                                                   |
| `action`       | (Optional) Use `"close_builder"` to close the UI safely.                    |
| `on_action`    | (Optional) A function to run when clicked. Receives `data` if needed.       |
| `should_close` | (Optional) Closes the UI builder after clicking. Default: `false`.          |
| `class`        | (Optional) Style of button — try `"primary"`, `"danger"`, `"success"`, etc. |
| `icon`         | (Optional) Add an icon, e.g., `"fas fa-check"`.                             |
| `modal`        | (Optional) Show a confirmation modal before running the action.             |
| `dataset`      | (Optional) Extra data to pass to the `on_action` function.                  |

***

## Notes

* Use multiple buttons in a row by adding more entries to the `buttons` table.
* `dataset = {}` gets passed into your `on_action` function.
* Use `should_close = true` if the UI should close after pressing the button.
* Use `modal = { title = "...", description = "..." }` to prompt confirmation before the button runs its logic.
* For closing the UI, use the special global action:

  ```lua
  action = "close_builder"
  ```
