mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(settings): align section nav with the first card via the grid, not a spacer
The settings and admin shells reserved the page-heading height in the left nav with a hidden replica block. The replica wrapped differently in the 220px nav column than the real heading in the wide content column, so the first nav item sat too low and drifted across locales. Hoist the heading into the shell and place it in its own grid row spanning only the content column: row 1 holds the heading, row 2 holds the nav and the cards. The nav's first item and the first card now start the same grid row, so they align by construction regardless of how the title or subtitle wraps. Drop the spacer component.
This commit is contained in:
1 parent
ee16b05c93
commit
f67542d29e
6 files changed
+158
-132
No files matched your search
@@ -224,21 +224,16 @@ export function AdminSectionRenderer({
|
||||
}
|
||||
|
||||
interface SectionFrameProps {
|
||||
title: string;
|
||||
// v1.18.6.1 — the visible heading + subtitle moved to `<AdminShell>`, which
|
||||
// places them in their own grid row so the left nav lines up with the first
|
||||
// card. `title` / `subtitle` are still passed by every call site (and remain
|
||||
// the i18n source of truth the shell reads), but the frame no longer paints
|
||||
// them — it is now just the `space-y-6` card-stack wrapper.
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
function SectionFrame({ title, subtitle, children }: SectionFrameProps) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{title}</h1>
|
||||
{subtitle && (
|
||||
<p className="text-muted-foreground text-sm">{subtitle}</p>
|
||||
)}
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
function SectionFrame({ children }: SectionFrameProps) {
|
||||
return <div className="space-y-6">{children}</div>;
|
||||
}
|
||||
@@ -30,13 +30,8 @@ export default function AdminOverviewPage() {
|
||||
return (
|
||||
<AdminShell>
|
||||
<div className="space-y-6">
|
||||
<header>
|
||||
<h1 className="text-2xl font-bold tracking-tight">
|
||||
{t("admin.title")}
|
||||
</h1>
|
||||
<p className="text-muted-foreground text-sm">{t("admin.subtitle")}</p>
|
||||
</header>
|
||||
|
||||
{/* v1.18.6.1 — the console title + subtitle render in `<AdminShell>`
|
||||
now (its own grid row, so the nav lines up with the first card). */}
|
||||
{settingsError && (
|
||||
<div
|
||||
role="alert"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { JSX, ReactNode } from "react";
|
||||
import type { JSX } from "react";
|
||||
|
||||
import { AccountSection } from "@/components/settings/account-section";
|
||||
import { AboutSection } from "@/components/settings/about-section";
|
||||
@@ -29,9 +29,6 @@ import {
|
||||
type SettingsSectionSlug,
|
||||
} from "@/components/settings/section-slugs";
|
||||
import { SettingsShell } from "@/components/settings/settings-shell";
|
||||
import { SettingsSectionFrame } from "@/components/settings/settings-section-frame";
|
||||
import { SettingsHubBackLink } from "@/components/settings/settings-hub-back-link";
|
||||
import { ModuleTourTrigger } from "@/components/onboarding/module-tour-trigger";
|
||||
|
||||
/**
|
||||
* Dynamic settings section route. Each of the `SETTINGS_SECTION_SLUGS`
|
||||
@@ -74,50 +71,6 @@ const SECTION_COMPONENTS: Record<
|
||||
advanced: AdvancedSection,
|
||||
};
|
||||
|
||||
// v1.18.6 (W9) — the two Layout-hub child editors render a "← back to hub"
|
||||
// link above their heading. The shared `<SettingsSectionFrame>` exposes a
|
||||
// `topSlot` for exactly this; the link lives here so the section bodies stay
|
||||
// pure card content.
|
||||
const HUB_CHILD_SLUGS: ReadonlySet<SettingsSectionSlug> = new Set([
|
||||
"dashboard",
|
||||
"insights",
|
||||
]);
|
||||
|
||||
/** Optional content rendered above the canonical heading, per slug. */
|
||||
function frameTopSlot(slug: SettingsSectionSlug): ReactNode {
|
||||
if (HUB_CHILD_SLUGS.has(slug)) {
|
||||
return (
|
||||
<SettingsHubBackLink
|
||||
href="/settings/layout"
|
||||
labelKey="settings.sections.layout.backToHub"
|
||||
/>
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Optional inline content rendered at the top-right of the heading row. */
|
||||
function frameHeadingAccessory(slug: SettingsSectionSlug): ReactNode {
|
||||
// v1.18.6 (W9) — the module guided-tour re-entry triggers used to live in
|
||||
// a `justify-end` header inside the section body; they move to the frame's
|
||||
// heading row so the heading itself is the spotlight anchor.
|
||||
if (slug === "gesundheitsakte") {
|
||||
return (
|
||||
<span data-tour-id="export-hero">
|
||||
<ModuleTourTrigger stopId="export" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (slug === "integrations") {
|
||||
return (
|
||||
<span data-tour-id="integrations-hero">
|
||||
<ModuleTourTrigger stopId="integrations" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface PageProps {
|
||||
// Next.js 16 made route `params` an async Promise. We `await` it before use.
|
||||
params: Promise<{ section: string }>;
|
||||
@@ -138,17 +91,19 @@ export default async function SettingsSectionPage({ params }: PageProps) {
|
||||
// guards the slug, but a future slug added to `SETTINGS_SECTION_SLUGS`
|
||||
// without a wired component would otherwise crash silently — placeholder
|
||||
// surfaces the gap visually instead.
|
||||
// v1.18.6 (W9) — every section now renders inside the shared
|
||||
// `<SettingsSectionFrame>`, which emits the one visible heading + subtitle
|
||||
// each page must show (the section bodies no longer carry their own).
|
||||
// v1.18.6.1 — the heading + subtitle (and the Layout-hub "← back" link)
|
||||
// now live in `<SettingsShell>`, which places them in their own grid row
|
||||
// spanning only the content column so the left nav's first item lines up
|
||||
// with the top of the first card. The page body is pure card content,
|
||||
// wrapped in the labelled `<section>` so the historic
|
||||
// `settings-section-<slug>-title` `aria-labelledby` linkage still resolves.
|
||||
const body = SectionComponent ? (
|
||||
<SettingsSectionFrame
|
||||
slug={section}
|
||||
topSlot={frameTopSlot(section)}
|
||||
headingAccessory={frameHeadingAccessory(section)}
|
||||
<section
|
||||
aria-labelledby={`settings-section-${section}-title`}
|
||||
className="space-y-6"
|
||||
>
|
||||
<SectionComponent />
|
||||
</SettingsSectionFrame>
|
||||
</section>
|
||||
) : (
|
||||
<SectionPlaceholder slug={section} />
|
||||
);
|
||||
|
||||
@@ -40,7 +40,6 @@ import { cn } from "@/lib/utils";
|
||||
import { scrollBehaviorForUser } from "@/lib/motion";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { SectionNavHeadingSpacer } from "@/components/settings/section-nav-heading-spacer";
|
||||
import { isAdminSectionSlug, type AdminSectionSlug } from "./section-slugs";
|
||||
|
||||
interface AdminSection {
|
||||
@@ -208,6 +207,24 @@ export function AdminShell({ active, children }: AdminShellProps) {
|
||||
// children — until the role is confirmed ADMIN.
|
||||
if (!user || user.role !== "ADMIN") return null;
|
||||
|
||||
// v1.18.6.1 — the heading lives in the shell so it can occupy its own grid
|
||||
// row spanning only the content column; the nav's first item then lines up
|
||||
// with the top of the first card by construction. `/admin` overview
|
||||
// (activeSlug === null) shows the console title; each section shows its own.
|
||||
const headingTitle =
|
||||
activeSlug === null ? t("admin.title") : t(`admin.section.${activeSlug}.title`);
|
||||
const headingSubtitle =
|
||||
activeSlug === null
|
||||
? t("admin.subtitle")
|
||||
: t(`admin.section.${activeSlug}.subtitle`);
|
||||
|
||||
const headingBlock = (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{headingTitle}</h1>
|
||||
<p className="text-muted-foreground text-sm">{headingSubtitle}</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
// v1.4.25 W8 — AuthShell wraps the page in `px-4 py-6 md:px-6`
|
||||
// already, so this inner shell only carries the wider max-width.
|
||||
// Previously the duplicate `px-4 py-6 md:px-6 md:py-8` here was
|
||||
@@ -215,6 +232,10 @@ export function AdminShell({ active, children }: AdminShellProps) {
|
||||
// pages than on Dashboard/Insights/Measurements.
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-screen-xl">
|
||||
{/* v1.18.6.1 — heading above the chip strip on mobile; on desktop it
|
||||
renders inside the grid (row 1 / content column). */}
|
||||
<div className="mb-4 md:hidden">{headingBlock}</div>
|
||||
|
||||
{/* Mobile section strip — horizontal scroll, hidden on md+.
|
||||
`no-scrollbar` (defined in `globals.css`) suppresses the
|
||||
painted scrollbar at the top of every admin page; the
|
||||
@@ -278,16 +299,22 @@ export function AdminShell({ active, children }: AdminShellProps) {
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-[220px_1fr]">
|
||||
{/* Desktop sticky sidebar */}
|
||||
{/* v1.18.6.1 — two-row grid: heading in row 1 / col 2, nav in row 2 /
|
||||
col 1, cards in row 2 / col 2. The nav's first item starts the same
|
||||
grid row as the first card, so they align by construction across
|
||||
locales and however the heading wraps — no fixed-height spacer. */}
|
||||
<div className="grid gap-6 md:grid-cols-[220px_1fr] md:grid-rows-[auto_1fr]">
|
||||
{/* Heading — desktop only (mobile renders it above the strip). */}
|
||||
<div className="hidden md:col-start-2 md:row-start-1 md:block">
|
||||
{headingBlock}
|
||||
</div>
|
||||
|
||||
{/* Desktop sticky sidebar — starts at the cards row (row 2). */}
|
||||
<aside
|
||||
aria-label={t("admin.shell.sectionsNav")}
|
||||
className="hidden md:block"
|
||||
className="hidden md:col-start-1 md:row-start-2 md:block"
|
||||
>
|
||||
<div className="sticky top-20">
|
||||
{/* v1.18.6 (W9) — align the first nav item with the top of the
|
||||
first card, matching the settings shell. */}
|
||||
<SectionNavHeadingSpacer />
|
||||
<ul className="space-y-1">
|
||||
<li>
|
||||
<Link
|
||||
@@ -329,12 +356,14 @@ export function AdminShell({ active, children }: AdminShellProps) {
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* Main column — page renders its own h1 + subtitle. Same
|
||||
{/* Main column (cards) — row 2 / col 2. Same
|
||||
`min-h-[calc(100dvh-12rem)]` reserve as `<SettingsShell>`
|
||||
so navigating between admin sub-pages (e.g. system-status
|
||||
→ login-overview) does not jump the page height while the
|
||||
new section is still fetching. */}
|
||||
<main className="min-h-[calc(100dvh-12rem)] min-w-0">{children}</main>
|
||||
<main className="min-h-[calc(100dvh-12rem)] min-w-0 md:col-start-2 md:row-start-2">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* `<SectionNavHeadingSpacer>` — invisible spacer that reserves exactly the
|
||||
* height of a section's heading block (h1 + subtitle) plus the `space-y-6`
|
||||
* gap that separates the heading from the first card.
|
||||
*
|
||||
* v1.18.6 (W9) — Marc's symmetry ask: the left settings / admin menu's first
|
||||
* item must line up with the TOP OF THE FIRST CARD, not with the page
|
||||
* heading. The page heading lives in the content column above the first card,
|
||||
* so the sidebar needs to start one heading-block lower. Replicating the
|
||||
* exact heading markup (same `text-2xl` h1 + `text-sm` subtitle) as a hidden,
|
||||
* `aria-hidden` block keeps the offset pixel-accurate across locales and
|
||||
* line-wrapping — a hard-coded `pt-[…]` would drift the moment a title or
|
||||
* subtitle wraps to a second line.
|
||||
*
|
||||
* It is only rendered on `md+` (the desktop sticky sidebar); the mobile chip
|
||||
* strip has no heading-to-align-with.
|
||||
*
|
||||
* v1.18.6 (L11) — pass the active section's resolved `title` so the h1 line
|
||||
* wraps identically when a locale's title runs to two lines, rather than
|
||||
* reserving a single ` ` line. The subtitle copy lives per-page in the
|
||||
* section frame and is not threaded up here, so the spacer reserves one
|
||||
* subtitle line; a subtitle that wraps to two lines in a given locale is the
|
||||
* residual known limitation the original comment called out.
|
||||
*/
|
||||
export function SectionNavHeadingSpacer({ title }: { title?: string }) {
|
||||
return (
|
||||
<div aria-hidden="true" className="invisible mb-6 select-none">
|
||||
<h1 className="text-2xl font-bold tracking-tight">{title || " "}</h1>
|
||||
<p className="text-muted-foreground text-sm"> </p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
isSettingsSectionSlug,
|
||||
type SettingsSectionSlug,
|
||||
} from "./section-slugs";
|
||||
import { SectionNavHeadingSpacer } from "./section-nav-heading-spacer";
|
||||
import { SettingsHubBackLink } from "./settings-hub-back-link";
|
||||
|
||||
// Re-export so existing call-sites importing from this module keep working.
|
||||
// New server-side call-sites (e.g. `generateStaticParams()`) should import
|
||||
@@ -211,6 +211,28 @@ export interface SettingsShellProps {
|
||||
* pass an explicit value so they don't need to mock the router.
|
||||
*/
|
||||
active?: SettingsSectionSlug;
|
||||
/**
|
||||
* v1.18.6.1 — the page heading + subtitle now live in the shell, not in
|
||||
* the section body. The shell places them in their own grid row that
|
||||
* spans ONLY the content column, so the left nav's first item lines up
|
||||
* with the top of the first card by construction — no fixed-height
|
||||
* spacer to drift across locales or subtitle line-wraps.
|
||||
*
|
||||
* Title comes from `settings.sections.<active>.title` when omitted; pass
|
||||
* an explicit value for the per-module pages (Vorsorge / Illness / Labs)
|
||||
* that stay out of the slug registry. `headingId` keeps the historic
|
||||
* `settings-section-<slug>-title` anchor for `aria-labelledby` and the
|
||||
* spotlight tour.
|
||||
*/
|
||||
heading?: {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
headingId: string;
|
||||
/** Rendered above the heading (e.g. a "← back to hub" link). */
|
||||
topSlot?: React.ReactNode;
|
||||
/** Rendered inline at the top-right of the heading row. */
|
||||
headingAccessory?: React.ReactNode;
|
||||
};
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
@@ -246,7 +268,11 @@ function deriveActiveSlug(
|
||||
return isSettingsSectionSlug(candidate) ? candidate : "account";
|
||||
}
|
||||
|
||||
export function SettingsShell({ active, children }: SettingsShellProps) {
|
||||
export function SettingsShell({
|
||||
active,
|
||||
heading,
|
||||
children,
|
||||
}: SettingsShellProps) {
|
||||
const pathname = usePathname();
|
||||
const { t } = useTranslations();
|
||||
const { user } = useAuth();
|
||||
@@ -300,6 +326,53 @@ export function SettingsShell({ active, children }: SettingsShellProps) {
|
||||
});
|
||||
}, [activeSlug]);
|
||||
|
||||
// v1.18.6.1 — resolve the heading once. Pages pass an explicit `heading`
|
||||
// (the canonical path); the slug fallback keeps the shell renderable on
|
||||
// its own (and in tests that mount it without a heading) by deriving the
|
||||
// title from the active section. The heading lives in the shell so it can
|
||||
// occupy its own grid row spanning only the content column — see the grid
|
||||
// below.
|
||||
const resolvedHeading =
|
||||
heading ??
|
||||
(activeSection
|
||||
? {
|
||||
title: t(activeSection.titleKey),
|
||||
subtitle: t(`settings.sections.${activeSection.slug}.subtitle`),
|
||||
headingId: `settings-section-${activeSection.slug}-title`,
|
||||
topSlot: LAYOUT_CHILD_SLUGS.has(activeSection.slug) ? (
|
||||
<SettingsHubBackLink
|
||||
href="/settings/layout"
|
||||
labelKey="settings.sections.layout.backToHub"
|
||||
/>
|
||||
) : undefined,
|
||||
headingAccessory: undefined,
|
||||
}
|
||||
: null);
|
||||
|
||||
const headingBlock = resolvedHeading ? (
|
||||
<div className="space-y-6">
|
||||
{resolvedHeading.topSlot ? <div>{resolvedHeading.topSlot}</div> : null}
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="min-w-0">
|
||||
<h1
|
||||
id={resolvedHeading.headingId}
|
||||
className="text-2xl font-bold tracking-tight"
|
||||
>
|
||||
{resolvedHeading.title}
|
||||
</h1>
|
||||
{resolvedHeading.subtitle ? (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{resolvedHeading.subtitle}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
{resolvedHeading.headingAccessory ? (
|
||||
<div className="shrink-0">{resolvedHeading.headingAccessory}</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
// v1.4.25 W8 — AuthShell wraps the page in `px-4 py-6 md:px-6`
|
||||
// already, so this inner shell only carries the wider max-width.
|
||||
// Previously the duplicate `px-4 py-6 md:px-6 md:py-8` here was
|
||||
@@ -307,6 +380,11 @@ export function SettingsShell({ active, children }: SettingsShellProps) {
|
||||
// pages than on Dashboard/Insights/Measurements.
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-screen-xl">
|
||||
{/* v1.18.6.1 — on mobile the heading sits above the chip strip; on
|
||||
desktop it is rendered inside the grid (row 1 / content column) so
|
||||
it does not paint twice. */}
|
||||
{headingBlock ? <div className="mb-4 md:hidden">{headingBlock}</div> : null}
|
||||
|
||||
{/* Mobile section strip — horizontal scroll, hidden on md+.
|
||||
`no-scrollbar` (defined in `globals.css`) suppresses the
|
||||
painted scrollbar; the horizontal swipe + keyboard arrow
|
||||
@@ -354,22 +432,28 @@ export function SettingsShell({ active, children }: SettingsShellProps) {
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-[220px_1fr]">
|
||||
{/* Desktop sticky sidebar */}
|
||||
{/* v1.18.6.1 — two-row grid on desktop:
|
||||
row 1 / col 2 = heading (content column only)
|
||||
row 2 / col 1 = nav row 2 / col 2 = cards
|
||||
The nav's first item lines up with the top of the first card BY
|
||||
CONSTRUCTION — both start the grid's second row — so the alignment
|
||||
holds across locales and however the title or subtitle wraps. No
|
||||
fixed-height spacer to guess. The `gap-6` between rows reproduces
|
||||
the `space-y-6` the heading-to-first-card gap used to carry. */}
|
||||
<div className="grid gap-6 md:grid-cols-[220px_1fr] md:grid-rows-[auto_1fr]">
|
||||
{/* Heading — desktop only here (mobile renders it above the strip). */}
|
||||
{headingBlock ? (
|
||||
<div className="hidden md:col-start-2 md:row-start-1 md:block">
|
||||
{headingBlock}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Desktop sticky sidebar — starts at the cards row (row 2). */}
|
||||
<aside
|
||||
aria-label={t("settings.shell.sectionsNav")}
|
||||
className="hidden md:block"
|
||||
className="hidden md:col-start-1 md:row-start-2 md:block"
|
||||
>
|
||||
<div className="sticky top-20">
|
||||
{/* v1.18.6 (W9) — push the first nav item down to the top of the
|
||||
first card (level with the page heading's following gap), so
|
||||
the menu reads symmetric with the content column. Feed the
|
||||
active title so the spacer's h1 wraps the same way (L11). */}
|
||||
<SectionNavHeadingSpacer
|
||||
title={
|
||||
activeSection ? t(activeSection.titleKey) : undefined
|
||||
}
|
||||
/>
|
||||
<ul className="space-y-1">
|
||||
{visibleSections.map((section) => {
|
||||
const isActive = section.slug === activeSlug;
|
||||
@@ -412,7 +496,7 @@ export function SettingsShell({ active, children }: SettingsShellProps) {
|
||||
v1.16.4 — a `<div>`, not `<main>`: the surrounding AuthShell
|
||||
already provides the page's single `<main>` landmark and a
|
||||
nested second one is an a11y violation. */}
|
||||
<div className="min-h-[calc(100dvh-12rem)] min-w-0 pb-24 md:pb-0">
|
||||
<div className="min-h-[calc(100dvh-12rem)] min-w-0 pb-24 md:col-start-2 md:row-start-2 md:pb-0">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user