DevactionUI.Modal (devaction_ui v0.2.3)

Copy Markdown View Source

A dialog for a decision that interrupts: confirm, tell that something worked, fill a short form. To edit without losing the context use DevactionUI.Drawer; to ask before something that cannot be undone use danger_dialog/1.

The LiveView decides when it is there (:if={@open}). It takes the focus in, keeps it inside, closes with Esc and, unless it is dismissible={false}, with a click outside; the focus goes back to the button that opened it when that button used open/1. Sizes: :sm 400, :md 520 (default), :lg 720. A tall body scrolls inside the panel, between the header and the footer.

While it is open the DevactionUI.Overlay hook locks the scroll of the page and makes everything around it inert (put data-overlay-keep on what has to stay usable, such as a toast region). Overlays stack: Esc closes only the one on top. The stacking order, from the bottom: a popover in place z-40, a tooltip z-50, a DevactionUI.Drawer z-60, a modal z-70 (so a modal opened from a drawer is over it), a popover with portal z-80; a toast region of the app has to be above that.

The body is whatever goes in the default slot and the actions go in footer:

<Modal.modal id="rename" on_close="close" close_label="Close">
  <:close_icon><.icon name="x" /></:close_icon>
  <:title>Rename the project</:title>
  <:subtitle>The new name shows to the whole team.</:subtitle>
  <input name="name" />
  <:footer><button>Cancel</button><button>Save</button></:footer>
</Modal.modal>

With centered the icon tile, the title and the text sit in the middle and the footer buttons too: the success variant, usually with tone={:ok}.

Summary

Functions

The command that closes: gives the focus back, then runs on_close (an event name or a JS command).

The command for the button that opens a modal: it remembers the focus, then pushes event. Closing puts the focus back there. The same as DevactionUI.Drawer.open/1.

Functions

close(js)

The command that closes: gives the focus back, then runs on_close (an event name or a JS command).

modal(assigns)

Attributes

  • id (:string) (required)
  • size (:atom) - 400, 520 or 720 px wide. Defaults to :md. Must be one of :sm, :md, or :lg.
  • tone (:atom) - the tone of the icon tile. Defaults to :neutral. Must be one of :neutral, :info, :ok, :warn, or :risk.
  • centered (:boolean) - the icon, the title and the text in the middle, for a success. Defaults to false.
  • dismissible (:boolean) - a click outside closes it. Defaults to true.
  • on_close (:any) (required) - an event name or a JS command, run on Esc, the close button and a click outside.
  • close_label (:string) - when given, a close button is drawn in the corner. Defaults to nil.
  • focus (:string) - a selector of what takes the focus when it opens; the first control when left out. Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • icon - the mark in the tile before the title.
  • close_icon
  • title (required)
  • subtitle
  • inner_block - the body, between the header and the footer.
  • footer - the actions, at the end.

open(event_or_js)

The command for the button that opens a modal: it remembers the focus, then pushes event. Closing puts the focus back there. The same as DevactionUI.Drawer.open/1.