Billing On Demand Billing
A configuration panel for pay-as-you-go resource billing. A segmented toggle switches the account between a fixed monthly rate and metered pricing, each resource shows a usage bar against its included limit plus the running cost when metered, and an auto-recharge switch controls whether the balance tops up automatically. Built for infrastructure and developer-tool billing pages where usage-based cost needs to stay visible and adjustable in one place.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/billing-on-demand-billing.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing80.tsx instead.
Usage
The file also exports billing80Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.
import { Billing80, billing80Demo } from "@/components/blocks/billing/billing80"; export default function Page() { return <Billing80 {...billing80Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "On-demand billing" | Panel heading. |
| description | string | none | Optional line under the heading. |
| defaultMode | "fixed" | "metered" | "metered" | Which billing mode is active on first render. |
| fixedPriceLabel | string | "$99/mo flat rate" | Text shown in the fixed-price panel when mode is "fixed". |
| resources | ResourceUsage[] | none | Usage bars rendered in the order given, one per resource. |
| estimatedTotal | string | none | Formatted running total shown at the bottom of the metered view. |
| defaultAutoRecharge | boolean | false | Whether the auto-recharge switch starts on. |
| autoRechargeThreshold | string | none | Balance level that triggers a recharge, shown only while auto-recharge is on. |
| autoRechargeAmount | string | none | Amount added on each auto-recharge, shown only while auto-recharge is on. |
| className | string | none | Extra classes for the outer container. |
Types
interface ResourceUsage { id: string; label: string; unit: string; used: number; includedLimit: number; unitPrice: string; currentCost: string; }
Behavior notes
- Billing mode and the auto-recharge switch are both local state, seeded from defaultMode and defaultAutoRecharge; toggling either only changes what's shown, it doesn't call any billing API.
- Switching to "fixed" keeps the usage bars visible but hides per-resource cost and the estimated total, since a flat rate makes them informational rather than what's actually billed.
- Each resource's bar fill is used divided by includedLimit, clamped to 100%, and turns amber once used exceeds includedLimit; the component doesn't compute currentCost itself, that string comes from your data.
- The auto-recharge switch is a real toggle button with role="switch" and aria-checked, and its helper text changes between the threshold/amount summary and an "off" explanation based on the current state.
Frequently asked questions
More Billing Blocks
View all →Billing Invoice List
Invoice history table with status badges, formatted amounts, and a per-row download link, built with shadcn/ui and Tailwind CSS.
Billing Failed Payment Alert
High-contrast failed-payment alert with a message, a retry button, and an optional update-payment-method button, built with shadcn/ui and Tailwind CSS.
Billing Credit Balance
Compact credit balance card with a large total, an optional purchased-versus-promotional breakdown, a low-balance notice, and a top-up button.
Billing Payment Methods
A saved payment method list for React and Next.js with brand icons, a default badge, near-expiry warnings, and remove/set-default actions per row.
Billing Add Card
A card entry form for React and Next.js with auto-formatted fields, internal brand detection, and per-field validation feedback built with shadcn/ui and Tailwind CSS.
Billing Coupon Code
An inline promo code input for React and Next.js with a simulated loading state, an applied summary showing the discount amount, and an invalid-code message.