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

View Source

Tree items for hierarchical/nested structures to be used with:

Use Corex.Tree.new/1 to build a list of items from a list of maps.

Summary

Functions

Creates a list of Tree.Item structs from a list of maps. Recursively processes :children if present.

Functions

new(items)

@spec new([map()]) :: [Corex.Tree.Item.t()]

Creates a list of Tree.Item structs from a list of maps. Recursively processes :children if present.

Fields

  • :label - (required) Display text
  • :value - (optional) Unique node value, auto-generated if not provided
  • :to - (optional) Destination (path or URL)
  • :children - (optional) Nested items (list of maps)
  • :disabled - (optional) Whether the item is disabled
  • :group - (optional) Group identifier
  • :meta - (optional) Additional metadata
  • :redirect - (optional) :href | :patch | :navigate | false

  • :new_tab - (optional) Open the destination in a new tab

Examples

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

Raises ArgumentError if items is not a list of maps.