defmodule LiveDebuggerWeb.Components.Tree do
@moduledoc """
Tree component which show nested tree of live view and live components.
"""
use LiveDebuggerWeb, :component
alias LiveDebugger.Utils.Parsers
alias LiveDebugger.Structs.TreeNode
@max_node_number 20
@doc """
Tree component which show nested tree of live view and live components.
You need to pass TreeNode struct to render the tree.
This component emits `select_node` event with `node_id` param when a node is clicked. `node_id` is parsed.
To calculate `max_opened_node_level` it uses `max_nesting_level/2` function.
Clicking on the node will emit `select_node` event with params: `node-id`, `search-attribute`, `search-value`.
"""
attr(:id, :string, required: true, doc: "The id of the tree")
attr(:tree_node, :any, required: true, doc: "The TreeNode struct to render")
attr(:title, :string, required: true, doc: "The title of the tree")
attr(:selected_node_id, :string, required: true, doc: "The id of the selected node")
attr(:highlight?, :boolean, default: false, doc: "The highlight flag")
attr(:class, :string, default: nil, doc: "CSS class")
attr(:max_opened_node_level, :integer,
required: true,
doc: "The maximum level of the tree to be opened"
)
def tree(assigns) do
~H"""
<%= @title %>
<%= if LiveDebugger.Feature.enabled?(:highlighting) do %>
<.toggle_switch label="Highlight" checked={@highlight?} phx-click="toggle-highlight" />
<% end %>