Accessibility: skip link, labelled landmarks, visible focus, page-change announcements, sortable headings as real buttons, every label tied to its field, named row checkboxes, and text contrast raised to 4.5:1 in both themes. Command palette: also runs actions (silence/end maintenance, theme, density, wall display, sign out) and is a proper dialog; g-then-letter shortcuts, "/" and "?". Row detail panel for six tables. Server Activity card, with the health check now recording offline/back-online and disk events in the audit log. Map page of hosts, servers, DNS names and monitors. Full-screen wall display. A getting-started checklist on the admin dashboard. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { useState, type KeyboardEvent, type MouseEvent } from "react";
|
|
|
|
/**
|
|
* Makes the rows of a table open a detail panel. Spread `rowProps(item)` onto the row: a click or Enter on the row opens it, but
|
|
* a click on a button, link or tick-box inside the row does its own thing and leaves the panel alone.
|
|
*/
|
|
export function useRowDetail<T>() {
|
|
const [selected, setSelected] = useState<T | null>(null);
|
|
|
|
function rowProps(item: T) {
|
|
return {
|
|
className: "row-clickable",
|
|
tabIndex: 0,
|
|
"aria-haspopup": "dialog" as const,
|
|
onClick: (e: MouseEvent<HTMLElement>) => {
|
|
if ((e.target as HTMLElement).closest("a, button, input, select, textarea, label, summary")) return;
|
|
// The row takes the focus, so it is what the keyboard comes back to when the panel closes.
|
|
e.currentTarget.focus({ preventScroll: true });
|
|
setSelected(item);
|
|
},
|
|
onKeyDown: (e: KeyboardEvent<HTMLElement>) => {
|
|
if (e.key === "Enter" && e.target === e.currentTarget) {
|
|
e.preventDefault();
|
|
setSelected(item);
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
return { selected, close: () => setSelected(null), rowProps };
|
|
}
|