learning_ai_common_plat/packages/data-viz/src/Heatmap.tsx
saravanakumardb1 d082480849 feat(packages): Wave 4 motion + Wave 5b data-viz + Wave 7 notifications-ui
Three new product-agnostic packages unlock visible elegance lifts
across every product:

═══════════════════════════════════════════════════════════════════════
@bytelyst/motion@0.1.0 — Wave 4 elegance primitives  (2.21 KB / 8 KB)
═══════════════════════════════════════════════════════════════════════

  <Reveal>          — IntersectionObserver-based fade/slide entry,
                      6 directions, configurable spring + delay
  <StaggerList>     — sequenced reveal of children with per-item delay
  <NumberFlow>      — RAF-tweened number counter, cubic-out easing,
                      Intl-formatted, prefers-reduced-motion aware
  <TiltCard>        — 3D perspective tilt + cursor-tracking glare
                      overlay (single-element ref, no React rerenders)
  <ScrollProgress>  — fixed scroll-position bar (window or any element)

Plus exported `SPRINGS` (4 cubic-bezier presets) + `prefersReducedMotion`
helper. Every primitive accepts `disableMotion` for snapshot tests.

═══════════════════════════════════════════════════════════════════════
@bytelyst/data-viz@0.1.0 — Wave 5b viz primitives  (2.63 KB / 10 KB)
═══════════════════════════════════════════════════════════════════════

  <Sparkline>     — line trend with gradient fill + last-point marker
  <BarSparkline>  — discrete-bar mini-chart with max-bar highlight
  <KpiCard>       — label + headline + delta arrow + sparkline; supports
                    'goodWhen=lower' for latency/cost metrics
  <ProgressRing>  — circular progress with center content slot,
                    animated stroke-dashoffset
  <Heatmap>       — GitHub-style calendar grid with color-mix() intensity

All pure SVG / CSS — zero runtime dependencies.

═══════════════════════════════════════════════════════════════════════
@bytelyst/notifications-ui@0.1.0 — Wave 7 essentials (3.31 KB / 10 KB)
═══════════════════════════════════════════════════════════════════════

  <NotificationCenter>  — bell trigger + badge + dropdown panel with
                          All / Unread / Mentions tabs, outside-click
                          + Escape close, mark-all-read action
  <InboxItem>           — single row with unread dot, kind glyph,
                          relative timestamp, optional action buttons
  <BannerStack>         — top-of-page strip with maxVisible + +N more,
                          accent-bordered tone variants, dismissible
  <Announcement>        — inline 'What's new' pill (3 tone variants)

5 notification kinds (info/success/warning/danger/mention) + 5 banner
kinds (... + announcement gradient).

═══════════════════════════════════════════════════════════════════════
Quality gates
═══════════════════════════════════════════════════════════════════════
  All three packages: tsc --noEmit clean, build clean.
  Tests:    motion 16/16  ·  data-viz 14/14  ·  notifications-ui 17/17
  Bundles:  motion 2.21 KB  ·  data-viz 2.63 KB  ·  noti-ui 3.31 KB
  Budgets:  added to .size-limit.cjs (8/10/10 KB respectively)

Refs:
  learning_ai_uxui_web/docs/ROADMAP_2026.md
    §Wave 4 (Motion), §Wave 5b (Charts), §Wave 7 (Productisation)
  Decisions doc §13 (mobile-native = tokens-only) leaves room for these
    web-first packages to be the canonical surface
2026-05-27 13:08:30 -07:00

89 lines
2.3 KiB
TypeScript

import { useMemo, type CSSProperties } from 'react';
export interface HeatmapCell {
/** ISO date or any stable label. */
date: string;
/** Value — drives intensity. */
value: number;
/** Optional tooltip text. */
label?: string;
}
export interface HeatmapProps {
/** Cells laid out top-to-bottom then left-to-right (calendar style). */
cells: HeatmapCell[];
/** Rows. Default 7 (week). */
rows?: number;
/** Cell size in px (square). Default 12. */
cell?: number;
/** Gap between cells in px. Default 3. */
gap?: number;
/** Active color (interpolated by intensity). */
color?: string;
/** Empty cell color. */
emptyColor?: string;
ariaLabel?: string;
className?: string;
style?: CSSProperties;
}
/**
* `<Heatmap>` — GitHub-style calendar heatmap. Pure CSS grid, no
* tooltips library — uses native `title` attributes for the on-hover
* label so the bundle stays tiny.
*/
export function Heatmap({
cells,
rows = 7,
cell = 12,
gap = 3,
color = 'var(--bl-accent, #6366f1)',
emptyColor = 'var(--bl-surface-muted, rgba(0,0,0,0.04))',
ariaLabel,
className,
style,
}: HeatmapProps) {
const max = useMemo(
() => cells.reduce((m, c) => Math.max(m, c.value), 0) || 1,
[cells],
);
return (
<div
data-testid="bl-heatmap"
role="img"
aria-label={ariaLabel ?? 'Activity heatmap'}
className={className}
style={{
display: 'grid',
gridTemplateRows: `repeat(${rows}, ${cell}px)`,
gridAutoFlow: 'column',
gap,
...style,
}}
>
{cells.map((c, i) => {
const intensity = c.value > 0 ? 0.15 + 0.85 * (c.value / max) : 0;
return (
<div
key={`${c.date}-${i}`}
data-testid={`bl-heatmap-cell-${i}`}
data-value={c.value}
data-intensity={intensity.toFixed(2)}
title={c.label ?? `${c.date}: ${c.value}`}
style={{
width: cell,
height: cell,
borderRadius: 2,
background:
intensity === 0
? emptyColor
: `color-mix(in srgb, ${color} ${Math.round(intensity * 100)}%, transparent)`,
transition: 'transform 120ms ease',
}}
/>
);
})}
</div>
);
}