Staaarter

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.

By Staaarter Team
Billing
Updated July 22, 2026
Docs
Live preview

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.json

Prefer 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

PropTypeDefaultDescription
headingstring"On-demand billing"Panel heading.
descriptionstringnoneOptional line under the heading.
defaultMode"fixed" | "metered""metered"Which billing mode is active on first render.
fixedPriceLabelstring"$99/mo flat rate"Text shown in the fixed-price panel when mode is "fixed".
resourcesResourceUsage[]noneUsage bars rendered in the order given, one per resource.
estimatedTotalstringnoneFormatted running total shown at the bottom of the metered view.
defaultAutoRechargebooleanfalseWhether the auto-recharge switch starts on.
autoRechargeThresholdstringnoneBalance level that triggers a recharge, shown only while auto-recharge is on.
autoRechargeAmountstringnoneAmount added on each auto-recharge, shown only while auto-recharge is on.
classNamestringnoneExtra 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