| 1 | "use client" |
| 2 | |
| 3 | import { useMemo } from "react" |
| 4 | import { Area } |
| 5 | import { AreaChart } |
| 6 | import type { AreaVariant |
| 7 | import type { BloomInput |
| 8 | import type { DitherColor |
| 9 | |
| 10 | export type SparklineProps |
| 11 | /** Plain numeric series — the common sparkline case. */ |
| 12 | data: number |
| 13 | color: DitherColor |
| 14 | variant?: AreaVariant |
| 15 | /** Controlled crosshair position (e.g. a committed point). */ |
| 16 | markerIndex?: number |
| 17 | /** Parent-driven hover (e.g. the whole card/row) — lifts the fill. */ |
| 18 | hovered?: boolean |
| 19 | /** Glow on the dither fill. */ |
| 20 | bloom?: BloomInput |
| 21 | /** Only bloom while hovered. */ |
| 22 | bloomOnHover?: boolean |
| 23 | /** Play the entrance sweep — off by default for a calm spark. */ |
| 24 | animate?: boolean |
| 25 | className?: string |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Thin wrapper over {@link |
| 30 | * single `number[]` series, no axes/grid/tooltip, no scrub crosshair (unless a |
| 31 | * `markerIndex` is supplied). Keeps the hover brightness lift. |
| 32 | */ |
| 33 | export function Sparkline({ |
| 34 | data, |
| 35 | color, |
| 36 | variant = "gradient" |
| 37 | markerIndex = null, |
| 38 | hovered = false, |
| 39 | bloom = "off" |
| 40 | bloomOnHover = false, |
| 41 | animate = false, |
| 42 | className, |
| 43 | }: SparklineProps) |
| 44 | // Memoized explicitly so the chart works without React Compiler: `rows` |
| 45 | // identity drives the entrance-replay revision, so a fresh array every |
| 46 | // render would re-trigger the revision's state adjustment each pass. |
| 47 | const rows = |
| 48 | const config = |
| 49 | |
| 50 | return ( |
| 51 | <AreaChart |
| 52 | data={rows} |
| 53 | config={config} |
| 54 | interactive={false} |
| 55 | animate={animate} |
| 56 | markerIndex={markerIndex} |
| 57 | hovered={hovered} |
| 58 | bloom={bloom} |
| 59 | bloomOnHover={bloomOnHover} |
| 60 | margins={{ top: |
| 61 | className={className} |
| 62 | > |
| 63 | <Area dataKey=" |
| 64 | </AreaChart> |
| 65 | ) |
| 66 | } |