add admin sidebar layout with responsive drawer navigation
- New admin root + child layouts with daisyUI drawer sidebar - AdminLayoutHook tracks current path for active nav highlighting - Split router into :admin, :admin_theme, :user_settings live_sessions - Theme editor stays full-screen with back link to admin - Admin bar on shop pages for logged-in users (mount_current_scope) - Strip Layouts.app wrapper from admin LiveViews - Remove nav from root.html.heex (now only serves auth pages) - 9 new layout tests covering sidebar, active state, theme editor, admin bar Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,35 +35,8 @@ defmodule SimpleshopThemeWeb.Layouts do
|
||||
|
||||
def app(assigns) do
|
||||
~H"""
|
||||
<header class="navbar px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex-1">
|
||||
<a href="/" class="flex-1 flex w-fit items-center gap-2">
|
||||
<img src={~p"/images/logo.svg"} width="36" />
|
||||
<span class="text-sm font-semibold">v{Application.spec(:phoenix, :vsn)}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<ul class="flex flex-column px-1 space-x-4 items-center">
|
||||
<li>
|
||||
<a href="https://phoenixframework.org/" class="btn btn-ghost">Website</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/phoenixframework/phoenix" class="btn btn-ghost">GitHub</a>
|
||||
</li>
|
||||
<li>
|
||||
<.theme_toggle />
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://hexdocs.pm/phoenix/overview.html" class="btn btn-primary">
|
||||
Get Started <span aria-hidden="true">→</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="px-4 py-20 sm:px-6 lg:px-8">
|
||||
<div class="mx-auto max-w-2xl flex flex-col gap-4">
|
||||
<main class="px-4 py-12 sm:px-6 lg:px-8">
|
||||
<div class="mx-auto max-w-lg flex flex-col gap-4">
|
||||
{render_slot(@inner_block)}
|
||||
</div>
|
||||
</main>
|
||||
@@ -72,6 +45,11 @@ defmodule SimpleshopThemeWeb.Layouts do
|
||||
"""
|
||||
end
|
||||
|
||||
@doc false
|
||||
def admin_nav_active?(current_path, link_path) do
|
||||
if String.starts_with?(current_path, link_path), do: "active", else: nil
|
||||
end
|
||||
|
||||
@doc """
|
||||
Shows the flash group with standard titles and content.
|
||||
|
||||
|
||||
102
lib/simpleshop_theme_web/components/layouts/admin.html.heex
Normal file
102
lib/simpleshop_theme_web/components/layouts/admin.html.heex
Normal file
@@ -0,0 +1,102 @@
|
||||
<div class="drawer lg:drawer-open h-full">
|
||||
<input id="admin-drawer" type="checkbox" class="drawer-toggle" />
|
||||
|
||||
<%!-- main content area --%>
|
||||
<div class="drawer-content flex flex-col min-h-screen">
|
||||
<%!-- mobile header --%>
|
||||
<header class="navbar bg-base-100 border-b border-base-200 lg:hidden">
|
||||
<div class="flex-none">
|
||||
<label for="admin-drawer" class="btn btn-square btn-ghost" aria-label="Open navigation">
|
||||
<.icon name="hero-bars-3" class="size-5" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<span class="text-lg font-semibold">SimpleShop</span>
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<.link href={~p"/"} class="btn btn-ghost btn-sm">
|
||||
<.icon name="hero-arrow-top-right-on-square-mini" class="size-4" /> Shop
|
||||
</.link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<%!-- page content --%>
|
||||
<main class="flex-1 p-4 sm:p-6 lg:p-8">
|
||||
<div class="mx-auto max-w-5xl">
|
||||
{@inner_content}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<%!-- sidebar --%>
|
||||
<div class="drawer-side z-40">
|
||||
<label for="admin-drawer" class="drawer-overlay" aria-label="Close navigation"></label>
|
||||
<aside class="bg-base-200 w-64 min-h-full flex flex-col">
|
||||
<%!-- sidebar header --%>
|
||||
<div class="p-4 border-b border-base-300">
|
||||
<.link navigate={~p"/admin/orders"} class="text-lg font-bold tracking-tight">
|
||||
SimpleShop
|
||||
</.link>
|
||||
<p class="text-xs text-base-content/60 mt-0.5 truncate">
|
||||
{@current_scope.user.email}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%!-- nav links --%>
|
||||
<nav class="flex-1 p-2" aria-label="Admin navigation">
|
||||
<ul class="menu gap-0.5">
|
||||
<li>
|
||||
<.link
|
||||
navigate={~p"/admin/orders"}
|
||||
class={admin_nav_active?(@current_path, "/admin/orders")}
|
||||
>
|
||||
<.icon name="hero-shopping-bag" class="size-5" /> Orders
|
||||
</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link
|
||||
href={~p"/admin/theme"}
|
||||
class={admin_nav_active?(@current_path, "/admin/theme")}
|
||||
>
|
||||
<.icon name="hero-paint-brush" class="size-5" /> Theme
|
||||
</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link
|
||||
navigate={~p"/admin/providers"}
|
||||
class={admin_nav_active?(@current_path, "/admin/providers")}
|
||||
>
|
||||
<.icon name="hero-cube" class="size-5" /> Providers
|
||||
</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link
|
||||
navigate={~p"/admin/settings"}
|
||||
class={admin_nav_active?(@current_path, "/admin/settings")}
|
||||
>
|
||||
<.icon name="hero-cog-6-tooth" class="size-5" /> Settings
|
||||
</.link>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<%!-- sidebar footer --%>
|
||||
<div class="p-2 border-t border-base-300">
|
||||
<ul class="menu gap-0.5">
|
||||
<li>
|
||||
<.link href={~p"/"}>
|
||||
<.icon name="hero-arrow-top-right-on-square" class="size-5" /> View shop
|
||||
</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/users/log-out"} method="delete">
|
||||
<.icon name="hero-arrow-right-start-on-rectangle" class="size-5" /> Log out
|
||||
</.link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<.flash_group flash={@flash} />
|
||||
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="h-full">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="csrf-token" content={get_csrf_token()} />
|
||||
<.live_title default="Admin" suffix=" · SimpleShop">
|
||||
{assigns[:page_title]}
|
||||
</.live_title>
|
||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} />
|
||||
<script defer phx-track-static src={~p"/assets/js/app.js"}>
|
||||
</script>
|
||||
<script>
|
||||
(() => {
|
||||
const setTheme = (theme) => {
|
||||
if (theme === "system") {
|
||||
localStorage.removeItem("phx:theme");
|
||||
document.documentElement.removeAttribute("data-theme");
|
||||
} else {
|
||||
localStorage.setItem("phx:theme", theme);
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
}
|
||||
};
|
||||
if (!document.documentElement.hasAttribute("data-theme")) {
|
||||
setTheme(localStorage.getItem("phx:theme") || "system");
|
||||
}
|
||||
window.addEventListener("storage", (e) => e.key === "phx:theme" && setTheme(e.newValue || "system"));
|
||||
window.addEventListener("phx:set-theme", (e) => setTheme(e.target.dataset.phxTheme));
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body class="h-full">
|
||||
{@inner_content}
|
||||
</body>
|
||||
</html>
|
||||
@@ -31,42 +31,6 @@
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="w-full relative z-10 flex items-center px-4 sm:px-6 lg:px-8 justify-between">
|
||||
<div>
|
||||
<%= if @current_scope && assigns[:conn] && @conn.request_path == "/admin/theme" do %>
|
||||
<.link href={~p"/"} class="text-sm hover:underline">← View Shop</.link>
|
||||
<% end %>
|
||||
</div>
|
||||
<ul class="menu menu-horizontal flex items-center gap-4">
|
||||
<%= if @current_scope do %>
|
||||
<li>
|
||||
{@current_scope.user.email}
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/admin/theme"}>Theme</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/admin/orders"}>Orders</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/admin/settings"}>Credentials</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/users/settings"}>Settings</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/users/log-out"} method="delete">Log out</.link>
|
||||
</li>
|
||||
<% else %>
|
||||
<li>
|
||||
<.link href={~p"/users/register"}>Register</.link>
|
||||
</li>
|
||||
<li>
|
||||
<.link href={~p"/users/log-in"}>Log in</.link>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</nav>
|
||||
{@inner_content}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,2 +1,13 @@
|
||||
<div
|
||||
:if={assigns[:current_scope]}
|
||||
style="background-color: var(--t-surface-raised, #f5f5f5); border-bottom: 1px solid var(--t-border-default, #e5e5e5); padding: 0.25rem 1rem; font-size: 0.75rem; text-align: right;"
|
||||
>
|
||||
<.link
|
||||
href={~p"/admin/orders"}
|
||||
style="color: var(--t-text-secondary, #666); text-decoration: none;"
|
||||
>
|
||||
Admin
|
||||
</.link>
|
||||
</div>
|
||||
<.shop_flash_group flash={@flash} />
|
||||
{@inner_content}
|
||||
|
||||
Reference in New Issue
Block a user