Staaarter

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.

By Staaarter Team
Billing
Updated May 5, 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-auto-recharge.json

Prefer 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

PropTypeDefaultDescription
headingstring"Auto-recharge"Panel heading.
descriptionstringnoneSupporting line under the heading.
balancenumbernoneCurrent balance in dollars, shown as a read-only figure.
defaultEnabledbooleantrueWhether auto-recharge starts on when the panel first renders.
defaultThresholdnumber20Starting value of the threshold slider, in dollars.
minThresholdnumber5Slider minimum.
maxThresholdnumber100Slider maximum.
stepnumber5Slider step size.
rechargeAmountstring"$50"Amount added on each recharge, shown as-is in the helper text and on the button after a successful recharge.
classNamestringnoneExtra 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