basalt-ui 2.26.0 → 2.27.1

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 (53) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/MIGRATING.md +91 -12
  3. package/dist/charts/Bars.d.ts.map +1 -1
  4. package/dist/charts/Bars.js +37 -1
  5. package/dist/charts/ChartCard.d.ts +8 -2
  6. package/dist/charts/ChartCard.d.ts.map +1 -1
  7. package/dist/charts/ChartCard.js +2 -0
  8. package/dist/charts/Sparkline.d.ts.map +1 -1
  9. package/dist/charts/Sparkline.js +76 -15
  10. package/dist/charts/chart-box.module.css +78 -1
  11. package/dist/charts/chart-box.module.css.d.ts +1 -0
  12. package/dist/charts/chart-legend.module.css +0 -14
  13. package/dist/charts/compile.d.ts +20 -0
  14. package/dist/charts/compile.d.ts.map +1 -1
  15. package/dist/charts/compile.js +85 -12
  16. package/dist/charts/legend.d.ts.map +1 -1
  17. package/dist/charts/legend.js +37 -87
  18. package/dist/charts/sparkline.module.css +4 -0
  19. package/dist/charts/state.d.ts +7 -0
  20. package/dist/charts/state.d.ts.map +1 -1
  21. package/dist/charts/state.js +14 -3
  22. package/dist/cli/shot/capture.d.ts +32 -3
  23. package/dist/cli/shot/capture.d.ts.map +1 -1
  24. package/dist/cli/shot/capture.js +17 -7
  25. package/dist/dashboard/meter-model.d.ts +17 -3
  26. package/dist/dashboard/meter-model.d.ts.map +1 -1
  27. package/dist/dashboard/meter-model.js +69 -19
  28. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  29. package/dist/dashboard/meter-parts.js +28 -12
  30. package/dist/dashboard/meter.module.css +17 -1
  31. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  32. package/dist/dashboard/stat-strip.js +90 -22
  33. package/dist/dashboard/stat-strip.module.css +13 -3
  34. package/dist/dashboard/stat-strip.module.css.d.ts +1 -0
  35. package/llms.txt +3 -2
  36. package/package.json +1 -1
  37. package/src/charts/Bars.tsx +50 -2
  38. package/src/charts/ChartCard.tsx +9 -1
  39. package/src/charts/Sparkline.tsx +113 -20
  40. package/src/charts/chart-box.module.css +78 -1
  41. package/src/charts/chart-box.module.css.d.ts +1 -0
  42. package/src/charts/chart-legend.module.css +0 -14
  43. package/src/charts/compile.ts +140 -18
  44. package/src/charts/legend.tsx +10 -74
  45. package/src/charts/sparkline.module.css +4 -0
  46. package/src/charts/state.tsx +30 -5
  47. package/src/cli/shot/capture.ts +25 -9
  48. package/src/dashboard/meter-model.ts +122 -31
  49. package/src/dashboard/meter-parts.tsx +53 -19
  50. package/src/dashboard/meter.module.css +17 -1
  51. package/src/dashboard/stat-strip.module.css +13 -3
  52. package/src/dashboard/stat-strip.module.css.d.ts +1 -0
  53. package/src/dashboard/stat-strip.tsx +114 -26
@@ -41,9 +41,10 @@
41
41
  * weights are not supported. `stale` dims a cell while placeholder data shows.
42
42
  */
43
43
  import { Card, Skeleton } from '@mantine/core'
44
- import { useId } from 'react'
44
+ import { useId, useRef } from 'react'
45
45
  import type { CSSProperties, ReactNode } from 'react'
46
46
  import { toErrorMessage } from '../common/errors'
47
+ import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
47
48
  import { cx } from '../common/props'
48
49
  import type { BasaltProps, Tone } from '../common/props'
49
50
  import { RetryButton } from '../common/retry-button'
@@ -285,32 +286,34 @@ function StripCell({
285
286
  {...(state === undefined && rows !== undefined && { 'data-strip-has-rows': '' })}
286
287
  {...(cell.stale && { 'data-stale': 'true' })}
287
288
  >
288
- <div className={classes.captionLine}>
289
- <div className={classes.captionMain}>
290
- {/* The caption and its info glyph are one unit: the qualifier wraps whole, never between them. */}
291
- <span className={classes.lead}>
292
- <span
293
- className={classes.caption}
294
- id={captionId}
295
- title={cell.caption}
296
- data-strip-caption
297
- >
298
- {cell.caption}
289
+ <div className={classes.head} data-strip-head>
290
+ <div className={classes.captionLine}>
291
+ <div className={classes.captionMain}>
292
+ {/* The caption and its info glyph are one unit: the qualifier wraps whole, never between them. */}
293
+ <span className={classes.lead}>
294
+ <span
295
+ className={classes.caption}
296
+ id={captionId}
297
+ title={cell.caption}
298
+ data-strip-caption
299
+ >
300
+ {cell.caption}
301
+ </span>
302
+ {cell.info !== undefined && <InfoGlyph text={cell.info} />}
303
+ </span>
304
+ {cell.qualifier !== undefined && (
305
+ <span className={classes.qualifier}>{cell.qualifier}</span>
306
+ )}
307
+ </div>
308
+ {cell.action !== undefined && (
309
+ <span className={classes.action} data-strip-action>
310
+ {cell.action}
299
311
  </span>
300
- {cell.info !== undefined && <InfoGlyph text={cell.info} />}
301
- </span>
302
- {cell.qualifier !== undefined && (
303
- <span className={classes.qualifier}>{cell.qualifier}</span>
304
312
  )}
305
313
  </div>
306
- {cell.action !== undefined && (
307
- <span className={classes.action} data-strip-action>
308
- {cell.action}
309
- </span>
310
- )}
314
+ {state !== undefined && <CellState state={state} />}
315
+ {state === undefined && hasHero && heroEl}
311
316
  </div>
312
- {state !== undefined && <CellState state={state} />}
313
- {state === undefined && hasHero && heroEl}
314
317
  {state === undefined && cell.visual !== undefined && (
315
318
  <div
316
319
  className={cx(classes.visual, loading && classes.hold)}
@@ -334,8 +337,12 @@ function StripCell({
334
337
  {rows.map((row) => (
335
338
  <li key={row.key} className={classes.row} data-strip-row={row.key}>
336
339
  <span className={classes.rowLabel}>{row.label}</span>
337
- <span className={classes.visual}>{row.visual}</span>
338
- <span className={classes.rowValue}>
340
+ <span className={classes.visual}>
341
+ <VisualSlotContext.Provider value={HOSTED}>
342
+ {row.visual}
343
+ </VisualSlotContext.Provider>
344
+ </span>
345
+ <span className={classes.rowValue} data-strip-row-value>
339
346
  {row.hideValue ? null : (row.value ?? EMPTY)}
340
347
  </span>
341
348
  <span>{row.delta}</span>
@@ -352,6 +359,46 @@ function StripCell({
352
359
  )
353
360
  }
354
361
 
362
+ /**
363
+ * One anatomy, a shared visual line: the cells of a row put the top of their drawn mark (Meter track, plot) on one line.
364
+ * Each cell's head (caption line, qualifier, value row) keeps its own height, so a longer qualifier
365
+ * pushes only its own value down; a visual cell whose head is shorter than a sibling's visual offset
366
+ * grows ITS head's min-height by the difference. Cells without a visual are untouched, so a footer
367
+ * still hugs its value and no sibling is stretched.
368
+ */
369
+ const DRAWN_MARK = '[data-meter-track], [data-basalt-sparkline], [data-basalt-chart]'
370
+
371
+ function alignVisuals(root: HTMLElement): void {
372
+ const rows = new Map<number, { head: HTMLElement; natural: number; offset: number }[]>()
373
+ for (const head of root.querySelectorAll<HTMLElement>('[data-strip-head]')) {
374
+ const article = head.parentElement
375
+ const visual = article?.querySelector<HTMLElement>('[data-strip-visual]')
376
+ // The shared line is the top of the drawn MARK (Meter track, sparkline or chart plot): a Meter's
377
+ // caption or tick-label row above its track sits above that line.
378
+ const plot = visual?.querySelector(DRAWN_MARK) ?? visual?.firstElementChild
379
+ const last = head.lastElementChild
380
+ if (!article || !plot || !last) continue
381
+ const { top, bottom } = head.getBoundingClientRect()
382
+ const articleTop = article.getBoundingClientRect().top
383
+ // The head's own height (its content, bottom of the last part) without any min-height we set.
384
+ const natural = last.getBoundingClientRect().bottom - top
385
+ const grown = bottom - top - natural
386
+ const key = Math.round(articleTop)
387
+ rows.set(key, [
388
+ ...(rows.get(key) ?? []),
389
+ { head, natural, offset: plot.getBoundingClientRect().top - articleTop - Math.max(grown, 0) },
390
+ ])
391
+ }
392
+ for (const cells of rows.values()) {
393
+ const target = cells.length < 2 ? 0 : Math.max(...cells.map((c) => c.offset))
394
+ for (const { head, natural, offset } of cells) {
395
+ const grow = target - offset
396
+ const next = grow > 0.5 ? `${natural + grow}px` : ''
397
+ if (head.style.minHeight !== next) head.style.minHeight = next
398
+ }
399
+ }
400
+ }
401
+
355
402
  export function StatStrip({
356
403
  label,
357
404
  cells,
@@ -369,6 +416,47 @@ export function StatStrip({
369
416
  const rest = footer?.filter((entry) => entry.under === undefined || !keys.has(entry.under)) ?? []
370
417
  const hasQualifier = cells.some((cell) => cell.qualifier !== undefined)
371
418
  const hasAction = cells.some((cell) => cell.action !== undefined)
419
+ const gridRef = useRef<HTMLDivElement>(null)
420
+ const observerRef = useRef<ResizeObserver | null>(null)
421
+ const watched = useRef('')
422
+ // Mount-only: one observer; a resize or a late font re-levels in the next frame (a write inside the
423
+ // callback would resize the observed grid in the same frame).
424
+ useIsomorphicLayoutEffect(() => {
425
+ const grid = gridRef.current
426
+ if (!grid || typeof ResizeObserver === 'undefined') return
427
+ let frame = 0
428
+ let live = true
429
+ const schedule = () => {
430
+ cancelAnimationFrame(frame)
431
+ frame = requestAnimationFrame(() => alignVisuals(grid))
432
+ }
433
+ const observer = new ResizeObserver(schedule)
434
+ observerRef.current = observer
435
+ void document.fonts?.ready?.then(() => {
436
+ if (live) schedule()
437
+ })
438
+ return () => {
439
+ live = false
440
+ cancelAnimationFrame(frame)
441
+ observer.disconnect()
442
+ observerRef.current = null
443
+ watched.current = ''
444
+ }
445
+ }, [])
446
+ // Re-level when the cells change, and watch the heads that now exist: a head that rewraps without
447
+ // changing the grid's height re-levels too.
448
+ useIsomorphicLayoutEffect(() => {
449
+ const grid = gridRef.current
450
+ if (!grid) return
451
+ alignVisuals(grid)
452
+ const observer = observerRef.current
453
+ const key = cells.map((cell) => cell.key).join('|')
454
+ if (!observer || watched.current === key) return
455
+ watched.current = key
456
+ observer.disconnect()
457
+ observer.observe(grid)
458
+ for (const head of grid.querySelectorAll('[data-strip-head]')) observer.observe(head)
459
+ }, [cells, footer])
372
460
  return (
373
461
  <div className={cx(classes.container, className)} style={style}>
374
462
  <Card>
@@ -385,7 +473,7 @@ export function StatStrip({
385
473
  } as CSSProperties
386
474
  }
387
475
  >
388
- <div className={classes.cells}>
476
+ <div ref={gridRef} className={classes.cells}>
389
477
  {cells.map((cell) => (
390
478
  <StripCell
391
479
  key={cell.key}