File size: 2,824 Bytes
23d418f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { type ReactNode, useState } from 'react'
import { SERIES, ORDER } from '@/lib/chart'
import type { SystemId } from '@/lib/types'

/** One claim of the Evals story: a title that states it, one sentence of takeaway, the
 * chart, and the numbers behind it as a table on demand (every chart has a table view:
 * the dataviz relief rule, and the honest way to read exact values). */
export function Section({
  id,
  title,
  takeaway,
  children,
  table,
}: {
  id: string
  title: string
  takeaway: ReactNode
  children: ReactNode
  table?: ReactNode
}) {
  const [showTable, setShowTable] = useState(false)
  return (
    <section id={id} className="scroll-mt-20 space-y-3">
      <h2 className="text-xl font-semibold tracking-tight">{title}</h2>
      <p className="max-w-3xl text-sm leading-relaxed text-muted-foreground">{takeaway}</p>
      <div className="rounded-2xl border bg-background p-4 sm:p-5">
        {children}
        {table && (
          <div className="mt-3 border-t pt-3">
            <button
              type="button"
              className="text-xs font-medium text-primary hover:underline"
              onClick={() => setShowTable(!showTable)}
              aria-expanded={showTable}
            >
              {showTable ? 'Hide the numbers' : 'Show the numbers'}
            </button>
            {showTable && <div className="mt-2 overflow-x-auto">{table}</div>}
          </div>
        )}
      </div>
    </section>
  )
}

/** The A / B / C legend: a colour swatch beside each name (identity never by colour
 * alone; text stays in ink colours). */
export function Legend({ names }: { names: Record<SystemId, string> }) {
  return (
    <ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
      {ORDER.map((s) => (
        <li key={s} className="flex items-center gap-1.5">
          <span className="size-2.5 rounded-sm" style={{ background: SERIES[s] }} aria-hidden />
          System {s.toUpperCase()} · {names[s]}
        </li>
      ))}
    </ul>
  )
}

/** A plain numbers table (the "Show the numbers" view). */
export function NumbersTable({ head, rows }: { head: string[]; rows: (string | number)[][] }) {
  return (
    <table className="w-full min-w-[28rem] text-left text-xs tabular-nums">
      <thead>
        <tr className="border-b text-muted-foreground">
          {head.map((h) => (
            <th key={h} className="py-1.5 pr-3 font-medium">
              {h}
            </th>
          ))}
        </tr>
      </thead>
      <tbody>
        {rows.map((row, i) => (
          <tr key={i} className="border-b last:border-0">
            {row.map((cell, j) => (
              <td key={j} className="py-1.5 pr-3">
                {cell}
              </td>
            ))}
          </tr>
        ))}
      </tbody>
    </table>
  )
}