Current section
Files
Jump to
Current section
Files
lib/beacon/live_admin/components/admin_components.ex
defmodule Beacon.LiveAdmin.AdminComponents do
@moduledoc """
Provides Admin UI components.
This file contains new components and also overrided Core components.
"""
use Phoenix.Component
alias Phoenix.LiveView.JS
alias Beacon.LiveAdmin.CoreComponents
alias Beacon.LiveAdmin.PageBuilder.Table
use Gettext, backend: Beacon.LiveAdmin.Gettext
import Beacon.LiveAdmin.Router, only: [beacon_live_admin_path: 3]
defdelegate header(assigns), to: CoreComponents
defdelegate icon(assigns), to: CoreComponents
defdelegate show_modal(assigns), to: CoreComponents
defdelegate hide_modal(assigns), to: CoreComponents
defdelegate show(selector), to: CoreComponents
defdelegate show(js, selector), to: CoreComponents
defdelegate hide(selector), to: CoreComponents
defdelegate hide(js, selector), to: CoreComponents
defdelegate translate_error(error), to: CoreComponents
defdelegate translate_errors(errors, field), to: CoreComponents
@menu_link_active_class "inline-block p-4 text-blue-600 border-b-2 border-blue-600 rounded-t-lg active"
@menu_link_regular_class "inline-block p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300"
@doc false
attr :socket, :map
attr :flash, :map
attr :beacon_layout, :map
attr :live_action, :atom
def layout_header(assigns) do
~H"""
<.flash_group flash={@flash} />
<Beacon.LiveAdmin.AdminComponents.layout_menu socket={@socket} site={@beacon_layout.site} current_action={@live_action} layout_id={@beacon_layout.id} />
"""
end
@doc false
attr :socket, :map
attr :site, :atom
attr :current_action, :atom
attr :layout_id, :string
def layout_menu(assigns) do
assigns =
assign(assigns,
active_class: @menu_link_active_class,
regular_class: @menu_link_regular_class
)
~H"""
<div class="mb-10 text-sm font-medium text-center text-gray-500 border-b border-gray-200">
<ul class="flex flex-wrap -mb-px">
{layout_menu_items(assigns)}
</ul>
</div>
"""
end
defp layout_menu_items(%{current_action: :new} = assigns) do
~H"""
<li class="mr-2"><.link patch={beacon_live_admin_path(@socket, @site, "/layouts/#{@layout_id}")} class={@active_class}>Layout</.link></li>
"""
end
defp layout_menu_items(assigns) do
~H"""
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/layouts/#{@layout_id}")} class={if(@current_action == :edit, do: @active_class, else: @regular_class)}>Layout</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/layouts/#{@layout_id}/meta_tags")} class={if(@current_action == :meta_tags, do: @active_class, else: @regular_class)}>Meta Tags</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/layouts/#{@layout_id}/resource_links")} class={if(@current_action == :resource_links, do: @active_class, else: @regular_class)}>
Resource Links
</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/layouts/#{@layout_id}/revisions")} class={if(@current_action == :revisions, do: @active_class, else: @regular_class)}>Revisions</.link>
</li>
"""
end
@doc false
attr :socket, :map
attr :flash, :map
attr :page, :any
attr :live_action, :atom
def page_header(assigns) do
~H"""
<.flash_group flash={@flash} />
<Beacon.LiveAdmin.AdminComponents.page_menu socket={@socket} site={@page.site} current_action={@live_action} page_id={@page.id} />
"""
end
@doc false
attr :socket, :map
attr :site, :atom
attr :current_action, :atom
attr :page_id, :string
def page_menu(assigns) do
assigns =
assign(assigns,
active_class: @menu_link_active_class,
regular_class: @menu_link_regular_class
)
~H"""
<div class="mb-10 text-sm font-medium text-center text-gray-500 border-b border-gray-200">
<ul class="flex flex-wrap -mb-px">
{page_menu_items(assigns)}
</ul>
</div>
"""
end
defp page_menu_items(%{current_action: :new} = assigns) do
~H"""
<li class="mr-2"><.link patch={beacon_live_admin_path(@socket, @site, "/pages/#{@page_id}")} class={@active_class}>Page</.link></li>
"""
end
defp page_menu_items(assigns) do
~H"""
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/pages/#{@page_id}")} class={if(@current_action == :edit, do: @active_class, else: @regular_class)}>Page</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/pages/#{@page_id}/meta_tags")} class={if(@current_action == :meta_tags, do: @active_class, else: @regular_class)}>Meta Tags</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/pages/#{@page_id}/schema")} class={if(@current_action == :schema, do: @active_class, else: @regular_class)}>Schema</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/pages/#{@page_id}/variants")} class={if(@current_action == :variants, do: @active_class, else: @regular_class)}>Variants</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/pages/#{@page_id}/revisions")} class={if(@current_action == :revisions, do: @active_class, else: @regular_class)}>Revisions</.link>
</li>
"""
end
@doc false
attr :socket, :map
attr :flash, :map
attr :component, :any
attr :live_action, :atom
def component_header(assigns) do
~H"""
<.flash_group flash={@flash} />
<Beacon.LiveAdmin.AdminComponents.component_menu socket={@socket} site={@component.site} current_action={@live_action} component_id={@component.id} />
"""
end
@doc false
attr :socket, :map
attr :site, :atom
attr :current_action, :atom
attr :component_id, :string
def component_menu(assigns) do
assigns =
assign(assigns,
active_class: @menu_link_active_class,
regular_class: @menu_link_regular_class
)
~H"""
<div class="mb-10 text-sm font-medium text-center text-gray-500 border-b border-gray-200">
<ul class="flex flex-wrap -mb-px">
{component_menu_items(assigns)}
</ul>
</div>
"""
end
defp component_menu_items(%{current_action: :new} = assigns) do
~H"""
<li class="mr-2"><.link patch={beacon_live_admin_path(@socket, @site, "/components/#{@component_id}")} class={@active_class}>Component</.link></li>
"""
end
defp component_menu_items(assigns) do
~H"""
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/components/#{@component_id}")} class={if(@current_action == :edit, do: @active_class, else: @regular_class)}>Component</.link>
</li>
<li class="mr-2">
<.link patch={beacon_live_admin_path(@socket, @site, "/components/#{@component_id}/slots")} class={if(@current_action == :slots, do: @active_class, else: @regular_class)}>Slots</.link>
</li>
"""
end
@doc """
Renders a thumbnail image.
"""
attr :source, :string, default: nil
def thumbnail(assigns) do
~H"""
<image src={@source} width="50" height="50" />
"""
end
@doc """
Renders a modal.
## Examples
<.modal id="confirm-modal">
This is a modal.
</.modal>
JS commands may be passed to the `:on_cancel` to configure
the closing/cancel event, for example:
<.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}>
This is another modal.
</.modal>
"""
attr :id, :string, required: true
attr :show, :boolean, default: false
attr :on_cancel, JS, default: %JS{}
slot :inner_block, required: true
def modal(assigns) do
~H"""
<div id={@id} phx-mounted={@show && show_modal(@id)} phx-remove={hide_modal(@id)} data-cancel={JS.exec(@on_cancel, "phx-remove")} class="relative z-50 hidden">
<div id={"#{@id}-bg"} class="fixed inset-0 transition-opacity bg-zinc-50/90" aria-hidden="true" />
<div class="fixed inset-0 overflow-y-auto" aria-labelledby={"#{@id}-title"} aria-describedby={"#{@id}-description"} role="dialog" aria-modal="true" tabindex="0">
<div class="flex items-center justify-center min-h-full">
<div class="w-full max-w-3xl p-4 sm:p-6 lg:py-8">
<.focus_wrap
id={"#{@id}-container"}
phx-window-keydown={JS.exec("data-cancel", to: "##{@id}")}
phx-key="escape"
phx-click-away={JS.exec("data-cancel", to: "##{@id}")}
class="relative hidden transition bg-white shadow-lg shadow-zinc-700/10 ring-zinc-700/10 rounded-2xl p-14 ring-1"
>
<div class="absolute top-6 right-5">
<button phx-click={JS.exec("data-cancel", to: "##{@id}")} type="button" class="flex-none p-3 -m-3 opacity-20 hover:opacity-40" aria-label={gettext("close")}>
<.icon name="hero-x-mark-solid" class="w-5 h-5" />
</button>
</div>
<div id={"#{@id}-content"}>
{render_slot(@inner_block)}
</div>
</.focus_wrap>
</div>
</div>
</div>
</div>
"""
end
@doc """
Renders flash notices.
## Examples
<.flash kind={:info} flash={@flash} />
<.flash kind={:info} phx-mounted={show("#flash")}>Welcome Back!</.flash>
"""
attr :id, :string, default: "flash", doc: "the optional id of flash container"
attr :flash, :map, default: %{}, doc: "the map of flash messages to display"
attr :title, :string, default: nil
attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup"
attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container"
slot :inner_block, doc: "the optional inner block that renders the flash message"
def flash(assigns) do
~H"""
<div
:if={msg = render_slot(@inner_block) || Phoenix.Flash.get(@flash, @kind)}
id={@id}
phx-click={JS.push("lv:clear-flash", value: %{key: @kind}) |> hide("##{@id}")}
role="alert"
class={[
"fixed top-2 right-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1",
@kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900",
@kind == :error && "bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900"
]}
{@rest}
>
<p :if={@title} class="flex items-center gap-1.5 text-sm font-semibold leading-6">
<.icon :if={@kind == :info} name="hero-information-circle-mini" class="w-4 h-4" />
<.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="w-4 h-4" />
{@title}
</p>
<p class="mt-2 text-sm leading-5">{msg}</p>
<button type="button" class="absolute p-2 group top-1 right-1" aria-label={gettext("close")}>
<.icon name="hero-x-mark-solid" class="w-5 h-5 opacity-40 group-hover:opacity-70" />
</button>
</div>
"""
end
@doc """
Shows the flash group with standard titles and content.
## Examples
<.flash_group flash={@flash} />
"""
attr :flash, :map, required: true, doc: "the map of flash messages"
def flash_group(assigns) do
~H"""
<.flash kind={:info} title="Success!" flash={@flash} />
<.flash kind={:error} title="Error!" flash={@flash} />
<.flash id="disconnected" kind={:error} title="We can't find the internet" phx-disconnected={show("#disconnected")} phx-connected={hide("#disconnected")} hidden>
Attempting to reconnect <.icon name="hero-arrow-path" class="w-3 h-3 ml-1 animate-spin" />
</.flash>
"""
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</.button>
</:actions>
</.simple_form>
"""
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}>
<div class="mt-10 space-y-8">
{render_slot(@inner_block, f)}
<div :for={action <- @actions} class="flex items-center justify-between gap-6 mt-2">
{render_slot(action, f)}
</div>
</div>
</.form>
"""
end
@doc """
Renders a button.
## Examples
<.button>Send!</.button>
<.button phx-click="go" class="ml-2">Send!</.button>
"""
attr :type, :string, default: nil
attr :class, :string, default: nil
attr :rest, :global, include: ~w(disabled form name value)
slot :inner_block, required: true
def button(assigns) do
~H"""
<button
type={@type}
class={[
"phx-submit-loading:opacity-75 rounded-xl whitespace-nowrap bg-blue-600 hover:bg-blue-700 focus:outline-none focus-visible:ring-4 focus-visible:ring-blue-200 active:bg-blue-800 py-3.5 px-6",
"text-sm/5 font-semibold tracking-[1.68px] text-white active:text-white/80 flex items-center gap-2",
@class
]}
{@rest}
>
{render_slot(@inner_block)}
</button>
"""
end
@doc """
Renders an input with label and error messages.
A `%Phoenix.HTML.Form{}` and field name may be passed to the input
to build input names and error messages, or all the attributes and
errors may be passed explicitly.
## Examples
<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />
"""
attr :id, :any, default: nil
attr :name, :any
attr :label, :string, default: nil
attr :value, :any
attr :type, :string,
default: "text",
values: ~w(checkbox color date datetime-local email file hidden month number password
range radio search select tel text textarea time url week)
attr :field, Phoenix.HTML.FormField, doc: "a form field struct retrieved from the form, for example: @form[:email]"
attr :errors, :list, default: []
attr :checked, :boolean, doc: "the checked flag for checkbox inputs"
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
attr :rest, :global, include: ~w(autocomplete cols disabled form list max maxlength min minlength
pattern placeholder readonly required rows size step)
slot :inner_block
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
assigns
|> assign(field: nil, id: assigns.id || field.id)
|> assign(:errors, Enum.map(field.errors, &translate_error(&1)))
|> assign_new(:name, fn -> if assigns.multiple, do: field.name <> "[]", else: field.name end)
|> assign_new(:value, fn -> field.value end)
|> input()
end
def input(%{type: "checkbox", value: value} = assigns) do
assigns =
assign_new(assigns, :checked, fn -> Phoenix.HTML.Form.normalize_value("checkbox", value) end)
~H"""
<div phx-feedback-for={@name}>
<label class="flex items-center gap-4 text-sm leading-6 text-zinc-600">
<input type="hidden" name={@name} value="false" />
<input type="checkbox" id={@id} name={@name} value="true" checked={@checked} class="rounded border-zinc-300 text-zinc-900 focus:ring-0" {@rest} />
{@label}
</label>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
"""
end
def input(%{type: "select"} = assigns) do
~H"""
<div phx-feedback-for={@name}>
<%= if @label do %>
<.label for={@id}>{@label}</.label>
<% end %>
<select
id={@id}
name={@name}
class="block w-full mt-1 bg-white border border-gray-300 rounded-md shadow-sm focus:border-blue-600 focus:ring-2 focus:ring-blue-200 sm:text-sm"
multiple={@multiple}
{@rest}
>
<option :if={@prompt} value="">{@prompt}</option>
{Phoenix.HTML.Form.options_for_select(@options, @value)}
</select>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
"""
end
def input(%{type: "textarea"} = assigns) do
~H"""
<div phx-feedback-for={@name}>
<%= if @label do %>
<.label for={@id}>{@label}</.label>
<% end %>
<textarea
id={@id}
name={@name}
class={[
"block w-full rounded-lg text-zinc-900 focus:ring-2 focus:ring-blue-200 sm:text-sm sm:leading-6",
"phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-blue-600",
"min-h-[6rem] border-zinc-300 focus:border-blue-600",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
><%= Phoenix.HTML.Form.normalize_value("textarea", @value) %></textarea>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
"""
end
# All other inputs text, datetime-local, url, password, etc. are handled here...
def input(assigns) do
~H"""
<div phx-feedback-for={@name}>
<%= if @label do %>
<.label for={@id}>{@label}</.label>
<% end %>
<input
type={@type}
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
"block w-full rounded-lg text-zinc-900 focus:ring-2 focus:ring-blue-200 sm:text-sm sm:leading-6",
"phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-blue-600",
"border-zinc-300 focus:border-blue-600",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
/>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
"""
end
@doc """
Renders a label.
"""
attr :for, :string, default: nil
slot :inner_block, required: true
def label(assigns) do
~H"""
<label for={@for} class="mb-2 block font-medium capitalize text-sm/5 text-[#304254]">
{render_slot(@inner_block)}
</label>
"""
end
@doc """
Generates a generic error message.
"""
slot :inner_block, required: true
def error(assigns) do
~H"""
<p class="flex gap-3 mt-3 text-sm leading-6 text-rose-600 phx-no-feedback:hidden">
<.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" />
{render_slot(@inner_block)}
</p>
"""
end
@doc ~S"""
Renders a table with generic styling.
## Examples
<.table id="users" rows={@users}>
<:col :let={user} label="id"><%= user.id %></:col>
<:col :let={user} label="username"><%= user.username %></:col>
</.table>
"""
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"""
<div class="px-4 overflow-y-auto sm:overflow-visible sm:px-0">
<table class="w-[40rem] mt-6 sm:w-full">
<thead class="text-sm leading-6 text-left text-zinc-500">
<tr>
<th :for={col <- @col} class="pt-0 pb-4 pl-0 pr-6 font-sans font-semibold uppercase text-sm tracking-[1.68px]">{col[:label]}</th>
<th class="relative p-0 pb-4"><span class="sr-only">{gettext("Actions")}</span></th>
</tr>
</thead>
<tbody id={@id} phx-update={match?(%Phoenix.LiveView.LiveStream{}, @rows) && "stream"} class="relative text-sm leading-6 divide-y border-grey-100 divide-grey-100 text-[#111625] font-medium">
<tr :for={row <- @rows} id={@row_id && @row_id.(row)} class="group hover:bg-[#F0F5F9]">
<td :for={{col, i} <- Enum.with_index(@col)} phx-click={@row_click && @row_click.(row)} class={["relative p-0", @row_click && "hover:cursor-pointer"]}>
<div class="block py-4 pr-6">
<span class="absolute right-0 -inset-y-px -left-3 group-hover:bg-[#F0F5F9] sm:rounded-l-xl" />
<span class={["relative", i == 0 && "font-semibold text-zinc-900"]}>
{render_slot(col, @row_item.(row))}
</span>
</div>
</td>
<td :if={@action != []} class="relative p-0 w-14">
<div class="block py-4 pl-6">
<div class="flex justify-end">
<span class="absolute left-0 -inset-y-px -right-3 group-hover:bg-[#F0F5F9] sm:rounded-r-xl" />
<span :for={action <- @action} class="relative text-sm font-medium font-semibold text-right text-zinc-900 hover:text-zinc-700 whitespace-nowrap">
{render_slot(action, @row_item.(row))}
</span>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
"""
end
@doc """
Renders a data list.
## Examples
<.list>
<:item title="Title"><%= @post.title %></:item>
<:item title="Views"><%= @post.views %></:item>
</.list>
"""
slot :item, required: true do
attr :title, :string, required: true
end
def list(assigns) do
~H"""
<div class="mt-14">
<dl class="-my-4 divide-y divide-zinc-100">
<div :for={item <- @item} class="flex gap-4 py-4 text-sm leading-6 sm:gap-8">
<dt class="flex-none w-1/4 text-zinc-500">{item.title}</dt>
<dd class="text-zinc-700">{render_slot(item)}</dd>
</div>
</dl>
</div>
"""
end
@doc """
Renders a back navigation link.
## Examples
<.back navigate={~p"/posts"}>Back to posts</.back>
"""
attr :navigate, :any, required: true
slot :inner_block, required: true
def back(assigns) do
~H"""
<div class="mt-16">
<.link navigate={@navigate} class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700">
<.icon name="hero-arrow-left-solid" class="w-3 h-3" />
{render_slot(@inner_block)}
</.link>
</div>
"""
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"""
<div class={"#{@class} px-4 py-2 mt-6 bg-white col-span-full rounded-[1.1rem]"}>
{render_slot(@inner_block)}
</div>
"""
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} />
</.simple_form>
"""
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">
<div class="flex items-center gap-2 justify-end">
<label for="sort_sort_by" class="text-sm font-medium text-gray-900">Sort by</label>
<.input type="select" field={f[:sort_by]} value={@table.sort_by} options={@options} />
</div>
</.simple_form>
"""
end
@doc """
Renders pagination to nagivate table results.
"""
attr :socket, Phoenix.LiveView.Socket, required: true
attr :page, Beacon.LiveAdmin.PageBuilder.Page, required: true
attr :limit, :integer, default: 11
def table_pagination(assigns) do
assigns = assign(assigns, :table, assigns.page.table)
~H"""
<div :if={@table.page_count > 1} class="flex flex-row justify-center space-x-6 pt-8 text-xl font-semibold pt-10 pb-10">
<.link
:if={@table.current_page > 1}
patch={Table.prev_path(@socket, @page)}
class="border-b-4 border-transparent hover:text-blue-600 hover:border-blue-600 active:text-blue-700 focus:outline-none focus:duration-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-300 focus-visible:rounded focus-visible:duration-300 transition-link duration-300 only-large"
>
<.icon name="hero-arrow-long-left-solid" class="mr-2" /> prev
</.link>
<span :if={@table.current_page == 1} class="font-heading font-semibold text-gray-400 cursor-default">
<.icon name="hero-arrow-long-left-solid" class="mr-2" /> prev
</span>
<%= for page <- Beacon.LiveAdmin.PageBuilder.Table.nav_pages(@table.current_page, @table.page_count, @limit) do %>
<span :if={is_integer(page)}>
<.link
patch={Table.goto_path(@socket, @page, page)}
class={
if @table.current_page == page,
do:
"px-3 pb-0.5 pt-1.5 border-b-4 border-transparent hover:text-blue-600 hover:border-blue-600 active:text-blue-700 focus:outline-none focus:duration-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-300 focus-visible:rounded focus-visible:duration-300 transition-link duration-300 only-large text-blue-700 border-blue-700",
else:
"px-3 pb-0.5 pt-1.5 border-b-4 border-transparent hover:text-blue-600 hover:border-blue-600 active:text-blue-700 focus:outline-none focus:duration-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-300 focus-visible:rounded focus-visible:duration-300 transition-link duration-300 only-large"
}
>
{page}
</.link>
</span>
<span :if={page == :sep}>
...
</span>
<% end %>
<.link
:if={@table.current_page < @table.page_count}
patch={Table.next_path(@socket, @page)}
class="border-b-4 border-transparent hover:text-blue-600 hover:border-blue-600 active:text-blue-800 focus:outline-none focus:duration-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-300 focus-visible:rounded focus-visible:duration-300 transition-link duration-300 only-large"
>
next <.icon name="hero-arrow-long-right-solid" class="mr-2" />
</.link>
<span :if={@table.current_page == @table.page_count} class="font-heading font-semibold text-gray-400 cursor-default">
next <.icon name="hero-arrow-long-right-solid" class="mr-2" />
</span>
</div>
"""
end
@doc """
Renders a select input with the available sites to select.
## Examples
<.site_selector selected_site="dev" options={[:dev, :dy]} />
"""
attr :selected_site, :string, default: ""
attr :options, :list, default: []
def site_selector(assigns) do
~H"""
<div class="pr-2">
<.form id="site-selector-form" for={%{}} phx-change="change-site">
<.input type="select" name="site" options={@options} value={@selected_site} />
</.form>
</div>
"""
end
end