Raxol.UI.Components.Display.Tree (Raxol v2.6.0)

View Source

A tree view component with expand/collapse and keyboard navigation.

Displays hierarchical data as an indented tree. Nodes can be expanded and collapsed. The cursor tracks the currently selected visible node.

Node data format:

%{id: atom, label: string, children: [node], data: any}

Keyboard bindings:

  • Up/Down: move cursor through visible nodes
  • Right: expand collapsed node (if it has children)
  • Left: collapse expanded node, or move to parent
  • Enter/Space: toggle expand/collapse; fire on_select for leaf nodes
  • Home/End: jump to first/last visible node

Summary

Functions

Recursively searches for a node by id in the tree.

Finds the parent of a node by id. Returns nil if the node is a root or not found.

Returns a flat list of {node, depth} tuples for all currently visible nodes, respecting the expanded set. Children of collapsed nodes are omitted.

Types

t()

@type t() :: %{
  id: String.t() | atom(),
  nodes: [tree_node()],
  expanded: MapSet.t(),
  cursor: atom() | nil,
  focused: boolean(),
  indent_size: non_neg_integer(),
  on_select: (atom(), any() -> any()) | nil,
  on_expand: (atom() -> any()) | nil,
  on_collapse: (atom() -> any()) | nil,
  style: map(),
  theme: map()
}

tree_node()

@type tree_node() :: %{
  id: atom(),
  label: String.t(),
  children: [tree_node()],
  data: any()
}

Functions

broadcast(msg)

command(cmd)

find_node(list, id)

@spec find_node([tree_node()], atom()) :: tree_node() | nil

Recursively searches for a node by id in the tree.

find_parent(nodes, id)

@spec find_parent([tree_node()], atom()) :: tree_node() | nil

Finds the parent of a node by id. Returns nil if the node is a root or not found.

mount(state)

Callback implementation for Raxol.UI.Components.Base.Component.mount/1.

schedule(msg, delay)

unmount(state)

Callback implementation for Raxol.UI.Components.Base.Component.unmount/1.

update(props, state)

Callback implementation for Raxol.UI.Components.Base.Component.update/2.

visible_nodes(map)

@spec visible_nodes(t()) :: [{tree_node(), non_neg_integer()}]

Returns a flat list of {node, depth} tuples for all currently visible nodes, respecting the expanded set. Children of collapsed nodes are omitted.