defmodule RiverConnectWeb.Components.UI.Command do @moduledoc """ Command palette components for RiverConnectWeb.Components.UI. Provides a set of components to build a command palette or searchable menu, similar to those found in modern applications. ## Example <.command id="command" class="rounded-lg border shadow-md md:min-w-[450px] w-full lg:max-w-[600px]"> <.command_input placeholder="Type a command or search..." /> <.command_empty> No results found <.command_list> <.command_group heading="Suggestions"> <.command_item phx-value-name="calendar" phx-click="select_command"> <.calendar class="w-4 h-4"/> Calendar ... <.command_group heading="Settings"> <.command_item phx-value-name="profile" phx-click="select_command"> <.user class="w-4 h-4"/> Profile <.command_shortcut>⌘P ... """ use RiverConnectWeb.Components.UI, :component import RiverConnectWeb.Components.UI.Dialog import RiverConnectWeb.Components.UI.Icon @doc """ Renders the root command palette container. ## Attributes * `:id` (required) - The unique id for the command palette. * `:class` - Additional classes to apply. ## Slots * `:inner_block` (required) - The content of the command palette. ## Example <.command id="my-command"> ... """ attr :id, :string, required: true attr :class, :any, default: "" slot :inner_block, required: true def command(assigns) do ~H"""
{render_slot(@inner_block)}
""" end @doc """ Renders a command palette inside a dialog. ## Attributes * `:id` (required) - The unique id for the command palette. * `:open` - Whether the dialog is open. ## Slots * `:inner_block` (required) - The content of the command palette. ## Example <.command_dialog id="my-command" open={@show_command}> ... """ attr :id, :string, required: true attr :open, :boolean, default: false slot :inner_block, required: true def command_dialog(assigns) do ~H""" <.dialog id={@id <> "_dialog"} open={@open}> <.dialog_content class="overflow-hidden p-0"> <.command id={@id} class="[&_[data-part='input']]:h-12"> {render_slot(@inner_block)} """ end @doc """ Renders the input field for searching/filtering commands. ## Attributes * `:class` - Additional classes to apply. * All global attributes are passed to the `` element. ## Example <.command_input placeholder="Type a command..." /> """ attr :class, :any, default: "" attr :rest, :global, default: %{} def command_input(assigns) do ~H"""
<.icon name="hero-magnifying-glass" />
""" end @doc """ Renders the list container for command items and groups. ## Attributes * `:class` - Additional classes to apply. ## Slots * `:inner_block` (required) - The content of the command list (groups/items). ## Example <.command_list> <.command_group heading="Actions"> <.command_item>... """ attr :class, :any, default: "" slot :inner_block, required: true def command_list(assigns) do ~H"""
{render_slot(@inner_block)}
""" end @doc """ Renders a message when no command results are found. ## Attributes * `:class` - Additional classes to apply. ## Slots * `:inner_block` (required) - The content to display when empty. ## Example <.command_empty> No results found """ attr :class, :any, default: "" slot :inner_block, required: true def command_empty(assigns) do ~H"""
{render_slot(@inner_block)}
""" end @doc """ Renders a group of command items with a heading. ## Attributes * `:heading` (required) - The group heading. ## Slots * `:inner_block` (required) - The command items in the group. ## Example <.command_group heading="Settings"> <.command_item>Profile """ attr :heading, :string, required: true slot :inner_block, required: true def command_group(assigns) do ~H""" """ end @doc """ Renders a single command item (button). ## Attributes * `:disabled` - Whether the item is disabled. * `:selected` - Whether the item is selected. * All global attributes are passed to the ` """ end @doc """ Renders a keyboard shortcut hint for a command item. ## Attributes * `:class` - Additional classes to apply. ## Slots * `:inner_block` (required) - The shortcut text. ## Example <.command_shortcut>⌘P """ attr :class, :any, default: "" slot :inner_block, required: true def command_shortcut(assigns) do ~H""" {render_slot(@inner_block)} """ end end