defmodule <%= @module %> do @moduledoc """ The `<%= @module %>` module is designed to render a hierarchical menu structure in Phoenix LiveView applications. It provides a versatile menu component capable of handling both simple and complex navigation systems with nested sub-menus. This module supports dynamic configuration of menu items through a list of maps, allowing for a wide range of customization options. Menu items can be rendered as standalone buttons or as expandable accordions containing nested sub-menus. The `MishkaChelekom.Menu` is ideal for creating multi-level navigation menus in applications with complex information architectures. The component integrates smoothly with other components from the `MishkaChelekom` library, such as `accordion` and `button_link`, to offer a consistent and cohesive UI experience. It also includes support for various padding and spacing options to control the layout and appearance of the menu. """ use Phoenix.Component import <%= inspect(@web_module) %>.Components.Accordion, only: [accordion: 1] import <%= inspect(@web_module) %>.Components.Button, only: [button_link: 1] @doc """ Renders a customizable `menu` component that can include menu items as a list of maps or use additional slots to define nested content. It supports both direct menu items and nested accordion submenus. ## Examples ```elixir <.menu>
  • <.button_link navigate="/" size="extra_small" color="misc" variant="unbordered" rounded="large" class="w-full" display="flex" icon_class="size-5" icon="hero-home" font_weight="font-bold" > Dashboard
  • <.button_link size="extra_small" color="misc" variant="unbordered" rounded="large" class="w-full" display="flex" navigate="/examples/footer" icon_class="size-5" icon="hero-server" > Footer
  • <.accordion padding="none" id="accordion1" size="extra_small" rounded="large" color="misc" variant="menu" > <:item title="Menu item" icon_class="size-5" icon="hero-bookmark">
  • <.button_link navigate="/examples/modal" size="extra_small" color="misc" variant="unbordered" rounded="large" class="w-full" display="flex" icon_class="size-5" icon="hero-bell" > Modal
  • <.button_link navigate="/examples/list" size="extra_small" color="misc" variant="unbordered" rounded="large" class="w-full" display="flex" icon_class="size-5" icon="hero-cake" > List
  • ``` ### It can be used as list of map ```elixir list_menues = [ %{ id: "Dashaboard", navigate: "/", title: "Dashaboard", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-home", active: true }, %{ id: "Footer", navigate: "/examples/footer", title: "Footer", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-server" }, %{ id: "Menu-item", title: "Menu item", padding: "pl-5 space-y-3 mt-3", size: "extra_small", rounded: "large", color: "misc", variant: "menu", icon: "hero-bookmark", icon_class: "size-5", sub_items: [ %{ navigate: "/examples/indicator", title: "Indicator", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-scissors" }, %{ navigate: "/examples/image", title: "Image", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-scale" }, %{ navigate: "/examples/rating", title: "Rating", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-building-storefront" }, %{ id: "Invoice", title: "Invoice", variant: "menu", padding: "pl-5 space-y-3 mt-3", size: "extra_small", rounded: "large", color: "misc", icon: "hero-bookmark", icon_class: "size-5", sub_items: [ %{ navigate: "/examples/popover", title: "Popover", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-bolt" }, %{ navigate: "/examples/overlay", title: "Overlay", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-shopping-bag" } ] } ] }, %{ navigate: "/examples/modal", title: "Modal", size: "extra_small", color: "misc", variant: "unbordered", rounded: "large", class: "w-full", display: "flex", icon_class: "size-5", icon: "hero-bell" } ] <.menu menu_items={@list_menues} /> ``` """ @doc type: :component attr :id, :string, default: nil, doc: "A unique identifier is used to manage state and interaction" attr :class, :string, default: nil, doc: "Custom CSS class for additional styling" attr :menu_items, :list, default: [], doc: "Determines menu items as a list of maps" attr :space, :string, default: "small", doc: "Space between items" attr :padding, :string, default: "small", doc: "Determines padding for items" slot :inner_block, doc: "Global attributes can define defaults which are merged with attributes provided by the caller" attr :rest, :global, doc: "Global attributes can define defaults which are merged with attributes provided by the caller" def menu(assigns) do ~H""" """ end <%= if is_nil(@padding) or "extra_small" in @padding do %> defp padding_size("extra_small"), do: "p-2" <% end %> <%= if is_nil(@padding) or "small" in @padding do %> defp padding_size("small"), do: "p-2.5" <% end %> <%= if is_nil(@padding) or "medium" in @padding do %> defp padding_size("medium"), do: "p-3" <% end %> <%= if is_nil(@padding) or "large" in @padding do %> defp padding_size("large"), do: "p-3.5" <% end %> <%= if is_nil(@padding) or "extra_large" in @padding do %> defp padding_size("extra_large"), do: "p-4" <% end %> <%= if is_nil(@padding) or "none" in @padding do %> defp padding_size("none"), do: "p-0" <% end %> defp padding_size(params) when is_binary(params), do: params <%= if is_nil(@space) or "none" in @space do %> defp space_class("none"), do: nil <% end %> <%= if is_nil(@space) or "extra_small" in @space do %> defp space_class("extra_small"), do: "space-y-2" <% end %> <%= if is_nil(@space) or "small" in @space do %> defp space_class("small"), do: "space-y-3" <% end %> <%= if is_nil(@space) or "medium" in @space do %> defp space_class("medium"), do: "space-y-4" <% end %> <%= if is_nil(@space) or "large" in @space do %> defp space_class("large"), do: "space-y-5" <% end %> <%= if is_nil(@space) or "extra_large" in @space do %> defp space_class("extra_large"), do: "space-y-6" <% end %> defp space_class(params) when is_binary(params), do: params end