DevactionUI.DangerDialog (devaction_ui v0.1.0)

Copy Markdown View Source

The dialog before something that cannot be undone: stop monitoring a repository, delete a project. The red button stays locked until the person types the name of the thing, so it is never a reflex. A click outside does not close it, only Esc, Cancel and the close button do.

The LiveView keeps what was typed (typed) and learns of each keystroke through on_type (a phx-keyup); confirmed?/2 says whether the button is unlocked, and the server checks it again when the event arrives. After it is done the caller can offer to undo with a toast.

Summary

Functions

Whether what was typed is the name of the thing, ignoring the spaces at the ends.

Functions

confirmed?(typed, expected)

@spec confirmed?(String.t() | nil, String.t()) :: boolean()

Whether what was typed is the name of the thing, ignoring the spaces at the ends.

danger_dialog(assigns)

Attributes

  • id (:string) (required)
  • name (:string) (required) - what must be typed: the name of the resource.
  • typed (:string) - what the person has typed so far. Defaults to "".
  • on_type (:string) (required) - the event of phx-keyup on the field.
  • on_confirm (:string) (required) - the event of the red button.
  • on_close (:any) (required) - a JS command or an event name run when it closes.
  • confirm_label (:string) (required) - what the red button does: "Stop monitoring", not "OK".
  • cancel_label (:string) (required)
  • close_label (:string) (required)
  • type_label (:string) (required) - the sentence over the field, with the name drawn in it by the caller.
  • Global attributes are accepted.

Slots

  • icon (required)
  • close_icon (required)
  • title (required)
  • inner_block (required) - what will be lost and what stays.