diff --git a/CLAUDE.md b/CLAUDE.md index 935c77c..a0009b6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -181,6 +181,8 @@ Everything else here is convention, and the import-alias rule in particular has - Prefer short-circuit (`&&`) over a ternary when the else branch is `null` or `undefined`, especially in React rendering. Do: `{isActive && }`. Don't: `{isActive ? : null}`. Guard the condition so it is a real boolean (`!!count && ...`), never a bare number that could render `0`. - Prefer optional chaining (`?.`). When optional chaining is used, ALWAYS pair it with nullish coalescing (`??`) to supply a fallback. - Prefer a single configurable object parameter over multiple positional parameters so argument order doesn't matter. Don't: `doSomething(foo, bar, hello)`. Do: `doSomething({ foo, bar, hello })`. +- A comment that fits on one line uses `//`. A comment that spans more than one line uses one block, `/* ... */`, or `/** ... */` when it documents an export, a type or one of its fields. Never stack `//` lines into a paragraph, and never wrap a one-line comment in `/* */`. +- Exceptions: comments inside JSX stay `{/* ... */}`, since JSX has no `//`; a trailing comment after code on the same line is always `//`; and a `/** ... */` doc comment that fits on one line stays as it is, because editors only show `/** */` comments on hover. ## Accessibility diff --git a/apps/admin-portal/src/components/Chart/ChartLegend.tsx b/apps/admin-portal/src/components/Chart/ChartLegend.tsx index 211477c..f5fc3de 100644 --- a/apps/admin-portal/src/components/Chart/ChartLegend.tsx +++ b/apps/admin-portal/src/components/Chart/ChartLegend.tsx @@ -1,3 +1,4 @@ +import { classNames } from '@/components/Chart/classNames' import { swatchClass, type ChartMark } from '@/components/Chart/ChartTooltip' import styles from '@/components/Chart/chart.module.scss' @@ -12,20 +13,79 @@ export type ChartLegendItem = { readonly note?: string } +/** Which series the reader left off the plot, and how to flip one. A chart + takes this whole or not at all, so a hidden series always comes with the + checkbox that brings it back. */ +export type SeriesToggle = { + /** Keys of the series currently left off the plot. */ + readonly hidden: readonly string[] + readonly onToggle: (key: string) => void +} + +/** Lets the reader choose which series are drawn. Without it the legend is a + plain key. */ +export type ChartLegendToggle = SeriesToggle & { + /** Names the group of checkboxes for a screen reader, such as "Hosts shown + on the CPU chart". */ + readonly label: string +} + type ChartLegendProps = { readonly items: readonly ChartLegendItem[] readonly mark?: ChartMark + readonly toggle?: ChartLegendToggle } -/** What each mark on the plot stands for, named in words beside its colour. */ -export const ChartLegend = ({ items, mark = 'square' }: ChartLegendProps) => ( -