shadcn.io is not affiliated with official shadcn/ui
Spend by Project Billing Block for React
Spend management for a usage-billed product: this period's spend per project, a budget bar with a tick at the alert threshold, the trend against last period, inline budget editing and the account's hard cap.
Installation
Overview
Let a team see where the money goes and cap it, inside your app, with this spend by project section for React with Base UI. A hairline frame with a plus mark on each corner holds a summary and one row per project (an edge gateway, inference workers, a marketing site, preview builds and an analytics warehouse). The summary puts the total spent beside the account's hard cap on a Progress bar in your foreground color, with what is left, what happens at the cap, the period, and the budgets set so far as a Data List. Each row gives the project, its team, the spend, a trend against the same days of last period, and a Progress bar for the spend against the project's budget, with a tick where its alert fires. The bar keeps your foreground color until the tick, then takes the warning tone and a "Past alert" Badge; past the budget it fills in the destructive tone and the badge reads "Over budget". "Edit budget" turns the line under the bar into two Number Inputs, the budget in dollars and the alert in percent, and the bar and tick follow as you type. A Shine Button saves every change at once, the only colored control, and rows are ruled with Guides. For usage-billed SaaS, hosting, AI APIs and admin consoles.
FAQ
How do I fill it with my own spend?
Everything comes from two constants at the top of the file. ACCOUNT holds the hard cap in dollars, the period's first and last day, the day the spend runs through and the same day of the period before (all ISO dates, written in UTC so they read the same in every time zone). PROJECTS lists each project's name, team, spend so far, prior (what it had spent on the same days last period, which is what the trend compares with), its budget and its alert as a percent of the budget. Replace them with your own metering, and pass them in as props if the page fetches them.
What does the tick on each bar mean?
It marks the alert threshold: the share of the budget at which you want a warning. The bar fills in your foreground color up to it, takes the warning tone from the tick on and the destructive tone once spend passes the budget. The tick moves as soon as you change the alert, so you can see what an 80% alert means in dollars before you save; the dollar value is written in the line under the bar too.
How does editing a budget work?
"Edit budget" opens the budget and the alert for that row and moves focus to the budget field; the same button becomes "Done". Nothing is sent yet. Done closes the row and keeps your changes, which show as "Budget $1,800 (was $1,500)", and the footer counts the unsaved changes. "Save budgets" applies all of them in one step. Typed values are held between the limits in LIMITS (a budget from $50 up to the hard cap, an alert from 50 to 100%), and an empty or out of range value falls back to the saved one.
What stops the budgets from adding up to more than the hard cap?
The Data List shows the budgets set so far and says "over the cap" when they pass it. Saving then refuses: the footer says by how much the budgets overshoot, and focus moves to the first row you changed, so you can lower it. The cap itself isn't edited here; it belongs on its own account screen, because lifting it changes what you can be billed. The line under the total says what happens when spend reaches it, so write what your product really does.
What does a screen reader hear?
The section is headed by an h2 and each project by an h3, followed by its team and any state badge. The spend is read as "Spent $1,285", the trend as "+18% on the same days last period, to Sep 12", and the line under the bar as the budget and the alert in dollars. The bars repeat what the text says, so they're hidden from assistive technology. The edit button is named for its project ("Edit budget for Edge gateway") and reports aria-expanded, each field is named for its project, and a polite status line in the footer reads out what was set, saved or refused.
How does it look on a phone?
Each row becomes a card: the project and its "Edit budget" button on one line, then the spend and its trend, then the bar and its line. The steppers hide below the sm breakpoint so both fields fit on one line; the number keypad still opens. The footer rides at the bottom of the panel while you scroll, with the status and "Save budgets". Nothing scrolls sideways at 320 px.
Related
- Pro
Usage Meters Billing
Plan and usageUsage meters for an app's settings: one row per quota with its count, a bar that turns to a warning tone at 80% and an over-limit tone past 100%, and a plain line on what happens next.
- Pro
Usage Alerts Billing
Plan and usageUsage alert settings: percentage thresholds as switches with number inputs, recipients as email chips, and a choice between email and a webhook, with a save that checks them.
- Pro
Current Plan Billing
Plan and usageThe account's current plan in app settings: plan, price, renewal date and card, a change-plan action, every quota's usage this period on shared hairlines, and the next invoice.
- Pro
Seat Management Billing
Plan and usageSeats on a team plan: members with a role each (viewers are free), a stepper for the seats you pay for, and the monthly and prorated cost worked out before you save.
- Pro
Usage Profile Pricing
CalculatorsA monthly estimate for Light, Standard and Heavy usage of a speech-to-text API: choosing a profile rolls the total, resizes a tall stacked bar of where the bill comes from and updates each cost line.
- Pro
Cancel Retention Billing
Upsell and retentionA cancel flow in three steps: a reason picker, an offer that matches it (half off for three months, or a pause), and a last page with the exact end date, each step taking focus and every outcome ending on a confirmation.