Corex.Tree.Item (Corex v0.1.0-beta.5)

View Source

Tree item structure.

Use it to create hierarchical/nested structures for:

Fields

  • :value - (optional) Unique node value, auto-generated if not provided
  • :label - (required) Display text
  • :to - (optional) Destination (path or URL) used by navigation components
  • :children - (optional) Nested items (list of maps)
  • :disabled - (optional) Whether the item is disabled
  • :group - (optional) Group identifier for grouping items
  • :meta - (optional) Additional metadata for the item
  • :redirect - (optional) Per-item navigation mode: :href (default, full page redirect), :patch (LiveView js().patch, same mount), :navigate (LiveView js().navigate, another mount in the same live_session), or false to disable redirect for this item. The hook never inspects the URL to guess the mode; it only executes what is declared here.
  • :new_tab - (optional) Open the item's destination in a new tab via window.open (mode is ignored when true)

Examples

Corex.Tree.Item.new(%{label: "File", children: [%{label: "New"}, %{label: "Open"}]})

Summary

Functions

Creates a single Tree.Item from a map, auto-generating a :value if not provided and recursively processing :children.

Types

t()

@type t() :: %Corex.Tree.Item{
  children: [t()],
  disabled: boolean(),
  group: String.t() | nil,
  label: String.t(),
  meta: map(),
  new_tab: boolean(),
  redirect: :href | :patch | :navigate | false | nil,
  to: String.t() | nil,
  value: String.t()
}

Functions

new(item)

@spec new(map()) :: t()

Creates a single Tree.Item from a map, auto-generating a :value if not provided and recursively processing :children.

Map keys must not include :id; use :value for node identity.

Raises ArgumentError if attrs is not a map or is missing required fields, or if a child is neither a map nor a Tree.Item struct.