Skip to content

Commit b25c064

Browse files
committed
BigNumber now handles big values using formatNumber and formatNumberCompact
Also includes some responsive improvements to make sure things wrap when it gets tight
1 parent 92835f1 commit b25c064

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

apps/webapp/app/components/metrics/BigNumber.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { type ReactNode } from "react";
22
import { AnimatedNumber } from "../primitives/AnimatedNumber";
33
import { Spinner } from "../primitives/Spinner";
4+
import { SimpleTooltip } from "../primitives/Tooltip";
45
import { cn } from "~/utils/cn";
6+
import { formatNumber, formatNumberCompact } from "~/utils/numberFormatter";
7+
import { Header3 } from "../primitives/Headers";
58

69
interface BigNumberProps {
710
title: ReactNode;
@@ -13,6 +16,7 @@ interface BigNumberProps {
1316
accessory?: ReactNode;
1417
suffix?: string;
1518
suffixClassName?: string;
19+
compactThreshold?: number;
1620
}
1721

1822
export function BigNumber({
@@ -25,25 +29,42 @@ export function BigNumber({
2529
accessory,
2630
animate = false,
2731
loading = false,
32+
compactThreshold = 100000,
2833
}: BigNumberProps) {
2934
const v = value ?? defaultValue;
35+
36+
const formatValue = (num: number) => {
37+
return num >= compactThreshold ? formatNumberCompact(num) : formatNumber(num);
38+
};
39+
40+
const shouldCompact = v !== undefined && v >= compactThreshold;
41+
3042
return (
31-
<div className="grid grid-rows-[1.5rem_auto] gap-4 rounded-sm border border-grid-dimmed bg-background-bright p-4">
32-
<div className="flex items-center justify-between">
33-
<div className="text-2sm text-text-dimmed">{title}</div>
43+
<div className="flex flex-col justify-between gap-4 rounded-sm border border-grid-dimmed bg-background-bright p-4">
44+
<div className="flex flex-wrap items-center justify-between gap-2">
45+
<Header3 className="leading-6">{title}</Header3>
3446
{accessory && <div className="flex-shrink-0">{accessory}</div>}
3547
</div>
3648
<div
3749
className={cn(
38-
"h-[3.75rem] text-[3.75rem] font-normal tabular-nums leading-none text-text-bright",
50+
"text-[3.75rem] font-normal tabular-nums leading-none text-text-bright",
3951
valueClassName
4052
)}
4153
>
4254
{loading ? (
4355
<Spinner className="size-6" />
4456
) : v !== undefined ? (
45-
<div className="flex items-baseline gap-1">
46-
{animate ? <AnimatedNumber value={v} /> : v}
57+
<div className="flex flex-wrap items-baseline gap-2">
58+
{shouldCompact ? (
59+
<SimpleTooltip
60+
button={animate ? <AnimatedNumber value={v} /> : formatValue(v)}
61+
content={formatNumber(v)}
62+
/>
63+
) : animate ? (
64+
<AnimatedNumber value={v} />
65+
) : (
66+
formatValue(v)
67+
)}
4768
{suffix && <div className={cn("text-xs", suffixClassName)}>{suffix}</div>}
4869
</div>
4970
) : (

apps/webapp/app/components/primitives/AnimatedNumber.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { motion, useSpring, useTransform, useMotionValue, animate } from "framer-motion";
1+
import { animate, motion, useMotionValue, useTransform } from "framer-motion";
22
import { useEffect } from "react";
33

44
export function AnimatedNumber({ value }: { value: number }) {

0 commit comments

Comments
 (0)