Budgets, each one's spending against its limit, the limit changed in place
The list's budgets option
The budgets option of docs/screen-list.md, for money held to a limit a period (a household's categories, a team's monthly spend): not in place of the list, a page of its own beside it (src/screens/budgets.tsx, its route /budgets, the same frame). It draws ListPage arrangement="plain"; the chooser (agent/layout-chooser.md) names the others, the same slots. By hand: copy the file below whole, then add the two lines of the app block to App.tsx (its import beside the screens', its route after the last) and the frame block's row to the frame's NAVIGATION (docs/screen-frame.md), before Settings. node goop/agent/start.mjs list:budgets does all three.
budgets: a card a budget, its meter and its limit
The page's heading says what is spent of what is budgeted this period, over a CardGrid of one outline Card a budget: its name, a Meter of what is spent against the limit (its tick at 80 %, past it the fill in the warning colour and its icon), what is left or how far over, and the limit in a NumberInput with its stepper, in whole units. A limit changed there is the page's at once: the meter, the words under it and the heading's total follow. Keep the budgets in your store, so every other screen reads the same limits; light, dark, phone and desktop are the parts' own: add no class for them.
`tsx budgets // src/screens/budgets.tsx: each budget's spending against its limit, the limit changed in place import { useState } from 'react'; import { ListPage } from '@/components/goop/patterns/list-page'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/goop/card'; import { CardGrid, CardGridItem } from '@/components/ui/goop/card-grid'; import { Meter, MeterLabel, MeterValue } from '@/components/ui/goop/meter'; import { NumberInput } from '@/components/ui/goop/number-input'; import { PageHeader, PageHeaderContent, PageHeaderDescription, PageHeaderTitle, } from '@/components/ui/goop/page-header'; import { ScreenFrame, ScreenTopBar } from './frame';
// ---- the sample data: swap it for yours const CURRENCY = 'EUR'; const PERIOD = 'November'; interface Budget { id: string; name: string; /** Spent this period and the limit, in whole units. */ spent: number; limit: number; } const BUDGETS: Budget[] = [ { id: 'incentives', name: 'Participant thank-yous', spent: 420, limit: 600 }, { id: 'travel', name: 'Travel to sites', spent: 515, limit: 500 }, { id: 'software', name: 'Software', spent: 180, limit: 240 }, { id: 'printing', name: 'Printing', spent: 35, limit: 120 }, { id: 'coffee', name: 'Coffee and snacks', spent: 88, limit: 100 }, ];
// ---- the page const money = new Intl.NumberFormat(undefined, { style: 'currency', currency: CURRENCY, maximumFractionDigits: 0 });
export default function BudgetsScreen() { const [budgets, setBudgets] = useState(BUDGETS); const spent = budgets.reduce((sum, one) => sum + one.spent, 0); const budgeted = budgets.reduce((sum, one) => sum + one.limit, 0); const setLimit = (id: string, limit: number) => setBudgets((all) => all.map((one) => (one.id === id ? { ...one, limit } : one))); return ( <ScreenFrame current="/budgets"> <ListPage arrangement="plain" header={<ScreenTopBar title="Budgets" />} heading={ <PageHeader> <PageHeaderContent> <PageHeaderTitle asChild> <h1>Budgets</h1> </PageHeaderTitle> <PageHeaderDescription> {${money.format(spent)} spent of ${money.format(budgeted)} budgeted for ${PERIOD}.} </PageHeaderDescription> </PageHeaderContent> </PageHeader> } collection={ <CardGrid aria-label="Budgets"> {budgets.map((one) => { const left = one.limit - one.spent; return ( <CardGridItem key={one.id}> <Card variant="outline"> <CardHeader> <CardTitle asChild> <h2>{one.name}</h2> </CardTitle> <CardDescription> {left < 0 ? ${money.format(-left)} over : ${money.format(left)} left} </CardDescription> </CardHeader> <CardContent className="flex flex-col gap-3"> <Meter value={one.spent} max={Math.max(one.limit, 1)} threshold={one.limit * 0.8} valueText={${money.format(one.spent)} of ${money.format(one.limit)}} > <MeterLabel>Spent</MeterLabel> <MeterValue>{${money.format(one.spent)} of ${money.format(one.limit)}}</MeterValue> </Meter> <NumberInput aria-label={Limit for ${one.name}} stepper min={0} step={10} format={(value) => money.format(value)} value={one.limit} onValueChange={(limit) => setLimit(one.id, Math.max(0, Math.round(limit ?? 0)))} /> </CardContent> </Card> </CardGridItem> ); })} </CardGrid> } /> </ScreenFrame> ); }
```tsx app
import BudgetsScreen from './screens/budgets';
if (page === 'budgets') return <BudgetsScreen />;`tsx frame { words: 'Budgets', path: '/budgets', icon: 'chart-bar' },