TermUI.Widgets.ToastManager (TermUI v0.2.0)

View Source

Manages multiple toast notifications with stacking.

ToastManager handles the lifecycle of multiple toasts, including stacking, auto-dismiss, and position management.

Usage

# Create manager
{:ok, manager} = ToastManager.init(%{position: :bottom_right})

# Add toasts
manager = ToastManager.add_toast(manager, "File saved", :success)
manager = ToastManager.add_toast(manager, "Warning: Low disk space", :warning)

# Update (check auto-dismiss)
manager = ToastManager.tick(manager)

Summary

Functions

Clears all toasts.

Gets all visible toasts.

Creates a new ToastManager.

Renders all toasts with stacking.

Updates the manager, removing dismissed toasts.

Gets the count of visible toasts.

Functions

add_toast(manager, message, type \\ :info, opts \\ [])

@spec add_toast(map(), String.t(), atom(), keyword()) :: map()

Adds a new toast to the manager.

clear_all(manager)

@spec clear_all(map()) :: map()

Clears all toasts.

get_toasts(manager)

@spec get_toasts(map()) :: [map()]

Gets all visible toasts.

new(opts \\ [])

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

Creates a new ToastManager.

render(manager, area)

@spec render(map(), map()) :: term()

Renders all toasts with stacking.

Returns a list of overlay nodes that should be rendered. Each toast is an overlay with absolute positioning.

tick(manager)

@spec tick(map()) :: map()

Updates the manager, removing dismissed toasts.

toast_count(manager)

@spec toast_count(map()) :: non_neg_integer()

Gets the count of visible toasts.