11import { type ReactNode } from "react" ;
22import { AnimatedNumber } from "../primitives/AnimatedNumber" ;
33import { Spinner } from "../primitives/Spinner" ;
4+ import { SimpleTooltip } from "../primitives/Tooltip" ;
45import { cn } from "~/utils/cn" ;
6+ import { formatNumber , formatNumberCompact } from "~/utils/numberFormatter" ;
7+ import { Header3 } from "../primitives/Headers" ;
58
69interface BigNumberProps {
710 title : ReactNode ;
@@ -13,6 +16,7 @@ interface BigNumberProps {
1316 accessory ?: ReactNode ;
1417 suffix ?: string ;
1518 suffixClassName ?: string ;
19+ compactThreshold ?: number ;
1620}
1721
1822export 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 ) : (
0 commit comments