LedgerUI.Components.Flow (LedgerUI v0.2.0)

Copy Markdown View Source

Workflow editor: steps on a dotted board joined by connections that carry the condition of each branch, a toolbar at the bottom and the configuration panel of a step on the right.

<.flow id="triage" edges={@edges} on_add="add_node" on_move="move_node" aria-label="Triage" class="h-[640px]">
  <:node id="in" kind="Trigger" kind_icon="mail" icon="mail" title="Invoice received">
    <.flow_section label="Event">An invoice arrives at the inbox.</.flow_section>
  </:node>
  <:node id="gate" kind="Approval" icon="shield" title="Approval" selected />
  <:toolbar><button class="lu-b c-primary v-solid s-md">Add node</button></:toolbar>
  <:panel label="Approval">
    <.flow_panel_head icon="shield" title="Approval" on_close="close_panel" />
    <.flow_panel_body>…fields…</.flow_panel_body>
  </:panel>
</.flow>

Layout

The server lays the steps out (no measuring): edges is a list of maps with from and to (node ids) and optionally label and status ("done" green, "error" red; an edge into the selected node takes the accent). A node's row is its depth along the edges, a parent is centred over its children, and every connection is an SVG path drawn in the gap above its target with the label on it. Without edges the nodes are a free grid, four to a row. Rows are 200px tall plus a gap, so keep a step's card about that size; the LedgerUI.Flow hook redraws the connections from the real node boxes.

Dragging

With on_move the nodes can be dragged on the board (pointer events); a drop pushes %{"id" => id, "x" => x, "y" => y} (to target when given). Keep the positions on the server and pass them back as the x/y of the :node; the connections follow while dragging.

Events: on_add (the + button under nodes with no outgoing edge, phx-value-id of the node), on_move (a node was dragged).

Summary

Functions

flow(assigns)

Attributes

  • id (:string) (required)
  • edges (:list) - Defaults to [].
  • on_add (:any) - Defaults to nil.
  • on_move (:string) - Event pushed when a node is dragged (id, x, y). Defaults to nil.
  • target (:any) - phx-target of on_move. Defaults to nil.
  • add_label (:string) - Defaults to "Add step after".
  • node_width (:integer) - Defaults to 300.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • actions - Buttons beside the selected node; the node id is the slot argument.
  • hint - Accepts attributes:
    • title (:string)
    • left (:integer)
    • top (:integer)
    • width (:integer)
    • class (:string)
  • node (required) - Accepts attributes:
    • id (:string)
    • title (:string)
    • icon (:string)
    • kind (:string)
    • kind_icon (:string)
    • status (:string)
    • selected (:boolean)
    • class (:string)
    • metrics (:list)
    • x (:integer)
    • y (:integer)
  • panel - Accepts attributes:
    • label (:string)
  • toolbar

flow_chip(assigns)

Attributes

  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

flow_chips(assigns)

Attributes

  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

flow_panel_body(assigns)

Attributes

  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

flow_panel_foot(assigns)

Attributes

  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

flow_panel_head(assigns)

Attributes

  • title (:string) (required)
  • icon (:string) - Defaults to nil.
  • on_close (:any) - Defaults to nil.
  • close_label (:string) - Defaults to "Close".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

flow_panel_tabs(assigns)

Attributes

  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

flow_section(assigns)

Attributes

  • label (:string) (required)
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

layout(node_ids, edges, opts \\ [])

@spec layout([String.t()], [map()], keyword()) :: map()

Lays node_ids out along edges.

Returns %{positions: %{id => {x, y}}, width: w, height: h, edges: [...]} where every edge has its SVG path d, the label position {lx, ly}, status, from and to.