Fluxon (Fluxon v2.4.0-rc.2)

To use Fluxon components in your LiveView or View modules, add the following to your module:

use Fluxon

This will import all available components. You can customize which components to import using the following options:

  • :only - List of components to import. Only the specified components will be imported.

    use Fluxon, only: [:button, :input, :modal]
  • :except - List of components to exclude. All components except the specified ones will be imported.

    use Fluxon, except: [:table, :tabs]

Summary

Functions

Closes a dialog component (modal, sheet).

Closes a dialog via push event.

Closes a popover component.

Programmatically dismisses a toast by ID.

Opens a dialog component (modal, sheet).

Opens a dialog via push event.

Opens a popover component.

Shows a toast notification.

Shows a loading toast and returns the socket and toast ID for later resolution.

Resolves a loading toast with a new color and title.

Functions

close_dialog(id)

Closes a dialog component (modal, sheet).

Parameters

  • id - The ID of the dialog element to close.

Example

<.button phx-click={Fluxon.close_dialog("my-modal")}>Close modal</.button>
<.modal id="my-modal"></.modal>

close_dialog(socket, id)

Closes a dialog via push event.

Parameters

Example

def handle_event("close_dialog", _, socket) do
  {:noreply, Fluxon.close_dialog(socket, "my-dialog")}
end

close_popover(js \\ %JS{}, id)

Closes a popover component.

Parameters

  • id - The ID of the popover element to close.

Example

<.button phx-click={Fluxon.close_popover("my-popover")}>Close popover</.button>
<.popover id="my-popover"></.popover>

dismiss_toast(socket, toast_id)

Programmatically dismisses a toast by ID.

Example

socket = Fluxon.dismiss_toast(socket, toast_id)

open_dialog(id)

Opens a dialog component (modal, sheet).

Example

<.button phx-click={Fluxon.open_dialog("my-modal")}>Open modal</.button>
<.modal id="my-modal"></.modal>

open_dialog(socket, id)

Opens a dialog via push event.

Parameters

Example

def handle_event("open_dialog", _, socket) do
  {:noreply, Fluxon.open_dialog(socket, "my-dialog")}
end

open_popover(js \\ %JS{}, id)

Opens a popover component.

Example

<.button phx-click={Fluxon.open_popover("my-popover")}>Open popover</.button>
<.popover id="my-popover"></.popover>

put_toast(socket_or_conn, title, opts \\ [])

Shows a toast notification.

Works with both Phoenix.LiveView.Socket (via push_event) and Plug.Conn (via response cookie). When using Plug.Conn, the :content option is silently dropped since cookies cannot safely transport HTML.

Options

  • :color - :info | :success | :warning | :error or nil for neutral (default nil)

  • :description - secondary text below title
  • :content - custom HEEx (~H"...") or HTML string (LiveView only)
  • :icon - false to hide icon, or custom HEEx/HTML (LiveView only). Default uses color-based icon.
  • :duration - auto-dismiss ms (default 4000, nil for persistent)
  • :dismissible - boolean (default true)
  • :action - single action map (shorthand for :actions with one item)
  • :actions - list of action maps. Each map supports:
    • label (required) - button/link text
    • event - LiveView event name (makes it a button)
    • href - URL (makes it a link)
    • value - map payload sent with the event (default %{})
    • variant - "outline" | "solid" | "soft" | "surface" | "ghost" | "link" (default "outline")

  • :id - custom ID (auto-generated if omitted)

Examples

# From a LiveView handler
Fluxon.put_toast(socket, "Changes saved!")
Fluxon.put_toast(socket, "User created", color: :success, description: "Email sent.")

# Single action (shorthand)
Fluxon.put_toast(socket, "Deleted", action: %{label: "Undo", event: "undo"})

# Multiple actions
Fluxon.put_toast(socket, "Deploy failed",
  color: :error,
  actions: [
    %{label: "Retry", event: "retry_deploy"},
    %{label: "View Logs", href: "/logs/123", variant: "link"}
  ])

# From a controller
Fluxon.put_toast(conn, "Welcome back!", color: :info)

# With custom content (LiveView only)
Fluxon.put_toast(socket, "New follower",
  content: ~H"""
  <div class="flex items-center gap-2">
    <img src={@user.avatar} class="size-6 rounded-full" />
    <span>{@user.name} started following you</span>
  </div>
  """)

put_toast_loading(socket, title, opts \\ [])

Shows a loading toast and returns the socket and toast ID for later resolution.

Example

{socket, toast_id} = Fluxon.put_toast_loading(socket, "Uploading...")
# Later, in another handler:
socket = Fluxon.resolve_toast(socket, toast_id, :success, "Upload complete!")

resolve_toast(socket, toast_id, color, title, opts \\ [])

Resolves a loading toast with a new color and title.

Example

socket = Fluxon.resolve_toast(socket, toast_id, :success, "Upload complete!")
socket = Fluxon.resolve_toast(socket, toast_id, :error, "Upload failed!", description: "Try again.")