Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Share NumberTicker from packages/ui and retire NumberFlow (#3324)

Luke Vella30a437bd1158
diff --git a/apps/landing/package.json b/apps/landing/package.json
index ea9dd887b..a6171357c 100644
--- a/apps/landing/package.json
+++ b/apps/landing/package.json
@@ -11,7 +11,6 @@
"i18n:scan": "i18next-cli extract"
},
"dependencies": {
- "@number-flow/react": "^0.6.2",
"@prisma/adapter-pg": "^7.8.0",
"@prisma/client": "^7.8.0",
"@rallly/billing": "workspace:*",
diff --git a/apps/landing/src/app/[locale]/(main)/pricing/pricing-controls.tsx b/apps/landing/src/app/[locale]/(main)/pricing/pricing-controls.tsx
index c89582eb9..4659b6af5 100644
--- a/apps/landing/src/app/[locale]/(main)/pricing/pricing-controls.tsx
+++ b/apps/landing/src/app/[locale]/(main)/pricing/pricing-controls.tsx
@@ -1,8 +1,8 @@
"use client";
-import NumberFlow from "@number-flow/react";
import type { PricesByCurrency } from "@rallly/billing";
import { cn } from "@rallly/ui";
+import { NumberTicker } from "@rallly/ui/number-ticker";
import {
Select,
SelectContent,
@@ -194,22 +194,29 @@ export function YearlySavingsBadge({
export function PlanPrice() {
const { interval, currency, prices, locale } = usePricing();
const amounts = prices[currency];
- if (!amounts) {
- return null;
- }
- const value =
- interval === "yearly" ? amounts.yearly / 12 / 100 : amounts.monthly / 100;
- return (
- <NumberFlow
- value={value}
- locales={locale}
- format={{
+ // NumberTicker rounds its value before formatting, so it is driven in minor
+ // units and the formatter divides — otherwise a monthly-equivalent yearly
+ // price like 8.33 would render as 8.
+ const format = React.useCallback(
+ (minorUnits: number) =>
+ new Intl.NumberFormat(locale, {
style: "currency",
currency: currency.toUpperCase(),
minimumFractionDigits: 0,
maximumFractionDigits: 2,
- }}
- />
+ }).format(minorUnits / 100),
+ [locale, currency],
+ );
+
+ if (!amounts) {
+ return null;
+ }
+
+ const minorUnits =
+ interval === "yearly" ? Math.round(amounts.yearly / 12) : amounts.monthly;
+
+ return (
+ <NumberTicker value={minorUnits} startOnView={false} format={format} />
);
}
diff --git a/apps/landing/src/components/home/animated-number.tsx b/apps/landing/src/components/home/animated-number.tsx
index 25a20d211..1707479d7 100644
--- a/apps/landing/src/components/home/animated-number.tsx
+++ b/apps/landing/src/components/home/animated-number.tsx
@@ -1,6 +1,6 @@
"use client";
-import NumberFlow from "@number-flow/react";
+import { NumberTicker } from "@rallly/ui/number-ticker";
import { BarChart2Icon, UsersIcon } from "lucide-react";
import * as React from "react";
@@ -95,8 +95,6 @@ function AnimatedNumber({
live?: boolean;
}) {
const [rolledUp, setRolledUp] = React.useState(false);
- const [shown, setShown] = React.useState(value);
- const [animated, setAnimated] = React.useState(false);
const ref = React.useRef<HTMLSpanElement>(null);
const live = useLiveCount({
@@ -106,16 +104,15 @@ function AnimatedNumber({
enabled: liveEnabled && rolledUp,
});
+ // NumberTicker's own startOnView drives the roll-up; this watches the same
+ // threshold only to know when it has finished, so the live tick can take
+ // over. Timing from mount instead would start the clock while the badge is
+ // still below the fold and hand over before the digits had moved.
React.useEffect(() => {
const el = ref.current;
- if (!el) {
+ if (!el || !liveEnabled) {
return;
}
- if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
- setRolledUp(true);
- return;
- }
- let frame: number;
let settle: number;
const observer = new IntersectionObserver(
([entry]) => {
@@ -123,38 +120,24 @@ function AnimatedNumber({
return;
}
observer.disconnect();
- // Two committed renders: drop to 0 without animation, then roll up.
- setShown(0);
- frame = requestAnimationFrame(() => {
- frame = requestAnimationFrame(() => {
- setAnimated(true);
- setShown(value);
- settle = window.setTimeout(() => setRolledUp(true), DURATION_MS);
- });
- });
+ settle = window.setTimeout(() => setRolledUp(true), DURATION_MS);
},
- { threshold: 0.5 },
+ { threshold: 0.6 },
);
observer.observe(el);
return () => {
observer.disconnect();
- cancelAnimationFrame(frame);
window.clearTimeout(settle);
};
- }, [value]);
+ }, [liveEnabled]);
- // Once ticking, the live value drives the display; before that the roll-up
- // owns it.
- const target = liveEnabled && rolledUp ? live : shown;
- // The sizer keeps the translation's own token unless ticking has pushed the
- // number past it, so a badge that never ticks measures exactly as before and
- // a ticking one never reflows the sentence as digits are added.
- const sizerText =
- live > value ? new Intl.NumberFormat(locale).format(live) : display;
+ const target = liveEnabled && rolledUp ? live : value;
+ const format = React.useCallback(
+ (n: number) => new Intl.NumberFormat(locale).format(n),
+ [locale],
+ );
return (
- // tabular-nums keeps the sizer and NumberFlow (which renders digits at a
- // uniform width) measuring identically.
<span
ref={ref}
role="img"
@@ -162,38 +145,13 @@ function AnimatedNumber({
// liveness flourish, and a label that mutates every minute would be
// churn for assistive tech without conveying anything new.
aria-label={display}
- className="relative inline-block tabular-nums"
+ className="inline-block tabular-nums"
>
- {/* Invisible copy of the final number holds its width for the whole
- animation so the surrounding text doesn't shift as digits roll in.
- Rendered as a pseudo-element rather than a text node so extractors
- (search snippets, reader mode) don't see the number twice — the
- readable copy is NumberFlow's own light-DOM text */}
- <span
- className="invisible before:content-[attr(data-value)]"
- data-value={sizerText}
- aria-hidden="true"
+ <NumberTicker
+ value={target}
+ format={format}
+ duration={DURATION_MS / 1000}
/>
- {/* NumberFlow's box is taller than the text (mask padding) but
- symmetric around the glyphs, so centering it on the sizer — also
- symmetric — puts both baselines in the same place */}
- <span
- className="absolute inset-0 flex items-center justify-end"
- aria-hidden="true"
- >
- <NumberFlow
- value={target}
- locales={locale}
- animated={animated}
- // Layout snaps instantly so digits spin straight vertically in
- // place instead of sliding sideways while the width grows.
- transformTiming={{ duration: 0 }}
- spinTiming={{
- duration: DURATION_MS,
- easing: "cubic-bezier(0.16, 1, 0.3, 1)",
- }}
- />
- </span>
</span>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx
index 710e841d2..7ba9ce3aa 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx
@@ -12,9 +12,9 @@ import {
DialogHeader,
DialogTitle,
} from "@rallly/ui/dialog";
+import { NumberTicker } from "@rallly/ui/number-ticker";
import { MinusIcon, PlusIcon } from "lucide-react";
import * as React from "react";
-import { NumberTicker } from "@/components/number-ticker";
import { Trans } from "@/i18n/client";
import { trpc } from "@/trpc/client";
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 17b7e15dd..44b89aaf5 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -39,6 +39,7 @@
"lucide-react": "^0.479.0",
"mdast-util-gfm-autolink-literal": "^2.0.1",
"micromark-extension-gfm-autolink-literal": "^2.1.0",
+ "motion": "^12.6.2",
"next-themes": "^0.4.6",
"react": "19.2.6",
"react-aria-components": "^1.16.0",
diff --git a/apps/web/src/lib/ease.ts b/packages/ui/src/ease.ts
similarity index 100%
rename from apps/web/src/lib/ease.ts
rename to packages/ui/src/ease.ts
diff --git a/apps/web/src/components/number-ticker.tsx b/packages/ui/src/number-ticker.tsx
similarity index 98%
rename from apps/web/src/components/number-ticker.tsx
rename to packages/ui/src/number-ticker.tsx
index 23e44a0c5..b962b0c1a 100644
--- a/apps/web/src/components/number-ticker.tsx
+++ b/packages/ui/src/number-ticker.tsx
@@ -1,10 +1,11 @@
"use client";
+
// beui.dev/components/motion/number
-import { cn } from "@rallly/ui";
import { animate, motion, useInView, useReducedMotion } from "motion/react";
import { useEffect, useMemo, useRef, useState } from "react";
-import { EASE_OUT } from "@/lib/ease";
+import { EASE_OUT } from "./ease";
+import { cn } from "./lib/utils";
export interface NumberTickerProps {
value: number;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0dba81178..70d6dbb25 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -65,9 +65,6 @@ importers:
apps/landing:
dependencies:
- '@number-flow/react':
- specifier: ^0.6.2
'@prisma/adapter-pg':
specifier: ^7.8.0
version: 7.8.0
@@ -630,7 +627,7 @@ importers:
version: link:../tsconfig
'@react-email/ui':
specifier: ^6.9.3
'@types/react':
specifier: 19.2.13
version: 19.2.13
@@ -843,6 +840,9 @@ importers:
micromark-extension-gfm-autolink-literal:
specifier: ^2.1.0
version: 2.1.0
+ motion:
+ specifier: ^12.6.2
next-themes:
specifier: ^0.4.6
@@ -3467,12 +3467,6 @@ packages:
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
engines: {node: '>= 8'}
- '@number-flow/[email protected]':
- resolution: {integrity: sha512-WjZuV4aA+vhRCgCF+adGLgFVVAJ8vdvq6EchRT2FiBIgElTXtDOA3YgkcMr9UHpvpS9v4H70AB5wZv0D9jc3QA==}
- peerDependencies:
- react: ^18 || ^19
- react-dom: ^18 || ^19
-
'@openai/[email protected]':
resolution: {integrity: sha512-R00Rz5327LefZggAxl28r7vFQq1vxa91OxtjZJOsQfAM/MyH8InW5qwwRu6pzUmRGp1E29XrOzm7u1TeV5Yz2A==}
engines: {node: '>=18'}
@@ -8252,9 +8246,6 @@ packages:
jiti:
optional: true
- resolution: {integrity: sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA==}
-
resolution: {integrity: sha512-7p3DrVEIopW1B1avAGLuCSh1jubc01H2JHc8B4qqGblmg5gI9yumBgACjWo4JlIc04ufug4xJ3SQI8HkS/Rgzw==}
engines: {node: ^20.19.0 || ^22.13.0 || >=24}
@@ -10252,9 +10243,6 @@ packages:
resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==}
- resolution: {integrity: sha512-MCnImG4Q5vPwhSXnov56nOuyyKn6LC+Qd7II1UiKc+ACRtug5iAtn0+CwXNxM38AC5lSowEY+oYEtZX2qMnUyw==}
-
resolution: {integrity: sha512-7wfH4sLbt4M0gCDzGE6vzQBo0bfTKjU7Sfpqy/7gs1qBfYz2vEJH6vXcBKpO3+6Yu1telwd0t9HpyOoLEQQbIQ==}
@@ -15956,13 +15944,6 @@ snapshots:
'@nodelib/fs.scandir': 2.1.5
fastq: 1.20.1
- dependencies:
- esm-env: 1.2.2
- number-flow: 0.6.2
- react: 19.2.6
- react-dom: 19.2.6([email protected])
-
'@openai/[email protected]':
dependencies:
'@openai/codex': 0.149.1
@@ -17498,10 +17479,10 @@ snapshots:
dependencies:
react: 19.2.6
dependencies:
esbuild: 0.28.1
transitivePeerDependencies:
- '@babel/core'
- '@opentelemetry/api'
@@ -21417,8 +21398,6 @@ snapshots:
transitivePeerDependencies:
- supports-color
-
dependencies:
acorn: 8.18.0
@@ -23947,7 +23926,7 @@ snapshots:
- '@types/node'
- babel-plugin-macros
dependencies:
'@next/env': 16.3.3
'@swc/helpers': 0.5.23
@@ -24038,10 +24017,6 @@ snapshots:
dependencies:
boolbase: 1.0.0
- dependencies:
- esm-env: 1.2.2
-