Heatmap
scificn/heatmapFreeComponent
Grid of colored cells showing density or activity. Opacity-based intensity scaling. Supports row/column labels.
Live preview
live · rendered by the registry
Rendered by scificn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.scificn.dev/r/heatmap.jsonSource
1import * as React from 'react'2import { cn } from '@/lib/utils'34export type HeatmapVariant = 'GREEN' | 'AMBER' | 'RED'56export interface HeatmapCell {7 value: number8 label?: string9}1011export interface HeatmapProps extends React.HTMLAttributes<HTMLDivElement> {12 /** Flat array of cells, filled left-to-right, top-to-bottom */13 data: HeatmapCell[] | number[]14 columns: number15 rowLabels?: string[]16 colLabels?: string[]17 title?: string18 variant?: HeatmapVariant19 /** Override the max value for normalization. Defaults to max(data). */20 max?: number21 /** Cell size in px. Default 16. */22 cellSize?: number23}2425function accentForVariant(v: HeatmapVariant): string {26 switch (v) {27 case 'GREEN': return 'var(--color-green)'28 case 'AMBER': return 'var(--color-amber)'29 case 'RED': return 'var(--color-red)'30 }31}3233const Heatmap = React.forwardRef<HTMLDivElement, HeatmapProps>(34 (35 {36 className,37 data,38 columns,39 rowLabels,40 colLabels,41 title,42 variant = 'GREEN',43 max,44 cellSize = 16,45 style,46 ...props47 },48 ref49 ) => {50 // Normalise to HeatmapCell[]51 const cells: HeatmapCell[] = data.map((d) =>52 typeof d === 'number' ? { value: d } : d53 )5455 const computedMax = max ?? Math.max(...cells.map((c) => c.value), 1)56 const accentColor = accentForVariant(variant)57 const rows = Math.ceil(cells.length / columns)58 const hasRowLabels = rowLabels && rowLabels.length > 059 const hasColLabels = colLabels && colLabels.length > 06061 return (62 <div63 ref={ref}64 className={cn(className)}65 style={{66 border: '1px solid var(--border)',67 background: 'var(--surface)',68 fontFamily: 'var(--font-mono)',69 overflowX: 'auto',70 // Keep component sized to content so parent controls overflow71 display: 'inline-block',72 maxWidth: '100%',73 ...style,74 }}75 {...props}76 >77 {/* Title bar */}78 {title && (79 <div80 style={{81 padding: '0.4rem 0.75rem',82 borderBottom: '1px solid var(--border)',83 background: 'var(--surface-raised)',84 fontSize: '0.6rem',85 color: 'var(--text-muted)',86 letterSpacing: '0.12em',87 textTransform: 'uppercase',88 }}89 >90 {title}91// … truncated
More from scificn
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alertalert | scificn | Components | Free | 1 dep | |
| Badgebadge | scificn | Components | Free | 1 dep | |
| Bar Chartbar-chart | scificn | Components | Free | no deps | |
| Breadcrumbbreadcrumb | scificn | Components | Free | no deps | |
| Buttonbutton | scificn | Components | Free | 2 deps | |
| Cardcard | scificn | Components | Free | no deps | |
| Checkboxcheckbox | scificn | Components | Free | 1 dep | |
| Dialogdialog | scificn | Components | Free | 1 dep |
