Billing Auto Recharge
A settings panel for prepaid, credit-based billing where a customer wants their balance topped up automatically instead of running out mid-cycle. A toggle switch turns auto-recharge on or off, a range slider sets the balance threshold that triggers a recharge, and a Recharge now button simulates an on-demand top-up with a loading spinner followed by a brief confirmation state. Built for AI credit systems and other pay-as-you-go wallets.
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-auto-recharge.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing23.tsx instead.
Usage
The file also exports billing23Demo, 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 { Billing23, billing23Demo } from "@/components/blocks/billing/billing23"; export default function Page() { return <Billing23 {...billing23Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Auto-recharge" | Panel heading. |
| description | string | none | Supporting line under the heading. |
| balance | number | none | Current balance in dollars, shown as a read-only figure. |
| defaultEnabled | boolean | true | Whether auto-recharge starts on when the panel first renders. |
| defaultThreshold | number | 20 | Starting value of the threshold slider, in dollars. |
| minThreshold | number | 5 | Slider minimum. |
| maxThreshold | number | 100 | Slider maximum. |
| step | number | 5 | Slider step size. |
| rechargeAmount | string | "$50" | Amount added on each recharge, shown as-is in the helper text and on the button after a successful recharge. |
| className | string | none | Extra classes for the outer container. |
Behavior notes
- The enable toggle, threshold value, and recharge status are all local component state; there are no onChange or onToggle callback props, so lift the state up or read it via a ref if a parent needs to react to changes.
- The threshold slider and its helper text only render while auto-recharge is enabled; turning the toggle off hides that whole section but keeps the chosen threshold in state.
- Recharge now is a demo-only interaction: clicking it sets a loading state for 900ms, then shows a 'rechargeAmount added' confirmation for 2 seconds before resetting to idle. It doesn't call any API, wire an onClick handler of your own via a wrapper if you need a real request.
- If balance is already at or below the current threshold, a small warning line appears under the slider so the mismatch is visible before saving.
- The toggle is a real button with role="switch" and aria-checked, and the slider is a native range input, so both work with keyboard and screen readers without any extra wiring.
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.