Chart page tabs (analysis, planets, matrix, details); square aspect matrix
CI / test (push) Successful in 40s
CI / build (push) Successful in 3m36s
CI / deploy (push) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 10:32:10 +00:00
co-authored by Claude Opus 5.5
parent d2a24ca42d
commit afa113ceca
5 changed files with 203 additions and 86 deletions
+73
View File
@@ -0,0 +1,73 @@
"use client";
import { type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from "react";
export type Tab = { id: string; label: string; content: ReactNode };
/**
* Tabs with the chosen one kept in the URL hash (#matrix), so a reload or a
* shared link opens the same tab. Hidden panels stay mounted: a running
* analysis keeps polling while another tab is open.
*/
export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {
const [active, setActive] = useState(tabs[0]?.id);
const buttons = useRef<(HTMLButtonElement | null)[]>([]);
useEffect(() => {
const fromHash = window.location.hash.slice(1);
if (tabs.some((t) => t.id === fromHash)) setActive(fromHash);
}, [tabs]);
function choose(id: string) {
setActive(id);
history.replaceState(null, "", `#${id}`);
}
function onKey(e: KeyboardEvent, i: number) {
const step = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
const to = e.key === "Home" ? 0 : e.key === "End" ? tabs.length - 1 : step ? (i + step + tabs.length) % tabs.length : -1;
if (to < 0) return;
e.preventDefault();
choose(tabs[to].id);
buttons.current[to]?.focus();
}
return (
<div className="tabs">
<div className="tab-list" role="tablist" aria-label={label}>
{tabs.map((t, i) => (
<button
key={t.id}
ref={(el) => {
buttons.current[i] = el;
}}
type="button"
role="tab"
id={`tab-${t.id}`}
aria-controls={`panel-${t.id}`}
aria-selected={active === t.id}
tabIndex={active === t.id ? 0 : -1}
className="tab"
onClick={() => choose(t.id)}
onKeyDown={(e) => onKey(e, i)}
>
{t.label}
</button>
))}
</div>
{tabs.map((t) => (
<div
key={t.id}
role="tabpanel"
id={`panel-${t.id}`}
aria-labelledby={`tab-${t.id}`}
hidden={active !== t.id}
className="tab-panel"
tabIndex={0}
>
{t.content}
</div>
))}
</div>
);
}