defmodule <%= @module_name %>.Components.UI.Command do
@moduledoc """
Command palette component with PhiaCommand vanilla JS hook.
Ejected from PhiaUI — you own this copy. Customise freely.
## Example
<.command id="global-cmd">
<.command_input id="global-cmd-input" on_change="search" />
<.command_list id="global-cmd-list">
<%= if @results == [] do %>
<.command_empty>No results found.
<% else %>
<.command_group label="Pages">
<.command_item :for={item <- @results} on_click="navigate" value={item.path}>
<%= item.label %>
<% end %>
## Hook setup
import PhiaCommand from "./hooks/command"
let liveSocket = new LiveSocket("/live", Socket, {
hooks: { PhiaCommand }
})
"""
use Phoenix.Component
import <%= @module_name %>.ClassMerger, only: [cn: 1]
attr :id, :string, required: true
attr :class, :string, default: nil
attr :rest, :global
slot :inner_block, required: true
def command(assigns) do
~H"""
<%%= render_slot(@inner_block) %>
"""
end
attr :id, :string, required: true
attr :placeholder, :string, default: "Type a command or search..."
attr :on_change, :string, required: true
attr :class, :string, default: nil
attr :rest, :global
def command_input(assigns) do
~H"""
"""
end
attr :id, :string, required: true
attr :class, :string, default: nil
attr :rest, :global
slot :inner_block, required: true
def command_list(assigns) do
~H"""
<%%= render_slot(@inner_block) %>
"""
end
attr :class, :string, default: nil
attr :rest, :global
slot :inner_block, required: true
def command_empty(assigns) do
~H"""
<%%= render_slot(@inner_block) %>
"""
end
attr :label, :string, required: true
attr :class, :string, default: nil
attr :rest, :global
slot :inner_block, required: true
def command_group(assigns) do
~H"""
<%%= @label %>
<%%= render_slot(@inner_block) %>
"""
end
attr :on_click, :string, required: true
attr :value, :string, required: true
attr :class, :string, default: nil
attr :rest, :global
slot :inner_block, required: true
def command_item(assigns) do
~H"""
<%%= render_slot(@inner_block) %>
"""
end
attr :class, :string, default: nil
attr :rest, :global
def command_separator(assigns) do
~H"""
"""
end
attr :class, :string, default: nil
attr :rest, :global
slot :inner_block, required: true
def command_shortcut(assigns) do
~H"""
<%%= render_slot(@inner_block) %>
"""
end
end