Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+1
-2
@@ -2,7 +2,6 @@ import { ReactNode } from "react";
|
||||
import { useParams } from "react-router";
|
||||
import BreadcrumbSimple from "../breadcrumbs/BreadcrumbSimple";
|
||||
import Tabs, { TabItem } from "../tabs/Tabs";
|
||||
import clsx from "clsx";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
@@ -28,7 +27,7 @@ export default function EditPageLayout({ title, menu, buttons, children, withHom
|
||||
{(title || buttons || menu || tabs) && (
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center justify-between space-x-2">
|
||||
<h1 className="flex flex-1 items-center truncate text-xl font-medium">{title}</h1>
|
||||
{title ? <h1 className="flex flex-1 items-center truncate text-xl font-medium">{title}</h1> : <div className="flex-1" />}
|
||||
<div className="flex items-center space-x-2">{buttons}</div>
|
||||
</div>
|
||||
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
import { ReactNode } from "react";
|
||||
import Breadcrumb from "../breadcrumbs/Breadcrumb";
|
||||
import Tabs, { TabItem } from "../tabs/Tabs";
|
||||
import BreadcrumbSimple from "../breadcrumbs/BreadcrumbSimple";
|
||||
|
||||
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { act, fireEvent, render, within } from "@testing-library/react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import SidebarIconsLayout from "./SidebarIconsLayout";
|
||||
|
||||
function useDeterministicFakeTimers() {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-01-01T00:00:00.000Z"));
|
||||
}
|
||||
|
||||
function renderLayout({ sticky = false }: { sticky?: boolean } = {}) {
|
||||
const { container } = render(
|
||||
<MemoryRouter initialEntries={["/overview"]}>
|
||||
<SidebarIconsLayout
|
||||
sticky={sticky}
|
||||
items={[
|
||||
{ name: "Overview", href: "/overview", icon: <span aria-hidden="true">O</span> },
|
||||
{ name: "Campaigns", href: "/campaigns", icon: <span aria-hidden="true">C</span> },
|
||||
]}
|
||||
>
|
||||
<main>Content</main>
|
||||
</SidebarIconsLayout>
|
||||
</MemoryRouter>
|
||||
);
|
||||
const sidebar = container.querySelector("nav:not([aria-label])");
|
||||
expect(sidebar).not.toBeNull();
|
||||
return sidebar as HTMLElement;
|
||||
}
|
||||
|
||||
describe("SidebarIconsLayout", () => {
|
||||
it("expands after 300 ms of hover and collapses after the pointer leaves", () => {
|
||||
useDeterministicFakeTimers();
|
||||
try {
|
||||
const sidebar = renderLayout();
|
||||
const hoverTarget = sidebar.parentElement;
|
||||
|
||||
expect(hoverTarget).not.toBeNull();
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
expect(within(sidebar).queryByRole("button")).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.mouseEnter(hoverTarget!);
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
|
||||
act(() => vi.advanceTimersByTime(299));
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
|
||||
act(() => vi.advanceTimersByTime(1));
|
||||
expect(sidebar).toHaveClass("w-[208px]");
|
||||
|
||||
fireEvent.mouseLeave(hoverTarget!);
|
||||
act(() => vi.advanceTimersByTime(349));
|
||||
expect(sidebar).toHaveClass("w-[208px]");
|
||||
|
||||
act(() => vi.advanceTimersByTime(1));
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("stays collapsed when the pointer leaves before the open delay", () => {
|
||||
useDeterministicFakeTimers();
|
||||
try {
|
||||
const sidebar = renderLayout();
|
||||
const hoverTarget = sidebar.parentElement!;
|
||||
|
||||
fireEvent.mouseEnter(hoverTarget);
|
||||
act(() => vi.advanceTimersByTime(250));
|
||||
fireEvent.mouseLeave(hoverTarget);
|
||||
act(() => vi.runAllTimers());
|
||||
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
|
||||
fireEvent.mouseEnter(hoverTarget);
|
||||
act(() => vi.advanceTimersByTime(299));
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
|
||||
act(() => vi.advanceTimersByTime(1));
|
||||
expect(sidebar).toHaveClass("w-[208px]");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not expand after a pointer route click remounts the settings shell", () => {
|
||||
useDeterministicFakeTimers();
|
||||
try {
|
||||
const firstRoute = render(
|
||||
<MemoryRouter initialEntries={["/overview"]}>
|
||||
<SidebarIconsLayout
|
||||
items={[
|
||||
{ name: "Overview", href: "/overview", icon: <span aria-hidden="true">O</span> },
|
||||
{ name: "Campaigns", href: "/campaigns", icon: <span aria-hidden="true">C</span> },
|
||||
]}
|
||||
>
|
||||
<main>Content</main>
|
||||
</SidebarIconsLayout>
|
||||
</MemoryRouter>
|
||||
);
|
||||
const sidebar = firstRoute.container.querySelector("nav:not([aria-label])") as HTMLElement;
|
||||
const hoverTarget = sidebar.parentElement!;
|
||||
const firstLink = within(sidebar).getByRole("link", { name: "Overview" });
|
||||
|
||||
fireEvent.mouseEnter(hoverTarget);
|
||||
act(() => vi.advanceTimersByTime(150));
|
||||
fireEvent.pointerDown(firstLink);
|
||||
fireEvent.focus(firstLink);
|
||||
fireEvent.pointerUp(firstLink);
|
||||
act(() => vi.runAllTimers());
|
||||
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
firstRoute.unmount();
|
||||
|
||||
const nextRoute = render(
|
||||
<MemoryRouter initialEntries={["/campaigns"]}>
|
||||
<SidebarIconsLayout
|
||||
items={[
|
||||
{ name: "Overview", href: "/overview", icon: <span aria-hidden="true">O</span> },
|
||||
{ name: "Campaigns", href: "/campaigns", icon: <span aria-hidden="true">C</span> },
|
||||
]}
|
||||
>
|
||||
<main>Next content</main>
|
||||
</SidebarIconsLayout>
|
||||
</MemoryRouter>
|
||||
);
|
||||
const nextSidebar = nextRoute.container.querySelector("nav:not([aria-label])") as HTMLElement;
|
||||
const nextHoverTarget = nextSidebar.parentElement!;
|
||||
|
||||
fireEvent.mouseEnter(nextHoverTarget);
|
||||
act(() => vi.advanceTimersByTime(1_000));
|
||||
|
||||
expect(nextSidebar).toHaveClass("w-12");
|
||||
|
||||
fireEvent.mouseLeave(nextHoverTarget);
|
||||
fireEvent.mouseEnter(nextHoverTarget);
|
||||
act(() => vi.advanceTimersByTime(300));
|
||||
|
||||
expect(nextSidebar).toHaveClass("w-[208px]");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("cancels the delayed close when the pointer returns", () => {
|
||||
useDeterministicFakeTimers();
|
||||
try {
|
||||
const sidebar = renderLayout();
|
||||
const hoverTarget = sidebar.parentElement!;
|
||||
|
||||
fireEvent.mouseEnter(hoverTarget);
|
||||
act(() => vi.advanceTimersByTime(300));
|
||||
fireEvent.mouseLeave(hoverTarget);
|
||||
act(() => vi.advanceTimersByTime(200));
|
||||
fireEvent.mouseEnter(hoverTarget);
|
||||
act(() => vi.advanceTimersByTime(350));
|
||||
|
||||
expect(sidebar).toHaveClass("w-[208px]");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("stays expanded while keyboard focus is inside", () => {
|
||||
const sidebar = renderLayout();
|
||||
const firstLink = within(sidebar).getByRole("link", { name: "Overview" });
|
||||
|
||||
fireEvent.focus(firstLink);
|
||||
expect(sidebar).toHaveClass("w-[208px]");
|
||||
|
||||
fireEvent.blur(firstLink, { relatedTarget: document.body });
|
||||
expect(sidebar).toHaveClass("w-12");
|
||||
});
|
||||
|
||||
it("smoothly magnifies the complete hovered navigation item", () => {
|
||||
const sidebar = renderLayout();
|
||||
const firstLink = within(sidebar).getByRole("link", { name: "Overview" });
|
||||
const itemSurface = firstLink.querySelector('[data-slot="inner-sidebar-nav-item-surface"]');
|
||||
|
||||
expect(itemSurface).toHaveClass(
|
||||
"pointer-events-none",
|
||||
"scale-100",
|
||||
"transition-[background-color,scale]",
|
||||
"duration-150",
|
||||
"ease-[cubic-bezier(0.4,0,0.2,1)]",
|
||||
"motion-reduce:transition-none",
|
||||
"group-hover/7aa51c7e:scale-[1.065]",
|
||||
"data-[sidebar-sweep-hover=true]:scale-[1.065]"
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the desktop settings rail fixed when sticky is enabled", () => {
|
||||
const sidebar = renderLayout({ sticky: true });
|
||||
|
||||
expect(sidebar.parentElement).toHaveClass("sm:sticky", "sm:top-0", "sm:self-start");
|
||||
expect(sidebar).toHaveClass("min-h-[calc(100svh-3.5rem)]");
|
||||
});
|
||||
|
||||
it("uses the selected icon and normalizes nested glyphs to the same size", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter initialEntries={["/overview"]}>
|
||||
<SidebarIconsLayout
|
||||
items={[
|
||||
{
|
||||
name: "Overview",
|
||||
href: "/overview",
|
||||
icon: (
|
||||
<span data-icon="default">
|
||||
<svg />
|
||||
</span>
|
||||
),
|
||||
iconSelected: (
|
||||
<span data-icon="selected">
|
||||
<svg />
|
||||
</span>
|
||||
),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<main>Content</main>
|
||||
</SidebarIconsLayout>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const selected = container.querySelector('[data-icon="selected"]');
|
||||
expect(selected).toBeInTheDocument();
|
||||
expect(selected).toHaveClass("size-5", "[&_svg]:size-5");
|
||||
expect(container.querySelector('[data-icon="default"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+111
-54
@@ -1,9 +1,9 @@
|
||||
import { Link, useLocation } from "react-router";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
import { cloneElement, isValidElement, useEffect, useRef, useState } from "react";
|
||||
import Tabs from "../tabs/Tabs";
|
||||
import EntityIcon from "~/components/layouts/icons/EntityIcon";
|
||||
import { SidebarInside } from "~/ui";
|
||||
import { isRouteActive } from "~/utils/navigation/routeMatching";
|
||||
|
||||
export type IconDto = {
|
||||
name: string;
|
||||
@@ -18,12 +18,26 @@ export type IconDto = {
|
||||
hidden?: boolean;
|
||||
};
|
||||
|
||||
// Pro-User gemerkter Collapse-Zustand der Inner-Sidebar (Default: aufgeklappt).
|
||||
const COLLAPSE_STORAGE_KEY = "hg.innerSidebar.collapsed";
|
||||
const HOVER_OPEN_DELAY_MS = 300;
|
||||
const HOVER_CLOSE_DELAY_MS = 350;
|
||||
const POINTER_ROUTE_SETTLE_MS = 750;
|
||||
let suppressPointerHoverUntil = 0;
|
||||
let lastPointerInteractionAt = 0;
|
||||
|
||||
function pointerHoverIsSuppressed() {
|
||||
const now = Date.now();
|
||||
if (now < lastPointerInteractionAt) {
|
||||
lastPointerInteractionAt = 0;
|
||||
suppressPointerHoverUntil = 0;
|
||||
return false;
|
||||
}
|
||||
return now < suppressPointerHoverUntil;
|
||||
}
|
||||
|
||||
export default function SidebarIconsLayout({
|
||||
children,
|
||||
items,
|
||||
sticky = false,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
items: IconDto[];
|
||||
@@ -32,59 +46,75 @@ export default function SidebarIconsLayout({
|
||||
align: "bottom" | "right";
|
||||
};
|
||||
scrollRestoration?: boolean;
|
||||
sticky?: boolean;
|
||||
}) {
|
||||
const location = useLocation();
|
||||
const mainElement = useRef<HTMLDivElement>(null);
|
||||
// SSR-safe: Server rendert immer aufgeklappt, der gemerkte Zustand wird erst nach Hydration geladen.
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
// Transitions erst NACH dem Restore aktivieren, sonst animiert der gemerkte Zustand bei jedem Seitenaufruf.
|
||||
const [animate, setAnimate] = useState(false);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [focusWithin, setFocusWithin] = useState(false);
|
||||
const openDelayRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const closeDelayRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const pointerInteractionRef = useRef(false);
|
||||
const suppressHoverUntilLeaveRef = useRef(false);
|
||||
const expanded = hovered || focusWithin;
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
setCollapsed(window.localStorage.getItem(COLLAPSE_STORAGE_KEY) === "1");
|
||||
} catch {
|
||||
// localStorage nicht verfügbar (Privatmodus o.ä.) -> Default aufgeklappt
|
||||
}
|
||||
const id = window.requestAnimationFrame(() => setAnimate(true));
|
||||
return () => window.cancelAnimationFrame(id);
|
||||
}, []);
|
||||
|
||||
function toggleCollapsed() {
|
||||
setCollapsed((prev) => {
|
||||
const next = !prev;
|
||||
try {
|
||||
window.localStorage.setItem(COLLAPSE_STORAGE_KEY, next ? "1" : "0");
|
||||
} catch {
|
||||
// persistieren best-effort
|
||||
}
|
||||
return next;
|
||||
});
|
||||
function cancelScheduledOpen() {
|
||||
if (openDelayRef.current === null) return;
|
||||
clearTimeout(openDelayRef.current);
|
||||
openDelayRef.current = null;
|
||||
}
|
||||
|
||||
function cancelScheduledClose() {
|
||||
if (closeDelayRef.current === null) return;
|
||||
clearTimeout(closeDelayRef.current);
|
||||
closeDelayRef.current = null;
|
||||
}
|
||||
|
||||
function handleMouseEnter() {
|
||||
cancelScheduledClose();
|
||||
if (suppressHoverUntilLeaveRef.current || pointerHoverIsSuppressed()) return;
|
||||
if (hovered || openDelayRef.current !== null) return;
|
||||
openDelayRef.current = setTimeout(() => {
|
||||
setHovered(true);
|
||||
openDelayRef.current = null;
|
||||
}, HOVER_OPEN_DELAY_MS);
|
||||
}
|
||||
|
||||
function handleMouseLeave() {
|
||||
suppressHoverUntilLeaveRef.current = false;
|
||||
pointerInteractionRef.current = false;
|
||||
cancelScheduledOpen();
|
||||
cancelScheduledClose();
|
||||
if (!hovered) return;
|
||||
closeDelayRef.current = setTimeout(() => {
|
||||
setHovered(false);
|
||||
closeDelayRef.current = null;
|
||||
}, HOVER_CLOSE_DELAY_MS);
|
||||
}
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (openDelayRef.current !== null) clearTimeout(openDelayRef.current);
|
||||
if (closeDelayRef.current !== null) clearTimeout(closeDelayRef.current);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
function findExactRoute(element: IconDto) {
|
||||
const hrefWithoutQuery = element.href.split("?")[0];
|
||||
if (element.exact) {
|
||||
return UrlUtils.stripTrailingSlash(location.pathname) === UrlUtils.stripTrailingSlash(hrefWithoutQuery);
|
||||
}
|
||||
return (location.pathname + location.search).includes(hrefWithoutQuery);
|
||||
return isRouteActive(location.pathname, element.href, { exact: element.exact });
|
||||
}
|
||||
const currentTab = items.find((element) => findExactRoute(element));
|
||||
|
||||
function renderItem(item: IconDto, idx: number) {
|
||||
const current = currentTab?.name === item.name;
|
||||
const iconNode =
|
||||
item.textIcon !== undefined ? (
|
||||
<EntityIcon className="h-5 w-5" icon={current ? item.textIconSelected ?? item.textIcon : item.textIcon} />
|
||||
) : current ? (
|
||||
item.iconSelected ?? item.icon
|
||||
) : (
|
||||
item.icon
|
||||
);
|
||||
// Collapsed: center the icon-only item in the narrow rail. Expanded: keep the regular label row.
|
||||
const textIcon = current ? (item.textIconSelected ?? item.textIcon) : item.textIcon;
|
||||
const icon = current ? (item.iconSelected ?? item.icon) : item.icon;
|
||||
const iconNode = textIcon !== undefined ? <EntityIcon className="size-5" icon={textIcon} /> : normalizeIcon(icon);
|
||||
// The icon stays left-anchored in both states (NavItem keeps a constant 32px icon column),
|
||||
// so the icon never shifts horizontally between the collapsed rail and the expanded label row.
|
||||
return (
|
||||
<Link key={idx} prefetch={item.prefetch} to={item.href} className="flex w-full justify-center" title={item.name}>
|
||||
<SidebarInside.NavItem icon={iconNode} selected={current} variant={collapsed ? "icon-only" : "icon-and-text"}>
|
||||
<Link key={idx} prefetch={item.prefetch} to={item.href} className="flex w-full justify-start" title={item.name}>
|
||||
<SidebarInside.NavItem icon={iconNode} selected={current} variant={expanded ? "icon-and-text" : "icon-only"}>
|
||||
{item.name}
|
||||
</SidebarInside.NavItem>
|
||||
</Link>
|
||||
@@ -96,14 +126,34 @@ export default function SidebarIconsLayout({
|
||||
|
||||
return (
|
||||
<div className="sm:flex sm:flex-row">
|
||||
{/* Desktop: Inner sidebar uses the same mechanical width-collapse as the main navigation. */}
|
||||
<div className="relative hidden sm:flex">
|
||||
<SidebarInside
|
||||
visible={true}
|
||||
variant={collapsed ? "closed" : "open"}
|
||||
onToggleCollapse={toggleCollapsed}
|
||||
className={`min-h-[calc(100svh-4rem)] ${animate ? "" : "transition-none"}`}
|
||||
>
|
||||
{/* Desktop: expand on pointer hover or keyboard focus; otherwise keep a compact icon rail. */}
|
||||
<div
|
||||
className={sticky ? "relative hidden sm:sticky sm:top-0 sm:flex sm:self-start" : "relative hidden sm:flex"}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
onPointerDownCapture={() => {
|
||||
const pointerInteractionAt = Date.now();
|
||||
pointerInteractionRef.current = true;
|
||||
suppressHoverUntilLeaveRef.current = true;
|
||||
lastPointerInteractionAt = pointerInteractionAt;
|
||||
suppressPointerHoverUntil = pointerInteractionAt + POINTER_ROUTE_SETTLE_MS;
|
||||
cancelScheduledOpen();
|
||||
setFocusWithin(false);
|
||||
}}
|
||||
onPointerUpCapture={() => {
|
||||
pointerInteractionRef.current = false;
|
||||
}}
|
||||
onPointerCancelCapture={() => {
|
||||
pointerInteractionRef.current = false;
|
||||
}}
|
||||
onFocusCapture={() => {
|
||||
if (!pointerInteractionRef.current) setFocusWithin(true);
|
||||
}}
|
||||
onBlurCapture={(event) => {
|
||||
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setFocusWithin(false);
|
||||
}}
|
||||
>
|
||||
<SidebarInside visible={true} variant={expanded ? "open" : "closed"} className="min-h-[calc(100svh-3.5rem)]">
|
||||
{topItems.map(renderItem)}
|
||||
{bottomItems.length > 0 && (
|
||||
<div className="mt-auto flex w-full flex-col">
|
||||
@@ -121,7 +171,7 @@ export default function SidebarIconsLayout({
|
||||
tabs={items
|
||||
.filter((f) => !f.hidden)
|
||||
.map((i) => {
|
||||
return { name: i.name, routePath: i.href };
|
||||
return { name: i.name, routePath: i.href, exact: i.exact };
|
||||
})}
|
||||
className="grow"
|
||||
/>
|
||||
@@ -129,9 +179,16 @@ export default function SidebarIconsLayout({
|
||||
</div>
|
||||
|
||||
{/* Hauptbereich */}
|
||||
<div ref={mainElement} className="w-full overflow-x-hidden">
|
||||
<div ref={mainElement} className="w-full overflow-x-hidden" data-route-transition-content="true">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeIcon(icon: React.ReactNode) {
|
||||
if (!isValidElement<{ className?: string }>(icon)) return icon;
|
||||
return cloneElement(icon, {
|
||||
className: `${icon.props.className ?? ""} inline-flex size-5 items-center justify-center [&_svg]:size-5`,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user