defmodule Observer.Web.Layouts do
@moduledoc """
This module provides layouts
## References:
* https://github.com/oban-bg/oban_web/blob/main/lib/oban/web/components/layouts.ex
"""
use Observer.Web, :html
embed_templates "layouts/*"
alias Observer.Web.Assets
alias Observer.Web.Components.Icons
defp asset_path(conn, asset) when asset in [:css, :js] do
hash = Assets.current_hash(asset)
{_dash, _routing, meta} = conn.private.phoenix_live_view
prefix = get_in(meta, [:extra, :session, Access.elem(2), Access.at(0)])
Phoenix.VerifiedRoutes.unverified_path(
conn,
conn.private.phoenix_router,
"#{prefix}/#{asset}-#{hash}"
)
end
attr :params, :map, required: true
attr :path, :string, default: nil
def logo(assigns) do
~H"""
Observer
WEB
"""
end
attr :params, :map, required: true
attr :page, :atom, required: true
attr :socket, :map, required: true
def nav(assigns) do
~H"""
"""
end
def footer(assigns) do
assigns =
assign(assigns,
oss_version: Application.spec(:observer_web, :vsn)
)
~H"""
"""
end
attr :name, :string
attr :version, :string
defp version(assigns) do
~H"""
{@name} {if @version, do: "v#{@version}", else: "–"}
"""
end
defp link_class(curr, page) do
base =
"flex items-center px-4 py-2.5 text-sm font-bold transition-all duration-200 text-gray-900 dark:text-white rounded-lg group"
if curr == page do
base <> " bg-gray-100 dark:bg-gray-700"
else
base <> " hover:text-black dark:hover:text-white hover:bg-cyan-500 dark:hover:bg-cyan-800"
end
end
defp list_pages_by_params(%{"iframe" => "true"}), do: [:tracing, :applications, :metrics]
defp list_pages_by_params(_params), do: [:root, :tracing, :applications, :metrics]
@doc """
Renders flash notices.
## Examples
<.flash kind={:info} flash={@flash} />
<.flash kind={:info} phx-mounted={show("#flash")}>Welcome Back!
"""
attr :id, :string, 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
assigns = assign_new(assigns, :id, fn -> "flash-#{assigns.kind}" end)
~H"""
{msg}