Collection
Business / Finance · v0.2.1Validated
Track assets, debts, and the change in net worth across the last six readings.
Net Worth · Preview
Loading widget…
Preparing source code…
Idle
Business / Finance · v0.2.1Validated
Track assets, debts, and the change in net worth across the last six readings.
Loading widget…
Preparing source code…
Load the Lumo theme once in your app entry point. The example uses the local Lumo workspace packages.
import "@lumo/tokens/tokens.css";
import { NetWorthWidget } from "@lumo/widgets/catalog/finance/net-worth";
export default function Example() {
return <NetWorthWidget />;
}Props for integrating the React component in your app.
historyreadonly NetWorthPoint[] | null (optional){
"history": [
{
"date": "2026-10-31",
"assetsMinor": 12530000,
"debtsMinor": 3450000
},
{
"date": "2026-11-24",
"assetsMinor": 12875000,
"debtsMinor": 3200000
}
]
}import type { NetWorthPoint } from "@lumo/widgets/catalog/finance/net-worth";
type Day = { date: string; assetsUsdCents: number[]; debtsUsdCents: number[] };
export function toHistory(days: readonly Day[]): NetWorthPoint[] {
return days.map(day => ({
date: day.date,
assetsMinor: day.assetsUsdCents.reduce((sum, cents) => sum + cents, 0),
debtsMinor: day.debtsUsdCents.reduce((sum, cents) => sum + cents, 0),
}));
}"use client";
import { Scale } from "lucide-react";
import { useMemo, useState, type KeyboardEvent } from "react";
import { AnimatedNumber, WidgetChart } from "@lumo/ui";
import { WidgetHeader } from "../support/layout";
import { FinanceTile } from "./FinanceTile";
import { shortUsd, signedUsd, USD_SHORT, usd } from "./finance-money";
import shared from "./finance-overview.module.css";
import { NET_WORTH_DATE, NET_WORTH_DEMO } from "./net-worth.constants";
import { readNetWorth } from "./net-worth-model";
import { WidgetChartArea } from "../../shared/WidgetChartArea";
import { useChartScrub } from "../../shared/use-chart-scrub";
import styles from "./net-worth.module.css";
import type { NetWorthWidgetProps } from "./net-worth.types";
export type { NetWorthPoint, NetWorthWidgetProps } from "./net-worth.types";
export function NetWorthWidget({ history = NET_WORTH_DEMO }: NetWorthWidgetProps = {}) {
const model = useMemo(() => history === null ? null : readNetWorth(history), [history]);
const [picked, setPicked] = useState<number>();
const found = model?.points.findIndex(point => point.date.getTime() === picked) ?? -1;
const index = found >= 0 ? found : (model?.points.length ?? 1) - 1;
const reading = model?.points[index];
const marker = model?.plotted[index];
function select(at: number) {
if (!model) return;
const last = model.points.length - 1;
const next = Math.min(last, Math.max(0, at));
setPicked(next === last ? undefined : model.points[next].date.getTime());
}
const scrub = useChartScrub(fraction => {
if (!model) return;
const nearest = model.plotted.reduce((best, point, i) =>
Math.abs(point.x - fraction * 100) < Math.abs(model.plotted[best].x - fraction * 100) ? i : best, 0);
select(nearest);
}, Boolean(model?.hasTrend), { commitOnRelease: true, onPress: event => event.currentTarget.focus({ preventScroll: true }) });
function navigate(event: KeyboardEvent<HTMLElement>) {
if (!model) return;
const next = event.key === "ArrowLeft" ? index - 1 : event.key === "ArrowRight" ? index + 1
: event.key === "Home" ? 0 : event.key === "End" ? model.points.length - 1 : null;
if (next === null) return;
event.preventDefault();
event.stopPropagation();
select(next);
}
const delta = reading && model ? reading.net - model.first.net : 0;
return <FinanceTile label="Net worth">
<WidgetHeader icon={<Scale />} title="Net Worth" tint="var(--success)"
subtitle={reading ? `As of ${NET_WORTH_DATE.format(reading.date)}` : undefined} />
{model && reading ? <>
<div className={styles.reading}>
<span role="group" aria-label={`${usd(reading.net)} net worth`} title={usd(reading.net)}><span aria-hidden="true"><AnimatedNumber value={reading.net / 100} format={USD_SHORT} className={styles.amount} /></span></span>
<div className={styles.change}>
{model.hasTrend && index > 0 && <><strong data-direction={Math.sign(delta)}>{signedUsd(delta)}</strong>
<span>vs {NET_WORTH_DATE.format(model.first.date)}</span></>}
</div>
</div>
{model.hasTrend && marker && <WidgetChart className={styles.plot} tabIndex={0} role="slider"
aria-label="Net worth history" aria-valuemin={1} aria-valuemax={model.points.length} aria-valuenow={index + 1}
aria-valuetext={`${NET_WORTH_DATE.format(reading.date)}, ${usd(reading.net)} net worth`}
onKeyDown={navigate} {...scrub} data-swipe-ignore data-studio-swipe-ignore>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" className={styles.chart} aria-hidden="true">
<WidgetChartArea path={model.path} color="var(--success)" baseline={{ y: 100, from: 2, to: 98 }} />
<path d={model.path} className={styles.line} />
<line x1={marker.x} x2={marker.x} y1="0" y2="100" className={styles.cursor} />
</svg>
<span className={styles.dot} aria-hidden="true" style={{ left: `${marker.x}%`, top: `${marker.y}%` }} />
</WidgetChart>}
<dl className={styles.breakdown}>
<div><dt>Assets</dt><dd title={usd(reading.assetsMinor)}>{shortUsd(reading.assetsMinor)}</dd></div>
<div><dt>Debts</dt><dd title={usd(reading.debtsMinor)}>{shortUsd(reading.debtsMinor)}</dd></div>
</dl>
</> : <p className={shared.empty}>{history === null ? "Balance history unavailable" : "No balance history"}</p>}
</FinanceTile>;
}
clsxlucide-reactmotionreactreact-domtailwind-merge