Stat Card
scificn/stat-cardFreeComponent
Metric tile with value, label, delta indicator, and status variants for dashboards.
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/stat-card.jsonSource
1import * as React from 'react'2import { cva, type VariantProps } from 'class-variance-authority'3import { cn } from '@/lib/utils'45const statCardVariants = cva(6 [7 'relative flex flex-col font-mono',8 'border border-solid rounded-none',9 ],10 {11 variants: {12 variant: {13 DEFAULT: ['border-[var(--border)]'],14 ACTIVE: ['border-[var(--color-green)]'],15 WARNING: ['border-[var(--color-amber)]'],16 CRITICAL: ['border-[var(--color-red)]'],17 },18 },19 defaultVariants: { variant: 'DEFAULT' },20 }21)2223export interface StatCardProps24 extends React.HTMLAttributes<HTMLDivElement>,25 VariantProps<typeof statCardVariants> {26 label: string27 value: string | number28 /** Delta text, e.g. "+2.3%" */29 delta?: string30 /** true = positive (▲ green), false = negative (▼ red), undefined = neutral */31 deltaPositive?: boolean32 /** Small status line shown at the bottom of the card */33 sublabel?: string34}3536const StatCard = React.forwardRef<HTMLDivElement, StatCardProps>(37 (38 {39 className,40 variant = 'DEFAULT',41 label,42 value,43 delta,44 deltaPositive,45 sublabel,46 style,47 ...props48 },49 ref50 ) => {51 const accentColor =52 variant === 'ACTIVE' ? 'var(--color-green)' :53 variant === 'WARNING' ? 'var(--color-amber)' :54 variant === 'CRITICAL' ? 'var(--color-red)' :55 'var(--text-secondary)'5657 const accentGlow =58 variant === 'ACTIVE' ? 'var(--text-glow-green)' :59 variant === 'WARNING' ? 'var(--text-glow-amber)' :60 variant === 'CRITICAL' ? 'var(--text-glow-red)' :61 'none'6263 const deltaColor =64 deltaPositive === true ? 'var(--color-green)' :65 deltaPositive === false ? 'var(--color-red)' :66 'var(--text-muted)'6768 const deltaSymbol =69 deltaPositive === true ? '▲ ' :70 deltaPositive === false ? '▼ ' :71 '— '7273 return (74 <div75 ref={ref}76 className={cn(statCardVariants({ variant }), className)}77 style={{78 padding: '1rem',79 gap: '0.4rem',80 background: 'var(--surface)',81 ...style,82 }}83 {...props}84 >85 {/* Label */}86 <div87 style={{88 fontSize: '0.6rem',89 color: 'var(--text-muted)',90 letterSpacing: '0.12em',91 textTransform: 'uppercase',92 }}93 >94 {label}95 </div>9697 {/* Value */}98// … truncated
What it pulls in
npm packages
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 |
