Staaarter

Billing Sms Credit Recharge

A billing block for managing communication credits: a live balance with a low-balance warning, a set of selectable top-up amounts with a running cost preview, and an auto-recharge switch that reveals a threshold slider when enabled. Clicking Buy credits simulates a purchase and adds the credits to the displayed balance. Built for communication platforms, marketing tools, and any usage-based product billed by credits instead of a flat subscription.

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

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/billing-sms-credit-recharge.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing124.tsx instead.

Usage

The file also exports billing124Demo, 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 { Billing124, billing124Demo } from "@/components/blocks/billing/billing124";

export default function Page() {
  return <Billing124 {...billing124Demo} />;
}

Props

PropTypeDefaultDescription
headingstring"SMS credits"Heading shown at the top.
descriptionstringnoneOptional note under the heading, for example how credits map to message pricing.
currentCreditsnumbernoneStarting credit balance, held in local state and updated after a purchase.
lowThresholdnumber500Balance at or below which the low-balance warning shows.
pricePerCreditnumbernoneDollar price per credit, used to compute the cost preview.
topUpOptionsnumber[]noneSelectable top-up amounts, rendered as a row of toggle chips.
defaultTopUpIndexnumber0Index into topUpOptions selected on first render.
defaultAutoRechargebooleanfalseWhether the auto-recharge switch starts on.
autoRechargeMinnumber100Minimum value on the auto-recharge threshold slider.
autoRechargeMaxnumber2000Maximum value on the auto-recharge threshold slider.
autoRechargeStepnumber100Step size on the auto-recharge threshold slider.
defaultAutoRechargeThresholdnumber500Starting value of the threshold slider.
purchaseLabelstring"Buy credits"Label on the purchase button, shown with the current cost appended.
classNamestringnoneExtra classes for the outer container.

Behavior notes

  • The credit balance, selected top-up amount, auto-recharge state, threshold, and purchase status are all local component state; nothing here calls a real API.
  • Selecting a different top-up amount recalculates the cost preview immediately as topUpAmount times pricePerCredit.
  • Clicking Buy credits sets a purchasing state for about 800ms, then adds the selected top-up amount to the displayed balance and shows an "Added" confirmation, resetting whenever a different top-up amount is chosen.
  • The auto-recharge switch is a real button with role="switch" and aria-checked, not a native checkbox, matching the rest of the site's toggle pattern since there's no Switch primitive in the UI kit.
  • Toggling auto-recharge on reveals a range-input slider for the recharge threshold; toggling it off hides the slider without losing its value.
  • The low-balance warning is derived from currentCredits versus lowThreshold on every render, not a separate flag you have to set yourself.

Frequently asked questions