Updated
Benchmark Race
NewCustomize
Color
Duration0.9s
Installation
npx shadcn@latest add https://uibrik.com/r/benchmark-race.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/benchmark-race/benchmark-race.tsx"use client"; import { useEffect, useId, useRef, useState, useSyncExternalStore, type CSSProperties, type KeyboardEvent, type ReactNode } from "react"; import { animate, AnimatePresence, motion, useInView } from "motion/react"; import { IconBoltFilled } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; // Benchmark race. Your product against the rest, one bar each. The first time // the card scrolls into view each logo pops in and its bar races to its // result, a little after the one above, while the number counts up beside it. // When your bar lands, a shine passes along it once. Tabs switch the measure // (build time, bundle size, throughput): bars travel straight to their new // lengths without dropping back to zero, numbers count up or down to the new // value, and with sorting on the rows trade places so the best result leads. // // Colour is spent on one thing at rest: your result. Your logo tile, bar and // lead chip ("3.1× faster") wear the accent; every other row stays neutral // until it is pointed at, when its logo tile and bar take its own brand colour // and the other rows step back. Surfaces are // set apart by fill alone: no borders, no shadows. // // Each bar is a full-width pill slid in from the left of its track, so it // moves on transform alone and its rounded end never squashes. Numbers are // written straight to the DOM as they count, without re-rendering.
Adds the files to
components/uibrik/benchmark-race and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/benchmark-race.Usage
import { BenchmarkRace } from "@/components/uibrik/benchmark-race/benchmark-race";<BenchmarkRace highlight="Acme" color="#2563eb" duration={0.9} sort shine showLead defaultIndex={0} locale="en-US" onIndexChange={(index) => {}} // benchmarks={[{ label: "…", results: [{ name: "…", value: 0 }] }]} // index={0}/>Where to use Benchmark Race
Performance comparisons
Bars racing to their results with counting numbers make benchmarks exciting.
Pairs with Comparison Table
Speed against competitors
Tabs switching the measure show wins across several metrics.
Benchmark pages
Rows re-sorting so the best leads make the winner obvious.
Pairs with Performance Meter
Props
BenchmarkRace- highlight
- Type string
- "Acme"
- Name of your own result, drawn in the accent colour.
- color
- Type string
- "#2563eb"
- Accent for your logo, bar and lead chip. Every other row stays neutral.
- duration
- Type number
- 0.9
- How long a bar takes to reach its result the first time.
- sort
- Type boolean
- true
- Order rows by result; they trade places when the measure changes.
- shine
- Type boolean
- true
- A shine passes along your bar each time it lands.
- showLead
- Type boolean
- true
- Show how far ahead you are of the best of the others, e.g. "3.1× faster".
- benchmarks
- Type { label: string; unit?: string; lowerIsBetter?: boolean; better?: string; caption?: string; results: { name: string; value: number; logo?: ReactNode; color?: string }[] }[]
- 3 measures
- One tab per measure. better is the word after the lead multiplier (faster, smaller, more). logo is a mark drawn in currentColor on a small tile; color is the brand colour its tile and bar take on hover. One measure hides the tabs.
- index / defaultIndex
- Type number
- 0
- Selected measure, controlled or uncontrolled.
- onIndexChange
- Type (index: number) => void
- –
- Called when a tab is picked.
- locale
- Type string
- "en-US"
- Locale for number formatting.
- className
- Type string
- –
- Classes for the card.