feat(ui): glass layout, icon actions and new icon set (#21)
CD — Deployment / deploy (push) Successful in 33s
CD — Deployment / deploy (push) Successful in 33s
PR automatique de feat/ui-glass-layout-icons vers main. --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #21 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #21.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useState } from "react";
|
||||
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
|
||||
import { NavLink, Outlet } from "react-router-dom";
|
||||
import { Button, cn } from "../ui/index.js";
|
||||
import { cn } from "../ui/index.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { Avatar } from "./Avatar.js";
|
||||
import { ColorBendsBackdrop } from "./ColorBendsBackdrop.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
CloseIcon,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
StarIcon,
|
||||
TrashIcon,
|
||||
} from "./icons.js";
|
||||
import { IconAction } from "./IconAction.js";
|
||||
|
||||
interface NavItem {
|
||||
to: string;
|
||||
@@ -49,10 +51,27 @@ const navClass = ({ isActive }: { isActive: boolean }) =>
|
||||
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
);
|
||||
|
||||
type PageHeaderContextValue = {
|
||||
header: ReactNode | null;
|
||||
setHeader: (header: ReactNode | null) => void;
|
||||
};
|
||||
|
||||
const PageHeaderContext = createContext<PageHeaderContextValue | null>(null);
|
||||
|
||||
export const usePageHeader = (header: ReactNode | null) => {
|
||||
const ctx = useContext(PageHeaderContext);
|
||||
useEffect(() => {
|
||||
if (!ctx) return;
|
||||
ctx.setHeader(header);
|
||||
return () => ctx.setHeader(null);
|
||||
}, [ctx, header]);
|
||||
};
|
||||
|
||||
export const AppShell = () => {
|
||||
const { user, logout } = useSession();
|
||||
const { t } = useI18n();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const [pageHeader, setPageHeader] = useState<ReactNode | null>(null);
|
||||
if (!user) return null;
|
||||
|
||||
const isAdmin = user.role_slug === "admin";
|
||||
@@ -88,24 +107,12 @@ export const AppShell = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-dvh overflow-hidden bg-background">
|
||||
<aside className="hidden w-60 shrink-0 flex-col gap-1 overflow-y-auto border-r border-border bg-surface p-3 lg:flex">
|
||||
<div className="px-1 py-2">{brand}</div>
|
||||
{NAV.map(renderLink)}
|
||||
{isAdmin ? (
|
||||
<>
|
||||
<p className="mt-3 px-3 py-1 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
{t("Administration")}
|
||||
</p>
|
||||
{ADMIN_NAV.map(renderLink)}
|
||||
</>
|
||||
) : null}
|
||||
<div className="mt-auto pt-3">{renderLink(ACCOUNT_NAV)}</div>
|
||||
</aside>
|
||||
<PageHeaderContext.Provider value={{ header: pageHeader, setHeader: setPageHeader }}>
|
||||
<div className="relative grid h-dvh grid-cols-[auto_1fr] grid-rows-[auto_1fr] overflow-hidden bg-background">
|
||||
<ColorBendsBackdrop variant="shell" />
|
||||
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
<header className="z-20 shrink-0 border-b border-border bg-surface">
|
||||
<div className="mx-auto flex w-full max-w-5xl items-center justify-between gap-4 px-4 py-3">
|
||||
<header className="relative z-50 col-span-2 row-start-1 border-b border-border/50 bg-surface/70 backdrop-blur-md">
|
||||
<div className="flex w-full items-center justify-between gap-4 px-4 py-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
@@ -116,7 +123,7 @@ export const AppShell = () => {
|
||||
>
|
||||
{menuOpen ? <CloseIcon className="h-5 w-5" /> : <MenuIcon className="h-5 w-5" />}
|
||||
</button>
|
||||
<span className="lg:hidden">{brand}</span>
|
||||
{brand}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -135,30 +142,62 @@ export const AppShell = () => {
|
||||
hasAvatar={user.has_avatar}
|
||||
avatarUpdatedAt={user.avatar_updated_at}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<LogoutIcon className="h-3.5 w-3.5" />}
|
||||
<IconAction
|
||||
label={t("Déconnexion")}
|
||||
icon={<LogoutIcon className="h-4 w-4" />}
|
||||
onClick={() => void logout()}
|
||||
>
|
||||
<span className="hidden sm:inline">{t("Déconnexion")}</span>
|
||||
</Button>
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{menuOpen ? (
|
||||
<nav className="flex flex-col gap-1 border-t border-border px-3 py-2 lg:hidden">
|
||||
{allNav.map(renderLink)}
|
||||
</nav>
|
||||
) : null}
|
||||
</header>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">
|
||||
<main className="mx-auto w-full max-w-5xl px-4 py-6">
|
||||
<Outlet />
|
||||
</main>
|
||||
<aside className="relative z-40 col-start-1 row-start-2 hidden w-60 flex-col gap-1 overflow-y-auto border-r border-border/50 bg-surface/70 p-3 backdrop-blur-md lg:flex">
|
||||
{NAV.map(renderLink)}
|
||||
{isAdmin ? (
|
||||
<>
|
||||
<p className="mt-3 px-3 py-1 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
{t("Administration")}
|
||||
</p>
|
||||
{ADMIN_NAV.map(renderLink)}
|
||||
</>
|
||||
) : null}
|
||||
<div className="mt-auto pt-3">{renderLink(ACCOUNT_NAV)}</div>
|
||||
</aside>
|
||||
|
||||
{menuOpen ? (
|
||||
<div className="lg:hidden">
|
||||
<div className="fixed inset-0 z-40 bg-black/50 backdrop-blur-sm" onClick={() => setMenuOpen(false)} aria-hidden="true" />
|
||||
<nav className="fixed inset-0 z-50 flex flex-col bg-background/95 backdrop-blur-lg transition-transform duration-300 sm:absolute sm:inset-y-0 sm:left-0 sm:w-72 sm:inset-x-auto">
|
||||
<div className="flex items-center justify-between border-b border-border/50 px-4 py-3">
|
||||
{brand}
|
||||
<button
|
||||
type="button"
|
||||
className="text-muted-foreground"
|
||||
aria-label={t("Fermer le menu")}
|
||||
onClick={() => setMenuOpen(false)}
|
||||
>
|
||||
<CloseIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col gap-1 overflow-y-auto p-3">
|
||||
{allNav.map(renderLink)}
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="relative z-10 col-start-2 row-start-2 min-h-0 overflow-hidden">
|
||||
<div className="h-full w-full bg-surface/30 backdrop-blur-lg">
|
||||
<div className="flex h-full flex-col">
|
||||
{pageHeader ? <div className="relative z-30 shrink-0">{pageHeader}</div> : null}
|
||||
<main className="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 pb-6 pt-4 [scrollbar-gutter:stable]">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageHeaderContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user