defmodule OutlookWeb.HtmlTreeComponent do
use Phoenix.Component
# use OutlookWeb, :html
import OutlookWeb.CoreComponents
alias Phoenix.LiveView.JS
attr :tree, :list, required: true
def render_tree(assigns) do
~H"""
<.tnode :for={node <- @tree} node={node} />
"""
end
def attributes(assigns) do
~H" <%= @name %>="<%= @value %>""
end
def tnode(%{node: %{status: _}} = assigns), do: ~H"<%= String.slice(@node.content, 0..20) %><%= if String.length(@node.content) > 20 do %>...<% end %>
"
def tnode(assigns) when assigns.node.type == :element do
~H"""
<<%= @node.name %><.attributes :for={{k,v} <- @node.attributes} name={k} value={v}
/>>