TermUI.Widgets.AlertDialog (TermUI v0.2.0)

View Source

Alert dialog widget for standardized messages and confirmations.

Alert dialog is a specialized dialog with predefined button configurations and visual icons for different message types.

Usage

AlertDialog.new(
  type: :confirm,
  title: "Delete File",
  message: "Are you sure you want to delete this file?",
  on_result: fn result -> handle_result(result) end
)

Alert Types

  • :info - Information message (i icon, OK button)
  • :success - Success message (✓ icon, OK button)
  • :warning - Warning message (⚠ icon, OK button)
  • :error - Error message (✗ icon, OK button)
  • :confirm - Confirmation dialog (? icon, Yes/No buttons)
  • :ok_cancel - OK/Cancel dialog (OK/Cancel buttons)

Keyboard Navigation

  • Tab/Shift+Tab: Move between buttons
  • Enter/Space: Activate focused button
  • Escape: Close (same as Cancel/No)
  • Y: Yes (in confirm dialogs)
  • N: No (in confirm dialogs)

Summary

Functions

Gets the currently focused button.

Gets the alert type.

Hides the alert.

Creates new AlertDialog widget props.

Updates the message.

Shows the alert.

Gets whether the alert is visible.

Functions

get_focused_button(state)

@spec get_focused_button(map()) :: term()

Gets the currently focused button.

get_type(state)

@spec get_type(map()) :: atom()

Gets the alert type.

hide(state)

@spec hide(map()) :: map()

Hides the alert.

new(opts)

@spec new(keyword()) :: map()

Creates new AlertDialog widget props.

Options

  • :type - Alert type (required): :info, :success, :warning, :error, :confirm, :ok_cancel
  • :title - Dialog title (required)
  • :message - Message to display (required)
  • :on_result - Callback with result (:ok, :cancel, :yes, :no)
  • :width - Dialog width (default: 50)
  • :icon_style - Style for the icon
  • :message_style - Style for the message
  • :button_style - Style for buttons
  • :focused_button_style - Style for focused button

set_message(state, message)

@spec set_message(map(), String.t()) :: map()

Updates the message.

show(state)

@spec show(map()) :: map()

Shows the alert.

visible?(state)

@spec visible?(map()) :: boolean()

Gets whether the alert is visible.