Raxol.UI.Components.Modal (Raxol v2.6.1)

View Source

A modal component for displaying overlay dialogs like alerts, prompts, confirmations, and forms.

Summary

Types

t()

State for the Modal component.

Functions

Creates props for an alert modal.

Wraps flow_content as an :absolute_layer with this modal as a centered, dimmed-backdrop dialog overlay (no-op passthrough when hidden). Prefer this over replacing the flow tree with Modal.render(state, %{}), which reflows background content.

Initializes the Modal component state from props.

Mount hook - called when component is mounted. No special setup needed for Modal.

Unmount hook - called when component is unmounted. No cleanup needed for Modal.

Updates the Modal component state in response to messages. Handles show/hide, button clicks, and form updates.

Types

t()

@type t() :: %Raxol.UI.Components.Modal{
  buttons: list(),
  content: any(),
  form_state: map(),
  id: any(),
  style: map(),
  title: String.t(),
  type: atom(),
  visible: boolean(),
  width: non_neg_integer()
}

State for the Modal component.

  • :id - unique identifier
  • :visible - whether the modal is visible
  • :title - modal title
  • :content - modal content (text or view elements)
  • :buttons - list of {label, message} tuples
  • :type - modal type (:alert, :confirm, :prompt, :form)
  • :width - modal width
  • :style - style map
  • :form_state - state for prompt/form fields

Functions

alert(id, title, content, opts \\ [])

Creates props for an alert modal.

as_dialog_overlay(state, flow_content)

@spec as_dialog_overlay(t(), map()) :: map()

Wraps flow_content as an :absolute_layer with this modal as a centered, dimmed-backdrop dialog overlay (no-op passthrough when hidden). Prefer this over replacing the flow tree with Modal.render(state, %{}), which reflows background content.

broadcast(msg)

command(cmd)

confirm(id, title, content, on_confirm \\ :confirm, on_cancel \\ :cancel, opts \\ [])

Creates props for a confirmation modal.

form(id, title, fields, on_submit \\ :submit, on_cancel \\ :cancel, opts \\ [])

Creates props for a form modal.

fields should be a list of maps, each defining a form field: %{id: :atom, type: :text_input | :checkbox | :dropdown, label: "string", value: initial_value, props: keyword_list, options: list, validate: regex | function} (options only for dropdown)

init(props)

Initializes the Modal component state from props.

mount(state)

Mount hook - called when component is mounted. No special setup needed for Modal.

prompt(id, title, content, on_submit \\ :submit, on_cancel \\ :cancel, opts \\ [])

Creates props for a prompt modal.

schedule(msg, delay)

unmount(state)

Unmount hook - called when component is unmounted. No cleanup needed for Modal.

update(props, state)

Updates the Modal component state in response to messages. Handles show/hide, button clicks, and form updates.