Raxol.UI.Components.Modal (Raxol v2.0.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.

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 \\ [])

@spec alert(any(), any(), any(), Keyword.t()) :: map()

Creates props for an alert modal.

broadcast(msg)

command(cmd)

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

@spec confirm(any(), any(), any(), any(), any(), Keyword.t()) :: map()

Creates props for a confirmation modal.

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

@spec form(any(), any(), list(), any(), any(), Keyword.t()) :: map()

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)

@spec init(map()) :: map()

Initializes the Modal component state from props.

mount(state)

@spec mount(map()) :: {map(), list()}

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

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

@spec prompt(any(), any(), any(), any(), any(), Keyword.t()) :: map()

Creates props for a prompt modal.

schedule(msg, delay)

unmount(state)

@spec unmount(map()) :: map()

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

update(msg, state)

@spec update(term(), map()) :: {map(), list()}

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