Billing Add Card
A card entry form for adding a new payment method. Formats the card number and expiry as the user types, detects the card brand from the digits typed so far, and validates every field on submit with an inline error under each one. On a valid submit it shows a success message and resets the form. Built with TypeScript, 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 button, input, label, alert dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/billing-add-card.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing5.tsx instead.
Usage
The file also exports billing5Demo, 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 { Billing5, billing5Demo } from "@/components/blocks/billing/billing5"; export default function Page() { return <Billing5 {...billing5Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Add a payment method" | Form heading. |
| description | string | none | Supporting description under the heading. |
| submitLabel | string | "Save card" | Label for the submit button. |
| className | string | none | Extra classes for the outer section element. |
Behavior notes
- Card number and expiry fields are formatted as the user types, digits only, grouped in fours for the number and split into MM/YY for expiry, and the CVV field strips non-digits and caps at 4 characters.
- The card brand shown inside the number field is detected from the digits typed so far using an internal Visa/Mastercard/Amex/Discover prefix check, it is never passed in as a prop.
- Validation runs on submit, not on every keystroke. Card number, expiry, CVV, and name are each checked, and any failing field gets a destructive-colored message directly beneath it plus aria-invalid on the input.
- A successful submit clears every field back to empty and shows a dismissible-looking success alert above the form confirming the card was added, no network request is made since this is a static demo.
- There is no server call in this block, form state lives entirely in useState and the component intentionally never stores or transmits the raw values it collects.
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 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.
Billing Subscription Summary
A subscription summary card with plan name, price, renewal date, and per-metric usage bars, plus manage and upgrade actions.