# `LedgerUI.Components.Modal`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/modal.ex#L78)

Modal dialog for short tasks and confirmations (`<.modal>`).

    <.button phx-click={LedgerUI.open("export")}>Export</.button>

    <.modal id="export" title="Export report" description="October 2026" icon="download" size="sm">
      <p>Choose a format.</p>
      <:footer>
        <.button variant="ghost" phx-click={LedgerUI.close("export")}>Cancel</.button>
        <.button variant="primary">Export</.button>
      </:footer>
    </.modal>

The title is either `title="Export report"` or the `<:title>` slot (markup); the footer is `<:footer>`
or `<:actions>`; `show` is `open` under the name of Phoenix's generated `modal`.

It opens and closes in the browser (`LedgerUI.open/close/toggle("export")`, no round trip),
from the server (`LedgerUI.open(socket, "export")`) or from the `open` assign. The
`LedgerUI.Overlay` hook (`priv/static/ledger_ui/hooks/overlay.js`) keeps the focus inside, closes on
Esc and on a click on the backdrop (unless `prevent_close`), returns the focus to the trigger and
locks the page's scroll. `on_open` / `on_close` run however it opened or closed; as event names
they push `%{"id" => id}` to the LiveView (or `target`).

The root carries `data-lu-overlay`: use `LedgerUI.DOM.onBeforeElUpdated` (see the README) so patches
keep the browser's state.

`inline` renders the dialog in the page flow, always visible and without the hook: a static preview.

`layout="page"` is the dialog of the app templates: only while `open`, a dim `lu-overlay` and a
`div.lu-modal` (`header`, `.bd`, `footer`) laid over the closest positioned ancestor, no hook;
the page owns the state and the overlay, Esc and × push `on_close`. The `:header` slot is then
the content before the ×. With `phx-submit` or `phx-change` in the attributes the dialog itself
is a `<form>` (so its controls validate and submit); `phx-target` goes to the form.

# `modal`

## Attributes

* `id` (`:string`) (required)
* `layout` (`:string`) - `page`: the canvas-v2 dialog (`lu-overlay` + `div.lu-modal` with `header`, `.bd`, `footer`), shown only while `open` and closed by `on_close` (a LiveView event or `%JS{}`). Defaults to `nil`. Must be one of `nil`, `""`, or `"page"`.
* `open` (`:boolean`) - The server's state; the browser can still open and close it. Defaults to `false`.
* `show` (`:boolean`) - The same as `open` (the name of Phoenix's generated `modal`); either one opens it. Defaults to `false`.
* `animation` (`:string`) - Defaults to `"fade"`. Must be one of `"fade"`, `"scale"`, `"sheet"`, `"shift-down"`, or `"shift-up"`.
* `size` (`:string`) - Defaults to `"lg"`. Must be one of `"full"`, `"lg"`, `"md"`, `"sm"`, `"xl"`, or `"xs"`.
* `placement` (`:string`) - Defaults to `"center"`. Must be one of `"bottom"`, `"center"`, or `"top"`.
* `origin` (`:string`) - Defaults to `"center"`. Must be one of `"bottom"`, `"center"`, or `"top"`.
* `blur` (`:boolean`) - Defaults to `false`.
* `backdrop_class` (`:any`) - Defaults to `nil`.
* `prevent_close` (`:boolean`) - Defaults to `false`.
* `close_button` (`:boolean`) - Defaults to `true`.
* `close_variant` (`:string`) - Defaults to `"plain"`. Must be one of `"plain"`, or `"chip"`.
* `on_open` (`:any`) - Defaults to `nil`.
* `on_close` (`:any`) - Defaults to `nil`.
* `target` (`:any`) - Defaults to `nil`.
* `close_label` (`:string`) - Defaults to `"Close"`.
* `role` (`:string`) - Defaults to `"dialog"`. Must be one of `"dialog"`, or `"alertdialog"`.
* `description` (`:string`) - Defaults to `nil`.
* `body_class` (`:any`) - Defaults to `nil`.
* `class` (`:any`) - Merged into the card. Defaults to `nil`.
* `icon` (`:string`) - An icon tile before the title (needs `title`). Defaults to `nil`.
* `icon_tone` (`:string`) - Defaults to `"neutral"`. Must be one of `"accent"`, `"error"`, `"info"`, `"lime"`, `"neutral"`, `"success"`, or `"warning"`.
* `card_style` (`:string`) - Inline style of the card (overrides the `size` width). Defaults to `nil`.
* `inline` (`:boolean`) - Static preview: in the page flow, always open, no hook. Defaults to `false`.
* Global attributes are accepted.
## Slots

* `title` - The dialog's title (the `title="..."` attribute, a plain string, does the same); draws the header.
* `actions` - The footer's buttons; the same as `:footer`.
* `header` - Accepts attributes:

  * `variant` (`:string`)
  * `class` (`:any`)
  * `style` (`:string`)
* `footer` - Accepts attributes:

  * `class` (`:any`)
  * `style` (`:string`)
* `inner_block`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
