diff --git a/lib/components_elixir_web/live/categories_live.ex b/lib/components_elixir_web/live/categories_live.ex index fa402d5..c3cdcec 100644 --- a/lib/components_elixir_web/live/categories_live.ex +++ b/lib/components_elixir_web/live/categories_live.ex @@ -159,6 +159,77 @@ defmodule ComponentsElixirWeb.CategoriesLive do Inventory.count_components_in_category(category_id) end + # Component for rendering individual category items + defp category_item(assigns) do + # Calculate margin based on depth (0 = no margin, 1+ = incremental margin) + margin_left = if assigns.depth == 0, do: 0, else: 32 + assigns.depth * 16 + + # Determine border style based on depth + border_class = if assigns.depth > 0, do: "border-l-2 border-gray-200 pl-6", else: "" + + # Icon size and button size based on depth + {icon_size, button_size, text_size, title_tag} = case assigns.depth do + 0 -> {"w-5 h-5", "p-2", "text-lg", "h3"} + 1 -> {"w-4 h-4", "p-1.5", "text-base", "h4"} + _ -> {"w-3 h-3", "p-1", "text-sm", "h5"} + end + + assigns = assigns + |> assign(:margin_left, margin_left) + |> assign(:border_class, border_class) + |> assign(:icon_size, icon_size) + |> assign(:button_size, button_size) + |> assign(:text_size, text_size) + |> assign(:title_tag, title_tag) + |> assign(:children, child_categories(assigns.categories, assigns.category.id)) + + ~H""" +
0 && "mt-4"]} style={"margin-left: #{@margin_left}px"}> +
+
+
+ <.icon name="hero-folder" class={"#{@icon_size} #{if @depth == 0, do: "text-indigo-500", else: "text-gray-400"} mr-3"} /> +
+ <%= if @title_tag == "h3" do %> +

{@category.name}

+ <% else %> +

{@category.name}

+ <% end %> + <%= if @category.description do %> +

{@category.description}

+ <% end %> +

+ {count_components_in_category(@category.id)} components +

+
+
+
+
+ + +
+
+ + <%= for child <- @children do %> + <.category_item category={child} categories={@categories} depth={@depth + 1} /> + <% end %> +
+ """ + end + @impl true def render(assigns) do ~H""" @@ -334,83 +405,14 @@ defmodule ComponentsElixirWeb.CategoriesLive do <% else %> - + <% end %>