Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: added number wheel component

dev_wandry6f64c9775d26
diff --git a/content/docs/typography/meta.json b/content/docs/typography/meta.json
index 55ece159..bf556fbb 100644
--- a/content/docs/typography/meta.json
+++ b/content/docs/typography/meta.json
@@ -12,6 +12,7 @@
"shimmer-sweep",
"typewriter",
"slot-machine-roll",
+ "number-wheel",
"infinite-marquee",
"perspective-marquee",
"matrix-decode",
diff --git a/content/docs/typography/number-wheel.mdx b/content/docs/typography/number-wheel.mdx
new file mode 100644
index 00000000..3d70ec81
--- /dev/null
+++ b/content/docs/typography/number-wheel.mdx
@@ -0,0 +1,98 @@
+---
+title: Number Wheel
+description: Odometer that rolls a number from one value to another with direction inferred from the values
+---
+
+<ComponentPreview name="number-wheel" />
+
+## Installation
+
+<InstallBlock name="number-wheel" />
+
+## Usage
+
+```tsx
+// src/Root.tsx
+import { Composition } from "remotion";
+import { NumberWheel } from "@/components/remocn/number-wheel";
+
+const NumberWheelScene = () => (
+ <NumberWheel from={0} to={24813} fontSize={120} />
+);
+
+export const RemotionRoot = () => (
+ <Composition
+ id="NumberWheel"
+ component={NumberWheelScene}
+ durationInFrames={112}
+ fps={30}
+ width={1280}
+ height={720}
+ />
+);
+```
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "from",
+ type: "number",
+ default: "0",
+ description: "Starting value. Direction is inferred from whether to is greater or less than from.",
+ },
+ {
+ name: "to",
+ type: "number",
+ default: "24813",
+ description: "Target value the wheel settles on. If greater than from, counts up; if less, counts down.",
+ },
+ {
+ name: "fontSize",
+ type: "number",
+ default: "120",
+ description: "Font size in pixels",
+ },
+ {
+ name: "color",
+ type: "string",
+ default: "\"#171717\"",
+ description: "Text color",
+ },
+ {
+ name: "speed",
+ type: "number",
+ default: "1",
+ description: "Multiplier for animation speed",
+ },
+ ]}
+/>
+
+Direction is determined by the relationship between `from` and `to` — no separate direction prop is needed. All values must be integers and non-negative.
+
+## Count Up
+
+Rolls upward from 0 to 24813:
+
+```tsx
+import { Backdrop } from "@/components/remocn/backdrop";
+import { NumberWheel } from "@/components/remocn/number-wheel";
+
+<Backdrop fill={{ type: "color", value: "#ffffff" }}>
+ <NumberWheel from={0} to={24813} fontSize={120} />
+</Backdrop>
+```
+
+## Count Down
+
+Rolls downward from 24813 to 0:
+
+```tsx
+import { Backdrop } from "@/components/remocn/backdrop";
+import { NumberWheel } from "@/components/remocn/number-wheel";
+
+<Backdrop fill={{ type: "color", value: "#ffffff" }}>
+ <NumberWheel from={24813} to={0} fontSize={120} />
+</Backdrop>
+```
diff --git a/registry/__index__.tsx b/registry/__index__.tsx
index 310fc7e8..0a71f204 100644
--- a/registry/__index__.tsx
+++ b/registry/__index__.tsx
@@ -63,6 +63,8 @@ import { MatrixDecode } from "@/registry/remocn/matrix-decode";
import { matrixDecodeConfig } from "@/registry/remocn/matrix-decode/config";
import { MeshGradientBg } from "@/registry/remocn/mesh-gradient-bg";
import { meshGradientBgConfig } from "@/registry/remocn/mesh-gradient-bg/config";
+import { NumberWheel } from "@/registry/remocn/number-wheel";
+import { numberWheelConfig } from "@/registry/remocn/number-wheel/config";
import { PerspectiveMarquee } from "@/registry/remocn/perspective-marquee";
import { perspectiveMarqueeConfig } from "@/registry/remocn/perspective-marquee/config";
import { PricingTierFocus } from "@/registry/remocn/pricing-tier-focus";
@@ -335,6 +337,7 @@ const registry: Record<string, RegistryEntry> = {
config: imageExpandToFullscreenConfig,
},
"github-stars": { Component: GitHubStars, config: githubStarsConfig },
+ "number-wheel": { Component: NumberWheel, config: numberWheelConfig },
"x-follow-card": { Component: XFollowCard, config: xFollowCardConfig },
"x-followers-overview": {
Component: XFollowersOverview,
@@ -450,6 +453,18 @@ if (githubStars) {
};
}
+const numberWheel = registry["number-wheel"];
+if (numberWheel) {
+ numberWheel.config.controls.speed = {
+ type: "number",
+ default: 1,
+ min: 1,
+ max: 4,
+ step: 0.25,
+ label: "Speed",
+ };
+}
+
const xFollowCard = registry["x-follow-card"];
if (xFollowCard) {
xFollowCard.config.controls.speed = {
diff --git a/registry/remocn/github-stars/__tests__/github-stars.test.ts b/registry/remocn/github-stars/__tests__/github-stars.test.ts
index bc1b6d9b..654cf56b 100644
--- a/registry/remocn/github-stars/__tests__/github-stars.test.ts
+++ b/registry/remocn/github-stars/__tests__/github-stars.test.ts
@@ -16,7 +16,6 @@ import {
computeCounterProgress,
computeScrollProgress,
computeSpacerRows,
- computeWheel,
downsampleStargazers,
getStarCount,
isScrollContained,
@@ -295,79 +294,6 @@ describe("getStarCount", () => {
});
});
-// ---------------------------------------------------------------------------
-// computeWheel — odometer digit alignment
-// ---------------------------------------------------------------------------
-
-describe("computeWheel", () => {
- it("lands every place on its exact integer digit at an integer current", () => {
- // The regression: 24813 used to render fractional wheels (1.3, 8.13, …)
- // for every place above the ones, leaving glyphs stuck between two values.
- const current = 24813;
- const digits = [3, 1, 8, 4, 2]; // ones → ten-thousands
- digits.forEach((expected, place) => {
- expect(computeWheel(current, place)).toBeCloseTo(expected, 10);
- });
- });
-
- it("rolls the ones place continuously", () => {
- expect(computeWheel(7, 0)).toBeCloseTo(7, 10);
- expect(computeWheel(7.4, 0)).toBeCloseTo(7.4, 10);
- expect(computeWheel(123.5, 0)).toBeCloseTo(3.5, 10);
- });
-
- it("parks a higher place on its integer digit outside the carry window", () => {
- // tens digit of 24813 is 1; it must not move until the ones is about to
- // carry (current within the final 10% of the tens cell).
- expect(computeWheel(24813, 1)).toBeCloseTo(1, 10);
- expect(computeWheel(24815, 1)).toBeCloseTo(1, 10);
- expect(computeWheel(24818, 1)).toBeCloseTo(1, 10); // frac 0.8 < 0.9 → parked
- });
-
- it("rolls a higher place toward the next digit during the carry window", () => {
- // current 24819.x → ones carrying 9→0, tens rolls 1→2 within [0.9,1.0).
- const start = computeWheel(24819, 1); // frac 0.9 → roll just starting
- const mid = computeWheel(24819.5, 1); // frac 0.95 → mid roll
- expect(start).toBeCloseTo(1, 6);
- expect(mid).toBeGreaterThan(1);
- expect(mid).toBeLessThan(2);
- });
-
- it("reaches the next integer exactly as the carry completes", () => {
- // Approaching the carry boundary the tens wheel tends to 2; at 24820 it has
- // ticked over to the parked 2.
- expect(computeWheel(24820, 1)).toBeCloseTo(2, 10);
- expect(computeWheel(24819.999, 1)).toBeGreaterThan(1.99);
- });
-
- it("renders 9→0 carry within [9, 10) so the trailing wheel glyph is used", () => {
- // tens digit 9 mid-carry must stay in [9,10), never wrap to a small value,
- // so DigitColumn shows the 9→0 transition via its trailing 0 cell.
- const w = computeWheel(999.5, 1); // tens is 9, frac 0.95 → rolling 9→10
- expect(w).toBeGreaterThanOrEqual(9);
- expect(w).toBeLessThan(10);
- });
-
- it("returns 0 for non-positive current at any place", () => {
- expect(computeWheel(0, 0)).toBe(0);
- expect(computeWheel(0, 3)).toBe(0);
- expect(computeWheel(-5, 2)).toBe(0);
- });
-
- it("keeps every wheel within [0, 10) across a full ramp to totalStars", () => {
- const total = 24813;
- const places = [0, 1, 2, 3, 4];
- for (let i = 0; i <= 1000; i++) {
- const current = (i / 1000) * total;
- for (const place of places) {
- const w = computeWheel(current, place);
- expect(w).toBeGreaterThanOrEqual(0);
- expect(w).toBeLessThan(10);
- }
- }
- });
-});
-
// ---------------------------------------------------------------------------
// SAMPLE_STARGAZERS
// ---------------------------------------------------------------------------
diff --git a/registry/remocn/github-stars/index.tsx b/registry/remocn/github-stars/index.tsx
index 27e41d19..2f26c9e4 100644
--- a/registry/remocn/github-stars/index.tsx
+++ b/registry/remocn/github-stars/index.tsx
@@ -1,7 +1,6 @@
"use client";
import { format, parseISO } from "date-fns";
-import type React from "react";
import { useState } from "react";
import { loadFont as loadSans } from "@remotion/google-fonts/Manrope";
import { loadFont as loadMono } from "@remotion/google-fonts/JetBrainsMono";
@@ -13,6 +12,7 @@ import {
useCurrentFrame,
useVideoConfig,
} from "remotion";
+import { Odometer } from "@/components/remocn/number-wheel";
export interface Stargazer {
login: string;
@@ -726,22 +726,6 @@ export function getStarCount(
return Math.round(scrollProgress * totalStars);
}
-const WHEEL_ROLL_START = 0.9;
-
-export function computeWheel(current: number, place: number): number {
- if (current <= 0) return 0;
- if (place === 0) return current % 10;
-
- const v = current / 10 ** place;
- const digit = Math.floor(v) % 10;
- const frac = v - Math.floor(v);
- if (frac <= WHEEL_ROLL_START) return digit;
-
- const raw = (frac - WHEEL_ROLL_START) / (1 - WHEEL_ROLL_START);
- const eased = raw * raw * (3 - 2 * raw); // smoothstep: 0→0, 1→1
- return digit + eased;
-}
-
// --- Sub-components --------------------------------------------------------
function StarGlyph({ size, fill }: { size: number; fill: string }) {
@@ -813,110 +797,6 @@ function Avatar({
);
}
-function DigitColumn({
- value,
- fontSize,
-}: {
- /** continuous wheel value in [0, 10) */
- value: number;
- fontSize: number;
-}) {
- const cellHeight = fontSize * 1.1;
- return (
- <span
- style={{
- display: "inline-block",
- overflow: "hidden",
- height: cellHeight,
- width: "0.62em",
- verticalAlign: "top",
- textAlign: "center",
- }}
- >
- <span
- style={{
- display: "flex",
- flexDirection: "column",
- transform: `translateY(${-value * cellHeight}px)`,
- }}
- >
- {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0].map((d, i) => (
- <span
- key={i}
- style={{ height: cellHeight, lineHeight: `${cellHeight}px` }}
- >
- {d}
- </span>
- ))}
- </span>
- </span>
- );
-}
-
-function Odometer({
- current,
- fontSize,
- color,
- mutedColor,
-}: {
- /** continuous running total (float) */
- current: number;
- fontSize: number;
- color: string;
- mutedColor: string;
-}) {
- const intVal = Math.max(0, Math.round(current));
- const formatted = intVal.toLocaleString("en-US");
-
- // Walk right→left so each digit knows its decimal place; drive each wheel
- // continuously from `current` (higher places roll slower → mechanical feel).
- const cells: React.ReactNode[] = [];
- let place = 0;
- for (let i = formatted.length - 1; i >= 0; i--) {
- const ch = formatted[i];
- if (ch === ",") {
- cells.unshift(
- <span
- key={`c${i}`}
- style={{
- display: "inline-block",
- width: "0.32em",
- color: "currentColor",
- fontSize: "0.85em",
- textAlign: "center",
- }}
- >
- ,
- </span>,
- );
- } else {
- const wheel = computeWheel(current, place);
- cells.unshift(
- <DigitColumn key={`d${i}`} value={wheel} fontSize={fontSize} />,
- );
- place++;
- }
- }
-
- return (
- <div
- style={{
- display: "flex",
- alignItems: "baseline",
- fontSize,
- fontWeight: 800,
- color,
- fontFamily: MONO_FAMILY,
- fontVariantNumeric: "tabular-nums",
- letterSpacing: "-0.03em",
- lineHeight: 1,
- }}
- >
- {cells}
- </div>
- );
-}
-
interface RowProps {
stargazer: Stargazer;
index: number;
@@ -1217,12 +1097,7 @@ export function GitHubStars({
>
<div style={{ display: "flex", alignItems: "center", gap: 20 }}>
<StarGlyph size={starSize} fill={accentColor} />
- <Odometer
- current={current}
- fontSize={counterSize}
- color={t.fg}
- mutedColor={t.fgMuted}
- />
+ <Odometer current={current} fontSize={counterSize} color={t.fg} />
</div>
{underline}
<div
@@ -1253,12 +1128,7 @@ export function GitHubStars({
>
<StarGlyph size={starSize} fill={accentColor} />
<div style={{ height: 20 }} />
- <Odometer
- current={current}
- fontSize={counterSize}
- color={t.fg}
- mutedColor={t.fgMuted}
- />
+ <Odometer current={current} fontSize={counterSize} color={t.fg} />
<div style={{ height: 16 }} />
{underline}
<div style={{ height: 20 }} />
diff --git a/registry/remocn/number-wheel/config.ts b/registry/remocn/number-wheel/config.ts
new file mode 100644
index 00000000..d120e2c3
--- /dev/null
+++ b/registry/remocn/number-wheel/config.ts
@@ -0,0 +1,38 @@
+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";
+
+export const numberWheelConfig: ComponentConfig = {
+ componentName: "NumberWheel",
+ importPath: "@/components/remocn/number-wheel",
+ controls: {
+ from: {
+ type: "number",
+ default: 0,
+ min: 0,
+ max: 1000000,
+ step: 1,
+ label: "From",
+ },
+ to: {
+ type: "number",
+ default: 24813,
+ min: 0,
+ max: 1000000,
+ step: 1,
+ label: "To",
+ },
+ fontSize: {
+ type: "number",
+ default: 120,
+ min: 24,
+ max: 280,
+ step: 4,
+ label: "Font size",
+ },
+ color: { type: "color", default: "#171717", label: "Color" },
+ },
+ durationInFrames: 112,
+ fps: FPS,
+ compositionWidth: W,
+ compositionHeight: H,
+ previewBackdrop: { type: "color", value: "#ffffff" },
+};
diff --git a/registry/remocn/number-wheel/index.tsx b/registry/remocn/number-wheel/index.tsx
new file mode 100644
index 00000000..0c8de122
--- /dev/null
+++ b/registry/remocn/number-wheel/index.tsx
@@ -0,0 +1,241 @@
+"use client";
+
+import type React from "react";
+import { loadFont as loadMono } from "@remotion/google-fonts/JetBrainsMono";
+import {
+ AbsoluteFill,
+ Easing,
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+
+const { fontFamily: MONO_FAMILY } = loadMono();
+
+export interface NumberWheelProps {
+ from?: number;
+ to?: number;
+ fontSize?: number;
+ color?: string;
+ speed?: number;
+}
+
+export interface OdometerProps {
+ current: number;
+ fontSize: number;
+ color: string;
+}
+
+const WHEEL_ROLL_START = 0.9;
+const SPRING_FRAMES = 30;
+const SPRING_CONFIG = { damping: 200, stiffness: 100, mass: 1 } as const;
+const COUNT_PORTION = 0.8;
+
+function rollFraction(current: number, place: number): number {
+ const v = current / 10 ** place;
+ const frac = v - Math.floor(v);
+ if (frac <= WHEEL_ROLL_START) return 0;
+ return (frac - WHEEL_ROLL_START) / (1 - WHEEL_ROLL_START);
+}
+
+function computeWheel(
+ current: number,
+ place: number,
+ springEased: (t: number) => number,
+): number {
+ if (current <= 0) return 0;
+ if (place === 0) return current % 10;
+
+ const digit = Math.floor(current / 10 ** place) % 10;
+ const t = rollFraction(current, place);
+ if (t <= 0) return digit;
+ return digit + springEased(t);
+}
+
+function placeOpacity(current: number, place: number): number {
+ if (place === 0) return 1;
+ const threshold = 10 ** place;
+ return interpolate(current, [threshold * 0.9, threshold], [0, 1], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+}
+
+function DigitColumn({
+ value,
+ fontSize,
+ opacity,
+}: {
+ value: number;
+ fontSize: number;
+ opacity: number;
+}) {
+ const cellHeight = fontSize * 1.1;
+ return (
+ <span
+ style={{
+ display: "inline-block",
+ overflow: "hidden",
+ height: cellHeight,
+ width: "0.62em",
+ verticalAlign: "top",
+ textAlign: "center",
+ opacity,
+ }}
+ >
+ <span
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ transform: `translateY(${-value * cellHeight}px)`,
+ }}
+ >
+ {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0].map((d, i) => (
+ <span
+ key={i}
+ style={{ height: cellHeight, lineHeight: `${cellHeight}px` }}
+ >
+ {d}
+ </span>
+ ))}
+ </span>
+ </span>
+ );
+}
+
+function OdometerColumns({
+ current,
+ templateValue,
+ fontSize,
+ color,
+ fps,
+}: {
+ current: number;
+ templateValue: number;
+ fontSize: number;
+ color: string;
+ fps: number;
+}) {
+ const springAtEnd = spring({
+ frame: SPRING_FRAMES,
+ fps,
+ config: SPRING_CONFIG,
+ });
+ const springEased = (t: number) =>
+ spring({ frame: t * SPRING_FRAMES, fps, config: SPRING_CONFIG }) /
+ springAtEnd;
+
+ const template = templateValue.toLocaleString("en-US");
+
+ const cells: React.ReactNode[] = [];
+ let place = 0;
+ for (let i = template.length - 1; i >= 0; i--) {
+ const ch = template[i];
+ if (ch === ",") {
+ cells.unshift(
+ <span
+ key={`c${i}`}
+ style={{
+ display: "inline-block",
+ width: "0.32em",
+ color: "currentColor",
+ fontSize: "0.85em",
+ textAlign: "center",
+ opacity: placeOpacity(current, place),
+ }}
+ >
+ ,
+ </span>,
+ );
+ } else {
+ const wheel = computeWheel(current, place, springEased);
+ cells.unshift(
+ <DigitColumn
+ key={`d${i}`}
+ value={wheel}
+ fontSize={fontSize}
+ opacity={placeOpacity(current, place)}
+ />,
+ );
+ place++;
+ }
+ }
+
+ return (
+ <div
+ style={{
+ display: "flex",
+ alignItems: "baseline",
+ fontSize,
+ fontWeight: 800,
+ color,
+ fontFamily: MONO_FAMILY,
+ fontVariantNumeric: "tabular-nums",
+ letterSpacing: "-0.03em",
+ lineHeight: 1,
+ }}
+ >
+ {cells}
+ </div>
+ );
+}
+
+export function Odometer({ current, fontSize, color }: OdometerProps) {
+ const { fps } = useVideoConfig();
+ const value = Math.max(0, Math.round(current));
+ return (
+ <OdometerColumns
+ current={current}
+ templateValue={value}
+ fontSize={fontSize}
+ color={color}
+ fps={fps}
+ />
+ );
+}
+
+export function NumberWheel({
+ from = 0,
+ to = 24813,
+ fontSize = 120,
+ color = "#171717",
+ speed = 1,
+}: NumberWheelProps) {
+ const frame = useCurrentFrame();
+ const { durationInFrames, fps } = useVideoConfig();
+
+ const start = Math.max(0, Math.round(from));
+ const end = Math.max(0, Math.round(to));
+
+ const progress = interpolate(
+ frame * speed,
+ [0, durationInFrames * COUNT_PORTION],
+ [0, 1],
+ {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ easing: Easing.bezier(0.5, 1, 0.5, 1),
+ },
+ );
+ const current = Math.max(0, start + progress * (end - start));
+ const maxVal = Math.max(start, end);
+
+ return (
+ <AbsoluteFill
+ style={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ <OdometerColumns
+ current={current}
+ templateValue={maxVal}
+ fontSize={fontSize}
+ color={color}
+ fps={fps}
+ />
+ </AbsoluteFill>
+ );
+}
diff --git a/registry/remocn/registry.json b/registry/remocn/registry.json
index 1a03547c..63805263 100644
--- a/registry/remocn/registry.json
+++ b/registry/remocn/registry.json
@@ -769,6 +769,9 @@
"date-fns",
"@remotion/google-fonts"
],
+ "registryDependencies": [
+ "@remocn/number-wheel"
+ ],
"files": [
{
"path": "github-stars/index.tsx",
@@ -777,6 +780,23 @@
}
]
},
+ {
+ "name": "number-wheel",
+ "type": "registry:component",
+ "title": "Number Wheel",
+ "description": "Mechanical odometer that rolls an integer up or down to its target, direction inferred from the values.",
+ "dependencies": [
+ "remotion",
+ "@remotion/google-fonts"
+ ],
+ "files": [
+ {
+ "path": "number-wheel/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/number-wheel.tsx"
+ }
+ ]
+ },
{
"name": "x-follow-card",
"type": "registry:component",
diff --git a/tsconfig.json b/tsconfig.json
index fd4bbc54..a529f6f0 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -37,6 +37,7 @@
"@/components/remocn/use-slider-transition": ["./registry/remocn-ui/slider/use-slider-transition.ts"],
"@/components/remocn/use-blur-in-transition": ["./registry/remocn-ui/blur-in/use-blur-in-transition.ts"],
"@/components/remocn/confetti": ["./registry/remocn/confetti/index.tsx"],
+ "@/components/remocn/number-wheel": ["./registry/remocn/number-wheel/index.tsx"],
"@/components/remocn/*": ["./registry/remocn-ui/*/index.tsx"],
"@/*": ["./*"]
}