Skip to content

Stat Bars

Percentage bars that grow, one after another, when the chart scrolls into view.

$npx shadcn@latest add https://framebrick.co/r/stat-bars.json

From the Nitip template, see it in context.

94%

On-time projects

78%

Returning clients

62%

Organic traffic

Installation

$ npx shadcn@latest add https://framebrick.co/r/stat-bars.json

Usage

import { StatBars } from "@/components/ui/stat-bars";

<StatBars stats={[{ value: 94, label: "Projects delivered on time" }, { value: 78, label: "Clients who come back" }]} />

Props

PropTypeDefaultDescription
stats{ value: number; label: string }[]—Values are percentages (0–100).
heightnumber320Height of the chart from 640 px up, in px.
fadebooleantrueFade the fill with the value (75-100%). Turn it off for a light primary, where the label would lose contrast.
classNamestring—Classes for the row.
  • Bars start at 30% and grow 50 ms apart — Nitip's refinement over Framer, kept here.
  • Only the fill fades with the value; the number and the label stay at full strength. Fading the whole bar, as Framer does, dropped the label to 3.3-4.3:1 on a coloured primary.
  • Below 640 px the bars lie flat and their width follows the value.
  • They grow once, the first time they are seen.
  • The server renders every bar at the 30% it starts from, so a bar that is never animated shows the wrong data. Without JavaScript a noscript style points the height at the real value, and in print a bar that never scrolled into view is set to its value; with JavaScript on screen neither applies.
  • With reduced motion the bars appear at their value instead of growing.

AI prompt

Paste into v0, Lovable, Bolt or Claude to rebuild this component in your own project.

Create a React + Tailwind CSS + Motion (motion/react) component called StatBars.
- A row of bars, one per stat: bg-primary, text-primary-foreground, rounded-md, p-4, the value as a large
  tabular-nums percentage at the top, a hairline under it, and the label at the bottom.
- Each bar's height is its value in percent of the chart height, and its opacity follows the value
  (minimum 0.35 so small bars stay readable).
- Animate a CSS variable --fill from 30% to the value with whileInView (viewport once, amount 0.5) and a spring
  (bounce 0.2, duration 0.4s), delayed by 50ms per bar, with the bar's height reading height: var(--fill).
- Under 640px the bars stack as horizontal rows whose width is the value instead.
- With prefers-reduced-motion (useReducedMotion), keep the starting value the same and use a zero-duration transition,
  so the bars arrive at their value when they come into view — a CSS variable is not a transform, so MotionConfig would
  not skip it. Do not change the starting value itself: it is rendered into the server HTML, and a different one on the
  client is a hydration mismatch.
- The server renders --fill at 30%, so a bar that is never animated shows the wrong height. Give the container a
  <noscript> style `[data-stat-bar]{--fill:var(--value)!important}` (position it absolute so it adds no flex gap), mark
  each bar with data-stat-bar, and give each bar `print:sm:h-(--value)!` so a printed page shows true heights.

Be the first to know

Get new templates and components first

One short email when we release a template or a free component. No spam — unsubscribe anytime.

We use your email only for Framebrick updates. Privacy policy