Newsfeed Metrics Bar
A social-style counter ribbon — a horizontal strip of icon + value + label triples for engagement counters like likes / reposts / comments / views. Built for news-feed cards and post surfaces where counts update live as a user interacts.
Preview
1284likes
312reposts
86comments
24100views
Customize
Counters
1284
312
86
24100
Display
Installation
npx shadcn@latest add https://craftbits.dev/r/newsfeed-metrics-bar.jsonUsage
import { Heart, Repeat2, MessageCircle } from "lucide-react";
import { NewsfeedMetricsBar } from "@craft-bits/core";
<NewsfeedMetricsBar
metrics={[
{ id: "likes", label: "likes", value: 1284, icon: <Heart />, trend: "up" },
{ id: "reposts", label: "reposts", value: 312, icon: <Repeat2 /> },
{ id: "comments", label: "comments", value: 86, icon: <MessageCircle /> },
]}
/>Anatomy
- Ribbon — a flex container with wrap. Packs tightly on wide cards; spills onto a second line on narrow ones — no media queries.
- Counter — an inline row of
icon -> value -> label, the order social UIs scan left-to-right. - Trend tone —
uppaints the value withcb-success,downwithcb-error,flatwithcb-fg-subtle.neutral(default) keeps the foreground tone. - Value transition — each value is keyed by itself, so the
motion.spanre-mounts on change and re-runsinitial -> animate. Live counters swap smoothly without imperative motion-value plumbing. - Icon-only mode — set
iconOnly: trueon a metric to hide the inline label while preserving it as the tile'saria-labelfor assistive tech.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
metrics | NewsfeedMetricsBarMetric[] | required | Ordered counter entries. |
aria-label | string | 'Engagement' | Accessible label for the status region. |
className | string | — | Merged onto the root via cn(). |
NewsfeedMetricsBarMetric
| Field | Type | Description |
|---|---|---|
id | string | Stable identifier, used as React key. |
label | ReactNode | Inline label rendered next to the value. |
value | number | string | Value to display; numbers render with tabular nums. |
icon | ReactNode | Optional leading icon, rendered before the value. |
trend | 'up' | 'down' | 'flat' | 'neutral' | Optional direction-of-change rating. |
iconOnly | boolean | When true, hide the label visually but keep it as aria-label. |
Accessibility
- The ribbon root is a
<div role="status">witharia-labelandaria-live="polite"so assistive tech announces updates. aria-atomic="false"scopes announcements to the changing counter rather than the whole bar.- Leading icons are
aria-hidden="true"— the visible label (or the tile'saria-labelwheniconOnlyis set) carries the accessible name. - Reduced-motion users get a static ribbon — no enter animation, no value transition.
Credits
- Extracted from:
terminal-dreams(src/components/frontend-design/sdp-news-feed/ui/MetricsBar.tsx). The original hard-coded four news-feed perf metrics (domNodes,networkReqs,scrollFps,tti), tied visibility to a step gate, computed trend thresholds inline withbad/goodbooleans, and laid the counters out in a 4-column CSS grid. craft-bits generalises the surface to a social-shapedmetrics[] = { id, label, value, icon?, trend?, iconOnly? }, drops the step gate, lifts the trend decision to the caller, and shifts the layout to an inline icon-leading row that matches how engagement ribbons read on real feeds. Distinct fromGalleryMetricsBar(label-above-value tiles for perf dashboards) andMetricsPanel(the larger dashboard primitive).