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.
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.jsonPrefer 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
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "SMS credits" | Heading shown at the top. |
| description | string | none | Optional note under the heading, for example how credits map to message pricing. |
| currentCredits | number | none | Starting credit balance, held in local state and updated after a purchase. |
| lowThreshold | number | 500 | Balance at or below which the low-balance warning shows. |
| pricePerCredit | number | none | Dollar price per credit, used to compute the cost preview. |
| topUpOptions | number[] | none | Selectable top-up amounts, rendered as a row of toggle chips. |
| defaultTopUpIndex | number | 0 | Index into topUpOptions selected on first render. |
| defaultAutoRecharge | boolean | false | Whether the auto-recharge switch starts on. |
| autoRechargeMin | number | 100 | Minimum value on the auto-recharge threshold slider. |
| autoRechargeMax | number | 2000 | Maximum value on the auto-recharge threshold slider. |
| autoRechargeStep | number | 100 | Step size on the auto-recharge threshold slider. |
| defaultAutoRechargeThreshold | number | 500 | Starting value of the threshold slider. |
| purchaseLabel | string | "Buy credits" | Label on the purchase button, shown with the current cost appended. |
| className | string | none | Extra 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
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.