@dinachi/cli 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/index.js +244 -72
  3. package/package.json +5 -1
  4. package/templates/agent/agent.tsx +35 -18
  5. package/templates/alert/alert.tsx +345 -0
  6. package/templates/alert/index.ts +16 -0
  7. package/templates/ask-bar/ask-bar.tsx +1061 -0
  8. package/templates/ask-bar/index.ts +1 -0
  9. package/templates/autocomplete/autocomplete.tsx +0 -1
  10. package/templates/breadcrumb/breadcrumb.tsx +606 -0
  11. package/templates/breadcrumb/index.ts +9 -0
  12. package/templates/calendar/calendar.tsx +1155 -0
  13. package/templates/calendar/index.ts +15 -0
  14. package/templates/combobox/combobox.tsx +0 -1
  15. package/templates/command-items/command-items.tsx +69 -0
  16. package/templates/command-items/index.ts +1 -0
  17. package/templates/command-palette/command-palette.tsx +954 -0
  18. package/templates/command-palette/index.ts +1 -0
  19. package/templates/comparison-table/comparison-table.tsx +540 -0
  20. package/templates/comparison-table/index.ts +15 -0
  21. package/templates/data-table/data-table.tsx +2077 -0
  22. package/templates/data-table/index.ts +14 -0
  23. package/templates/date-picker/date-picker.tsx +527 -0
  24. package/templates/date-picker/index.ts +2 -0
  25. package/templates/date-range-picker/date-range-picker.tsx +504 -0
  26. package/templates/date-range-picker/index.ts +2 -0
  27. package/templates/detail-list/detail-list.tsx +419 -0
  28. package/templates/detail-list/index.ts +12 -0
  29. package/templates/heat-table/heat-table.tsx +613 -0
  30. package/templates/heat-table/index.ts +9 -0
  31. package/templates/menu/menu.tsx +8 -3
  32. package/templates/month-picker/index.ts +1 -0
  33. package/templates/month-picker/month-picker.tsx +351 -0
  34. package/templates/omnibar/index.ts +1 -0
  35. package/templates/omnibar/omnibar.tsx +1009 -0
  36. package/templates/pagination/index.ts +8 -0
  37. package/templates/pagination/pagination.tsx +389 -0
  38. package/templates/table/index.ts +13 -0
  39. package/templates/table/table.tsx +265 -0
  40. package/templates/time-slots/index.ts +1 -0
  41. package/templates/time-slots/time-slots.tsx +589 -0
  42. package/templates/week-strip/index.ts +1 -0
  43. package/templates/week-strip/week-strip.tsx +329 -0
  44. package/templates/year-view/index.ts +1 -0
  45. package/templates/year-view/year-view.tsx +362 -0
@@ -0,0 +1,613 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { useVirtualizer } from "@tanstack/react-virtual"
5
+ import { cn } from "@/lib/utils"
6
+ import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/table"
7
+
8
+ export interface HeatRow {
9
+ label: string
10
+ /** Shown after the label on desktop, such as the cohort's size. */
11
+ meta?: React.ReactNode
12
+ /** One value per column. `null` leaves the cell blank. */
13
+ values: (number | null | undefined)[]
14
+ }
15
+
16
+ export interface HeatCell<Row extends HeatRow = HeatRow> {
17
+ row: Row
18
+ rowIndex: number
19
+ column: string
20
+ columnIndex: number
21
+ value: number
22
+ }
23
+
24
+ export interface HeatScaleRange {
25
+ min: number
26
+ max: number
27
+ }
28
+
29
+ export interface HeatColumnGroup {
30
+ label: React.ReactNode
31
+ /** How many columns it spans. */
32
+ span: number
33
+ }
34
+
35
+ export interface HeatTableProps<Row extends HeatRow = HeatRow>
36
+ extends Omit<React.TableHTMLAttributes<HTMLTableElement>, "children"> {
37
+ /** The column names as printed over the cells. */
38
+ columns: string[]
39
+ /** Each column's full name for screen readers and cell names, such as "Wed 18 Nov 2026" over "18". Defaults to `columns`. */
40
+ columnLabels?: string[]
41
+ /** Spanning headers over the columns, such as months over days. */
42
+ columnGroups?: HeatColumnGroup[]
43
+ /** Column names below 768px, where each column is a narrow square. Defaults to `columns`. */
44
+ phoneColumns?: string[]
45
+ rows: Row[]
46
+ /** The name over the row labels, such as "Cohort". */
47
+ rowHeader?: React.ReactNode
48
+ /** A value as printed. Defaults to the number as it is. */
49
+ format?: (value: number, cell: HeatCell<Row>) => string
50
+ /** A cell's accessible name. Defaults to "{row}, {column}: {value}". */
51
+ label?: (cell: HeatCell<Row>) => string
52
+ /** The value that shades lightest. Defaults to the lowest value in `rows`. */
53
+ min?: number
54
+ /** The value that shades darkest. Defaults to the highest value in `rows`. */
55
+ max?: number
56
+ /** Maps a value to 0 to 1. Defaults to a straight line from `min` to `max`. */
57
+ scale?: (value: number, range: HeatScaleRange) => number
58
+ /** A summary row under the grid, such as the average. */
59
+ footer?: { label: React.ReactNode; values: React.ReactNode[] }
60
+ /** What the line under the grid says about the chosen cell on a phone. */
61
+ readout?: (cell: HeatCell<Row>) => React.ReactNode
62
+ /** The cell chosen at first, which takes the tab stop and fills the phone readout. Defaults to the first filled cell. */
63
+ defaultCell?: { row: number; column: number }
64
+ /** Cell size. Compact fits about twice the columns. */
65
+ density?: "comfortable" | "compact"
66
+ /** Height of the scrolling area in px. Virtualized grids default to 480. */
67
+ maxHeight?: number
68
+ /** Renders only the rows in view. For grids of thousands of rows. */
69
+ virtualize?: boolean
70
+ /** Keeps the column headers and row labels in view while the grid scrolls. Defaults to on once `maxHeight` is set. */
71
+ sticky?: boolean
72
+ /** Runs as the pointer enters a filled cell, and with `null` as it leaves the grid. */
73
+ onCellHover?: (cell: HeatCell<Row> | null) => void
74
+ /** Runs when a cell takes focus, by keyboard or click. */
75
+ onCellFocus?: (cell: HeatCell<Row>) => void
76
+ onCellClick?: (cell: HeatCell<Row>, event: React.MouseEvent<HTMLTableCellElement>) => void
77
+ /** Classes for the element that scrolls the grid. */
78
+ containerClassName?: string
79
+ /** The element that scrolls the grid. */
80
+ containerRef?: React.Ref<HTMLDivElement>
81
+ }
82
+
83
+ const linear = (value: number, { min, max }: HeatScaleRange) =>
84
+ max === min ? (value < min ? 0 : 1) : (value - min) / (max - min)
85
+ const plain = (value: number) => String(value)
86
+
87
+ const isValue = (v: number | null | undefined): v is number => typeof v === "number" && Number.isFinite(v)
88
+
89
+ /**
90
+ * The cell's shade: the primary colour mixed into the surface, with text that stays readable
91
+ * on it. The mix skips 34% to 55%, where neither text colour reaches 4.5:1 on either theme.
92
+ */
93
+ export function heatShade(amount: number): React.CSSProperties {
94
+ const a = Math.min(1, Math.max(0, Number.isNaN(amount) ? 0 : amount))
95
+ const dark = a > 0.5
96
+ return {
97
+ background: `color-mix(in oklab, var(--primary) ${Math.round(dark ? 56 + (a - 0.5) * 60 : 6 + a * 54)}%, var(--card))`,
98
+ color: dark ? "var(--primary-foreground)" : "var(--card-foreground)",
99
+ }
100
+ }
101
+
102
+ type At = { r: number; c: number }
103
+
104
+ const SIZES = {
105
+ comfortable: { width: 56, height: 38, text: "12.5px" },
106
+ compact: { width: 32, height: 26, text: "11px" },
107
+ }
108
+ // Up to this many columns fit a phone as squares; past it they keep a size and scroll.
109
+ const PHONE_FIT = 12
110
+ const GAP = 3
111
+
112
+ const radius = "rounded-[min(0.375rem,var(--radius,0.375rem))]"
113
+ const tint = "color-mix(in_oklab,var(--foreground)_9%,transparent)"
114
+ // A tint as well as the text colour, since themes often set muted text close to the foreground.
115
+ // It is a background image so a sticky header keeps its opaque surface under it.
116
+ const lift = cn(
117
+ radius,
118
+ "transition-colors duration-100 motion-reduce:transition-none data-[active]:text-foreground",
119
+ `data-[active]:bg-[linear-gradient(${tint},${tint})]`
120
+ )
121
+ const surface = "bg-[var(--heat-table-surface,var(--background))]"
122
+ // Square corners and a halo over the border spacing, or cells scrolling under show through.
123
+ const pinned = cn("md:rounded-none md:shadow-[0_0_0_3px_var(--heat-table-surface,var(--background))]", surface)
124
+
125
+ const box = (fit: boolean) =>
126
+ cn(
127
+ "flex h-[var(--heat-table-cell-height)] w-[var(--heat-table-cell-width)] items-center justify-center",
128
+ radius,
129
+ fit ? "max-md:aspect-square max-md:h-auto max-md:w-full max-md:rounded-[5px]" : "max-md:h-7 max-md:w-7 max-md:rounded-[5px]"
130
+ )
131
+
132
+ const atOf = (el: EventTarget | null): { at: At; el: HTMLTableCellElement } | null => {
133
+ const td = (el as HTMLElement | null)?.closest?.<HTMLTableCellElement>("td[data-cell]")
134
+ if (!td) return null
135
+ const [r, c] = td.getAttribute("data-cell")!.split("-").map(Number)
136
+ return { at: { r, c }, el: td }
137
+ }
138
+
139
+ interface Shared<Row extends HeatRow> {
140
+ columns: string[]
141
+ names: string[]
142
+ format: (value: number, cell: HeatCell<Row>) => string
143
+ label?: (cell: HeatCell<Row>) => string
144
+ scale: (value: number, range: HeatScaleRange) => number
145
+ range: HeatScaleRange
146
+ fit: boolean
147
+ sticky: boolean
148
+ }
149
+
150
+ interface BodyRowProps<Row extends HeatRow> {
151
+ row: Row
152
+ r: number
153
+ /** The chosen column when this row holds the chosen cell, or -1. */
154
+ chosen: number
155
+ shared: Shared<Row>
156
+ index?: number
157
+ }
158
+
159
+ // Memoised so a new choice draws only the two rows it touches. Hover never renders at all.
160
+ const HeatBodyRow = React.memo(function HeatBodyRow<Row extends HeatRow>({ row, r, chosen, shared, index }: BodyRowProps<Row>) {
161
+ const { columns, names, format, label, scale, range, fit, sticky } = shared
162
+ return (
163
+ <TableRow role="row" aria-rowindex={index === undefined ? undefined : index + 2}>
164
+ <TableHead
165
+ role="rowheader"
166
+ className={cn(
167
+ "h-auto pe-2 ps-1 text-[11.5px] font-medium text-muted-foreground max-md:text-xs",
168
+ lift,
169
+ sticky && cn("md:sticky md:left-0 md:z-[1]", pinned)
170
+ )}
171
+ >
172
+ {row.label}
173
+ {row.meta != null && (
174
+ <span className="ms-2 font-normal text-muted-foreground max-md:hidden">
175
+ <span className="sr-only">,</span> {row.meta}
176
+ </span>
177
+ )}
178
+ </TableHead>
179
+ {columns.map((column, c) => {
180
+ const value = row.values[c]
181
+ if (!isValue(value))
182
+ return (
183
+ <TableCell key={c} role="gridcell" className="h-auto p-0">
184
+ <span data-slot="heat-table-blank" aria-hidden className={cn("block", box(fit))} />
185
+ </TableCell>
186
+ )
187
+ const cell: HeatCell<Row> = { row, rowIndex: r, column, columnIndex: c, value }
188
+ const printed = format(value, cell)
189
+ const isChosen = chosen === c
190
+ return (
191
+ <TableCell
192
+ key={c}
193
+ role="gridcell"
194
+ data-cell={`${r}-${c}`}
195
+ data-selected={isChosen || undefined}
196
+ aria-selected={isChosen}
197
+ tabIndex={isChosen ? 0 : -1}
198
+ aria-label={label ? label(cell) : `${row.label}, ${names[c]}: ${printed}`}
199
+ className="group h-auto cursor-default p-0 outline-none"
200
+ >
201
+ <span
202
+ data-slot="heat-table-cell"
203
+ style={heatShade(scale(value, range))}
204
+ className={cn(
205
+ box(fit),
206
+ "transition-shadow duration-100 motion-reduce:transition-none",
207
+ "group-focus-visible:shadow-[0_0_0_2px_var(--foreground)] md:group-data-[active]:shadow-[0_0_0_2px_var(--foreground)]",
208
+ "max-md:group-data-[selected]:shadow-[0_0_0_2px_var(--background),0_0_0_4px_var(--foreground)]"
209
+ )}
210
+ >
211
+ <span className="max-md:hidden" aria-hidden>
212
+ {printed}
213
+ </span>
214
+ </span>
215
+ </TableCell>
216
+ )
217
+ })}
218
+ </TableRow>
219
+ )
220
+ }) as <Row extends HeatRow>(props: BodyRowProps<Row>) => React.ReactElement
221
+
222
+ function setRef<V>(ref: React.Ref<V> | undefined, value: V | null) {
223
+ if (typeof ref === "function") ref(value)
224
+ else if (ref) (ref as React.MutableRefObject<V | null>).current = value
225
+ }
226
+
227
+ /**
228
+ * A grid of values shaded by size, with the number always printed so colour is never the
229
+ * only signal. Pointing at a cell lights its row and column headers. Below 768px the cells
230
+ * become squares and the chosen one is read out under the grid.
231
+ */
232
+ function HeatTableInner<Row extends HeatRow>(props: HeatTableProps<Row>, ref: React.ForwardedRef<HTMLTableElement>) {
233
+ const {
234
+ columns,
235
+ columnLabels,
236
+ columnGroups,
237
+ phoneColumns,
238
+ rows,
239
+ rowHeader,
240
+ format = plain,
241
+ label,
242
+ min: minProp,
243
+ max: maxProp,
244
+ scale = linear,
245
+ footer,
246
+ readout,
247
+ defaultCell,
248
+ density = "comfortable",
249
+ virtualize = false,
250
+ maxHeight: maxHeightProp,
251
+ sticky: stickyProp,
252
+ onCellHover,
253
+ onCellFocus,
254
+ onCellClick,
255
+ className,
256
+ containerClassName,
257
+ containerRef,
258
+ style,
259
+ onFocus,
260
+ onBlur,
261
+ onClick,
262
+ onKeyDown,
263
+ onMouseOver,
264
+ onMouseLeave,
265
+ ...rest
266
+ } = props
267
+ const maxHeight = maxHeightProp ?? (virtualize ? 480 : undefined)
268
+ const sticky = stickyProp ?? maxHeight !== undefined
269
+ const n = columns.length
270
+ const fit = n <= PHONE_FIT
271
+
272
+ // A loop, since spreading a large grid into Math.min overflows the stack.
273
+ const range = React.useMemo<HeatScaleRange>(() => {
274
+ let lo = Infinity
275
+ let hi = -Infinity
276
+ if (minProp === undefined || maxProp === undefined)
277
+ for (const row of rows)
278
+ for (let c = 0; c < n; c++) {
279
+ const v = row.values[c]
280
+ if (!isValue(v)) continue
281
+ if (v < lo) lo = v
282
+ if (v > hi) hi = v
283
+ }
284
+ const min = minProp ?? lo
285
+ // A max under the min would turn the scale upside down.
286
+ return { min, max: Math.max(min, maxProp ?? hi) }
287
+ }, [rows, n, minProp, maxProp])
288
+
289
+ const has = (at: At | null): at is At => !!at && at.c < n && isValue(rows[at.r]?.values[at.c])
290
+ const scan = (from: At, dr: number, dc: number): At | undefined => {
291
+ for (let r = from.r + dr, c = from.c + dc; r >= 0 && r < rows.length && c >= 0 && c < n; r += dr, c += dc)
292
+ if (isValue(rows[r].values[c])) return { r, c }
293
+ }
294
+ const first = React.useMemo(() => {
295
+ for (let r = 0; r < rows.length; r++) for (let c = 0; c < n; c++) if (isValue(rows[r].values[c])) return { r, c }
296
+ return null
297
+ }, [rows, n])
298
+ const last = () => {
299
+ for (let r = rows.length - 1; r >= 0; r--) for (let c = n - 1; c >= 0; c--) if (isValue(rows[r].values[c])) return { r, c }
300
+ }
301
+
302
+ const [chosen, setChosen] = React.useState<At | null>(defaultCell ? { r: defaultCell.row, c: defaultCell.column } : null)
303
+ const current = has(chosen) ? chosen : first
304
+
305
+ const names = React.useMemo(() => columns.map((column, c) => columnLabels?.[c] ?? column), [columns, columnLabels])
306
+ const shared = React.useMemo<Shared<Row>>(
307
+ () => ({ columns, names, format, label, scale, range, fit, sticky }),
308
+ [columns, names, format, label, scale, range, fit, sticky]
309
+ )
310
+ const cellOf = (at: At): HeatCell<Row> => ({
311
+ row: rows[at.r],
312
+ rowIndex: at.r,
313
+ column: columns[at.c],
314
+ columnIndex: at.c,
315
+ value: rows[at.r].values[at.c] as number,
316
+ })
317
+
318
+ const grid = React.useRef<HTMLTableElement | null>(null)
319
+ const [scroller, setScroller] = React.useState<HTMLDivElement | null>(null)
320
+ const scrollRef = React.useCallback(
321
+ (el: HTMLDivElement | null) => {
322
+ setScroller(el)
323
+ setRef(containerRef, el)
324
+ },
325
+ [containerRef]
326
+ )
327
+
328
+ /* ---- lighting, kept out of React so pointing at a cell renders nothing ---- */
329
+ const hovered = React.useRef<HTMLTableCellElement | null>(null)
330
+ const focused = React.useRef<HTMLTableCellElement | null>(null)
331
+ const lit = React.useRef<HTMLElement[]>([])
332
+ const paint = () => {
333
+ for (const el of lit.current) el.removeAttribute("data-active")
334
+ lit.current = []
335
+ const td = hovered.current?.isConnected ? hovered.current : focused.current?.isConnected ? focused.current : null
336
+ if (!td) return
337
+ const c = Number(td.getAttribute("data-cell")!.split("-")[1])
338
+ const on = [td.parentElement?.firstElementChild, grid.current?.querySelector(`thead th[data-column="${c}"]`)]
339
+ // Hover rings the cell; focus has its own ring.
340
+ if (td === hovered.current) on.push(td)
341
+ for (const el of on)
342
+ if (el instanceof HTMLElement) {
343
+ el.setAttribute("data-active", "")
344
+ lit.current.push(el)
345
+ }
346
+ }
347
+
348
+ /* ---- virtualisation ---- */
349
+ const size = SIZES[density]
350
+ const virtualizer = useVirtualizer({
351
+ count: virtualize ? rows.length : 0,
352
+ getScrollElement: () => scroller,
353
+ // Cells are a fixed size, so the estimate is the height.
354
+ estimateSize: () => size.height + GAP,
355
+ overscan: 6,
356
+ initialRect: { width: 0, height: maxHeight ?? 480 },
357
+ })
358
+ React.useEffect(() => {
359
+ if (virtualize) virtualizer.measure()
360
+ }, [virtualize, virtualizer, size.height])
361
+
362
+ /* ---- keyboard ---- */
363
+ const pending = React.useRef<At | null>(null)
364
+ const focusAt = (to: At) => {
365
+ const el = grid.current?.querySelector<HTMLElement>(`[data-cell="${to.r}-${to.c}"]`)
366
+ if (el) {
367
+ pending.current = null
368
+ el.focus()
369
+ } else pending.current = to
370
+ }
371
+ React.useLayoutEffect(() => {
372
+ if (pending.current) focusAt(pending.current)
373
+ })
374
+ const move = (to: At | undefined | null) => {
375
+ if (!to) return
376
+ setChosen(to)
377
+ if (virtualize) virtualizer.scrollToIndex(to.r, { align: "auto" })
378
+ focusAt(to)
379
+ }
380
+ const keys = (event: React.KeyboardEvent, at: At) => {
381
+ const ctrl = event.ctrlKey || event.metaKey
382
+ const step: Record<string, () => At | undefined | null> = {
383
+ ArrowRight: () => scan(at, 0, 1),
384
+ ArrowLeft: () => scan(at, 0, -1),
385
+ ArrowDown: () => scan(at, 1, 0),
386
+ ArrowUp: () => scan(at, -1, 0),
387
+ Home: () => (ctrl ? first : scan({ r: at.r, c: -1 }, 0, 1)),
388
+ End: () => (ctrl ? last() : scan({ r: at.r, c: n }, 0, -1)),
389
+ }
390
+ const go = step[event.key]
391
+ if (!go) return
392
+ event.preventDefault()
393
+ move(go())
394
+ }
395
+
396
+ const shown = current ? cellOf(current) : null
397
+ const bodyRow = (row: Row, r: number, index?: number) => (
398
+ <HeatBodyRow<Row>
399
+ key={r}
400
+ row={row}
401
+ r={r}
402
+ chosen={current?.r === r ? current.c : -1}
403
+ shared={shared}
404
+ index={index}
405
+ />
406
+ )
407
+ const items = virtualize ? virtualizer.getVirtualItems() : []
408
+ const top = items[0]?.start ?? 0
409
+ const bottom = virtualize ? virtualizer.getTotalSize() - (items[items.length - 1]?.end ?? 0) : 0
410
+ const spacer = (height: number) =>
411
+ height > 0 && (
412
+ <tr data-spacer aria-hidden>
413
+ <td colSpan={n + 1} style={{ height: Math.max(0, height - GAP), padding: 0 }} />
414
+ </tr>
415
+ )
416
+ const headerRows = columnGroups?.length ? 2 : 1
417
+
418
+ return (
419
+ <div
420
+ data-slot="heat-table"
421
+ data-density={density}
422
+ className="w-full"
423
+ style={
424
+ {
425
+ "--heat-table-cell-width": `${size.width}px`,
426
+ "--heat-table-cell-height": `${size.height}px`,
427
+ ...(maxHeight !== undefined && { "--heat-table-max-height": `${maxHeight}px` }),
428
+ } as React.CSSProperties
429
+ }
430
+ >
431
+ <Table
432
+ ref={(el) => {
433
+ grid.current = el
434
+ setRef(ref, el)
435
+ }}
436
+ role="grid"
437
+ dividers="none"
438
+ containerRef={scrollRef}
439
+ containerClassName={cn(
440
+ fit ? "max-md:overflow-visible" : "overflow-x-auto",
441
+ maxHeight !== undefined && "max-h-[var(--heat-table-max-height)] overflow-auto overscroll-contain",
442
+ containerClassName
443
+ )}
444
+ className={cn("w-auto border-spacing-[3px] tabular-nums", fit && "max-md:w-full max-md:table-fixed", className)}
445
+ aria-rowcount={virtualize ? rows.length + headerRows + (footer ? 1 : 0) : undefined}
446
+ style={{ fontSize: size.text, ...style }}
447
+ {...rest}
448
+ onMouseOver={(e) => {
449
+ const hit = atOf(e.target)
450
+ if (hit && hit.el !== hovered.current) {
451
+ hovered.current = hit.el
452
+ paint()
453
+ onCellHover?.(cellOf(hit.at))
454
+ }
455
+ onMouseOver?.(e)
456
+ }}
457
+ onMouseLeave={(e) => {
458
+ if (hovered.current) {
459
+ hovered.current = null
460
+ paint()
461
+ onCellHover?.(null)
462
+ }
463
+ onMouseLeave?.(e)
464
+ }}
465
+ onFocus={(e) => {
466
+ const hit = atOf(e.target)
467
+ if (hit) {
468
+ focused.current = hit.el
469
+ setChosen((prev) => (prev?.r === hit.at.r && prev.c === hit.at.c ? prev : hit.at))
470
+ paint()
471
+ onCellFocus?.(cellOf(hit.at))
472
+ }
473
+ onFocus?.(e)
474
+ }}
475
+ onBlur={(e) => {
476
+ if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {
477
+ focused.current = null
478
+ paint()
479
+ }
480
+ onBlur?.(e)
481
+ }}
482
+ onClick={(e) => {
483
+ const hit = atOf(e.target)
484
+ if (hit) {
485
+ move(hit.at)
486
+ onCellClick?.(cellOf(hit.at), e as unknown as React.MouseEvent<HTMLTableCellElement>)
487
+ }
488
+ onClick?.(e)
489
+ }}
490
+ onKeyDown={(e) => {
491
+ const hit = atOf(e.target)
492
+ if (hit) keys(e, hit.at)
493
+ onKeyDown?.(e)
494
+ }}
495
+ >
496
+ <TableHeader className={cn(sticky && "md:sticky md:top-0 md:z-[2]")}>
497
+ {columnGroups?.length ? (
498
+ <TableRow role="row" aria-rowindex={virtualize ? 1 : undefined}>
499
+ <TableHead role="columnheader" className={cn("h-[22px] border-b-0", sticky && cn("md:sticky md:left-0", pinned))} />
500
+ {columnGroups.map((group, i) => (
501
+ <TableHead
502
+ key={i}
503
+ role="columnheader"
504
+ colSpan={group.span}
505
+ className={cn(
506
+ "h-[22px] border-b-0 px-1 text-left text-[11.5px] font-semibold text-foreground max-md:text-xs",
507
+ sticky && surface
508
+ )}
509
+ >
510
+ {group.label}
511
+ </TableHead>
512
+ ))}
513
+ </TableRow>
514
+ ) : null}
515
+ <TableRow role="row" aria-rowindex={virtualize ? headerRows : undefined}>
516
+ <TableHead
517
+ role="columnheader"
518
+ className={cn(
519
+ "h-[26px] border-b-0 pe-2 ps-1 text-[11.5px] font-medium max-md:w-[58px] max-md:text-xs",
520
+ sticky && cn("md:sticky md:left-0 md:z-[1]", pinned)
521
+ )}
522
+ >
523
+ {rowHeader}
524
+ </TableHead>
525
+ {columns.map((column, c) => (
526
+ <TableHead
527
+ key={c}
528
+ role="columnheader"
529
+ data-column={c}
530
+ className={cn(
531
+ "h-[26px] border-b-0 px-2 text-center text-[11.5px] font-medium max-md:px-0 max-md:text-xs",
532
+ density === "compact" && "px-0 text-[10.5px]",
533
+ lift,
534
+ sticky && pinned
535
+ )}
536
+ >
537
+ {columnLabels?.[c] !== undefined ? (
538
+ <>
539
+ <span className="sr-only">{columnLabels[c]}</span>
540
+ <span className="max-md:hidden" aria-hidden>
541
+ {column}
542
+ </span>
543
+ </>
544
+ ) : (
545
+ // Screen readers keep the full name on a phone, where the short one is shown.
546
+ <span className="max-md:sr-only">{column}</span>
547
+ )}
548
+ <span className="md:hidden" aria-hidden>
549
+ {phoneColumns?.[c] ?? column}
550
+ </span>
551
+ </TableHead>
552
+ ))}
553
+ </TableRow>
554
+ </TableHeader>
555
+ <TableBody className="[&>tr:hover]:bg-transparent">
556
+ {virtualize ? (
557
+ <>
558
+ {spacer(top)}
559
+ {items.map((item) => bodyRow(rows[item.index], item.index, item.index + headerRows - 1))}
560
+ {spacer(bottom)}
561
+ </>
562
+ ) : (
563
+ rows.map((row, r) => bodyRow(row, r))
564
+ )}
565
+ </TableBody>
566
+ {footer && (
567
+ <TableFooter className="max-md:hidden [&>tr:first-child>*]:border-t-0">
568
+ <TableRow role="row" aria-rowindex={virtualize ? rows.length + headerRows + 1 : undefined}>
569
+ <TableHead
570
+ role="rowheader"
571
+ className={cn(
572
+ "h-[30px] pe-2 ps-1 pt-1.5 text-[11.5px] font-medium text-muted-foreground",
573
+ sticky && cn("md:sticky md:left-0", pinned)
574
+ )}
575
+ >
576
+ {footer.label}
577
+ </TableHead>
578
+ {columns.map((_, c) => (
579
+ <TableCell key={c} role="gridcell" className="h-[30px] px-0 pt-1.5 text-center font-semibold">
580
+ {footer.values[c]}
581
+ </TableCell>
582
+ ))}
583
+ </TableRow>
584
+ </TableFooter>
585
+ )}
586
+ </Table>
587
+ <div
588
+ data-slot="heat-table-readout"
589
+ aria-live="polite"
590
+ className="mt-5 min-h-[96px] border-t py-4 md:hidden"
591
+ >
592
+ {shown &&
593
+ (readout ? (
594
+ readout(shown)
595
+ ) : (
596
+ <>
597
+ <div className="text-[30px] font-semibold tabular-nums tracking-[-0.02em]">{format(shown.value, shown)}</div>
598
+ <div className="mt-0.5 text-[15px]">
599
+ {shown.row.label}, {names[shown.columnIndex]}
600
+ </div>
601
+ </>
602
+ ))}
603
+ </div>
604
+ </div>
605
+ )
606
+ }
607
+
608
+ const HeatTable = React.forwardRef(HeatTableInner) as <Row extends HeatRow = HeatRow>(
609
+ props: HeatTableProps<Row> & { ref?: React.ForwardedRef<HTMLTableElement> }
610
+ ) => React.ReactElement
611
+ ;(HeatTable as { displayName?: string }).displayName = "HeatTable"
612
+
613
+ export { HeatTable }
@@ -0,0 +1,9 @@
1
+ export {
2
+ HeatTable,
3
+ heatShade,
4
+ type HeatTableProps,
5
+ type HeatRow,
6
+ type HeatCell,
7
+ type HeatScaleRange,
8
+ type HeatColumnGroup,
9
+ } from "./heat-table"
@@ -66,12 +66,17 @@ const MenuPositioner = React.forwardRef<
66
66
  ))
67
67
  MenuPositioner.displayName = "MenuPositioner"
68
68
 
69
+ type MenuPlacement = Pick<
70
+ React.ComponentProps<typeof MenuPrimitive.Positioner>,
71
+ "side" | "align" | "sideOffset" | "alignOffset"
72
+ >
73
+
69
74
  const MenuContent = React.forwardRef<
70
75
  React.ComponentRef<typeof MenuPrimitive.Popup>,
71
- React.ComponentProps<typeof MenuPrimitive.Popup>
72
- >(({ className, ...props }, ref) => (
76
+ React.ComponentProps<typeof MenuPrimitive.Popup> & MenuPlacement
77
+ >(({ className, side, align, sideOffset, alignOffset, ...props }, ref) => (
73
78
  <MenuPortal>
74
- <MenuPositioner>
79
+ <MenuPositioner side={side} align={align} sideOffset={sideOffset ?? 6} alignOffset={alignOffset}>
75
80
  <MenuPrimitive.Popup
76
81
  ref={useMergedRef(ref, React.useContext(MenuAgentContext)?.popup)}
77
82
  className={cn(
@@ -0,0 +1 @@
1
+ export { MonthPicker, type MonthPickerProps } from "./month-picker";