@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 50 lines 1.65 KB
Raw
1 import { useGT } from "gt-react";
2 import { memo } from "react";
3 import { cn } from "~/lib/utils";
4
5 export function hasNonZeroStat(stat: { additions: number; deletions: number }): boolean {
6 return stat.additions > 0 || stat.deletions > 0;
7 }
8
9 export function formatCompactDiffCount(value: number): string {
10 if (value < 1000) return String(value);
11 if (value < 999_500) {
12 const k = value / 1000;
13 return `${k < 10 ? k.toFixed(1).replace(/\.0$/, "") : Math.round(k)}k`;
14 }
15 if (value < 999_500_000) {
16 const m = value / 1_000_000;
17 return `${m < 10 ? m.toFixed(1).replace(/\.0$/, "") : Math.round(m)}m`;
18 }
19 const b = value / 1_000_000_000;
20 return `${b < 10 ? b.toFixed(1).replace(/\.0$/, "") : Math.round(b)}b`;
21 }
22
23 export const DiffStatLabel = memo(function DiffStatLabel(props: {
24 additions: number;
25 deletions: number;
26 className?: string;
27 layout?: "aligned" | "inline";
28 }) {
29 const { additions, deletions, className, layout = "aligned" } = props;
30 const gt = useGT();
31 return (
32 <span
33 role="group"
34 aria-label={gt("{additions} additions, {deletions} deletions", { additions, deletions })}
35 className={cn(
36 layout === "inline"
37 ? "inline-flex items-center gap-1 tabular-nums align-middle"
38 : "inline-grid grid-cols-[4ch_4ch] gap-2 text-right tabular-nums align-middle",
39 className,
40 )}
41 >
42 <span aria-hidden="true" className="font-mono text-diff-addition-foreground">
43 +{formatCompactDiffCount(additions)}
44 </span>
45 <span aria-hidden="true" className="font-mono text-diff-deletion-foreground">
46 -{formatCompactDiffCount(deletions)}
47 </span>
48 </span>
49 );
50 });