Billing Custom Amount
A custom amount entry block for letting people define their own spend instead of picking a fixed tier. Typing into the input updates an inline error the moment the amount falls outside the allowed range, and a preset row lets people jump straight to common values. Built with shadcn/ui Input and Button components, Lucide icons, and Tailwind CSS.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its input, label, button dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/billing-custom-amount.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing43.tsx instead.
Usage
The file also exports billing43Demo, 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 { Billing43, billing43Demo } from "@/components/blocks/billing/billing43"; export default function Page() { return <Billing43 {...billing43Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Add funds" | Block heading. |
| description | string | "Enter any amount to top up your balance." | Supporting text under the heading. |
| presets | number[] | [25, 50, 100, 250] | Quick-select amounts rendered as pill buttons below the input. |
| min | number | 5 | Smallest amount the input accepts before showing an error. |
| max | number | 5000 | Largest amount the input accepts before showing an error. |
| currencySymbol | string | "$" | Symbol shown as the input prefix and in preset labels. |
| defaultAmount | number | 50 | Amount the input is seeded with on first render. |
| creditsPerDollar | number | none | When set, shows a converted credit total under the input, amount multiplied by this rate. |
| ctaLabel | string | "Add funds" | Label on the submit button, the current amount is appended to it once valid. |
| className | string | none | Extra classes for the outer container. |
Behavior notes
- The typed value is a controlled string, not a number, filtered on every keystroke by a regex that allows digits and up to two decimal places so the field never holds invalid characters.
- Validation runs on every render: an empty field, a value below min, or a value above max each show a distinct inline error and disable the submit button.
- Clicking a preset button replaces the current input value outright rather than adding to it, and the active preset gets a highlighted border when its value matches the typed amount exactly.
- The credit total only appears when creditsPerDollar is passed and the current amount is valid, it's computed inline on every render rather than stored in state.
- The submit button's label appends the formatted amount only while the amount is valid, so the button always describes what clicking it will actually charge.
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.