"""
end
@doc """
Renders a simple form.
## Examples
<.simple_form for={@form} phx-change="validate" phx-submit="save">
<.input field={@form[:email]} label="Email"/>
<.input field={@form[:username]} label="Username" />
<:actions>
<.button>Save
"""
attr :for, :any, required: true, doc: "the datastructure for the form"
attr :as, :any, default: nil, doc: "the server side parameter to collect all input under"
attr :rest, :global,
include: ~w(autocomplete name rel action enctype method novalidate target),
doc: "the arbitrary HTML attributes to apply to the form tag"
slot :inner_block, required: true
slot :actions, doc: "the slot for form actions, such as a submit button"
def simple_form(assigns) do
~H"""
<.form :let={f} for={@for} as={@as} {@rest}>
<%= render_slot(@inner_block, f) %>
<%= render_slot(action, f) %>
"""
end
@doc ~S"""
Renders a table with generic styling.
## Examples
<.table id="users" rows={@users}>
<:col :let={user} label="id"><%= user.id %>
<:col :let={user} label="username"><%= user.username %>
"""
attr :id, :string, required: true
attr :rows, :list, required: true
attr :row_id, :any, default: nil, doc: "the function for generating the row id"
attr :row_click, :any, default: nil, doc: "the function for handling phx-click on each row"
attr :row_item, :any,
default: &Function.identity/1,
doc: "the function for mapping each row before calling the :col and :action slots"
slot :col, required: true do
attr :label, :string
end
slot :action, doc: "the slot for showing user actions in the last table column"
def table(assigns) do
assigns =
with %{rows: %Phoenix.LiveView.LiveStream{}} <- assigns do
assign(assigns, row_id: assigns.row_id || fn {id, _item} -> id end)
end
~H"""
<%= col[:label] %>
<%= gettext("Actions") %>
<%= render_slot(col, @row_item.(row)) %>
<%= render_slot(action, @row_item.(row)) %>
"""
end
@doc """
Renders a data list.
## Examples
<.list>
<:item title="Title"><%= @post.title %>
<:item title="Views"><%= @post.views %>
"""
slot :item, required: true do
attr :title, :string, required: true
end
def list(assigns) do
~H"""
<%= item.title %>
<%= render_slot(item) %>
"""
end
@doc """
Renders a back navigation link.
## Examples
<.back navigate={~p"/posts"}>Back to posts
"""
attr :navigate, :any, required: true
slot :inner_block, required: true
def back(assigns) do
~H"""
"""
end
@doc """
Renders a rounded white panel that is pinned to the bottom of the screen and scrolls.
"""
slot :inner_block, required: true
attr :class, :string, default: ""
def main_content(assigns) do
~H"""
<%= render_slot(@inner_block) %>
"""
end
@doc """
Renders a search input text to filter table results.
"""
attr :table, Beacon.LiveAdmin.PageBuilder.Table, required: true
attr :placeholder, :string
def table_search(assigns) do
~H"""
<.simple_form :let={f} for={%{}} as={:search} phx-change="beacon:table-search">
<.input type="search" field={f[:query]} value={@table.query} autofocus={true} placeholder={@placeholder || "Search"} phx-debounce={200} />
"""
end
@doc """
Renders a select input to sort table results.
"""
attr :table, Beacon.LiveAdmin.PageBuilder.Table, required: true
attr :options, :list, required: true
def table_sort(assigns) do
~H"""
<.simple_form :let={f} for={%{}} as={:sort} phx-change="beacon:table-sort">