Spend Cap Button

Spend Cap Button is a copy-paste React component that stops same item bought twice by mistake before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/spend-cap-button
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 3 extra npm packages
  • A11y guidance in docs

StopsSame item bought twice by mistake

Was this component page useful?

How do I install Spend Cap Button?

pnpm dlx shadcn@latest add @bollard/spend-cap-button

The files land in your project. They're yours to edit.

What input mistakes does Spend Cap Button catch?

  • A repeat purchase of the same item within duplicateWindow, including a double-click
  • Purchases that would break a daily or monthly cap, with the overage and reset time
  • This purchase as a slice of each cap
  • Held Enter (auto-repeat) firing a second purchase

What props does Spend Cap Button accept?

SpendCapButton props
PropTypeDefault
amount* (required)

Price of this purchase.

number—
currency

ISO currency code.

string"INR"
locale

Locale for money and times.

string"en-IN"
itemId* (required)

Identifies what is being bought, for duplicate detection.

string—
purchases

Earlier purchases, in any order. Purchases made through this button are remembered too, so a double-buy is caught before the parent refreshes.

SpendPurchase[][]
duplicateWindow

A purchase of the same item within this many ms counts as a likely duplicate.

number3_600_000
caps

Spending caps; a purchase that breaks any of them is blocked.

SpendCap[][]
onPurchase* (required)

Charges. Return a promise to show a pending state; a rejection re-enables the button.

() => void | Promise<void>—
onViewOrder

Shown as "View order" on the duplicate warning.

(orderId: string) => void—
label

Templates: `{amount}`, `{when}`, `{cap}`, `{over}`, `{reset}`, `{left}` and `{after}` are filled in.

string"Pay {amount}"
duplicateText

Shown when the item was bought recently. `{ago}` is filled in.

string"You bought this {when}."
againLabel

Button label asking for the second click.

string"Buy again · {amount}"
blockedText

Shown when a cap would be broken.

string"Blocked: {over} over your {cap}. Resets in {reset}."
capText

Accessible label of a cap meter.

string"{left} left → {after} after"
capOverText

Cap line when this purchase doesn't fit.

string"{left} left · {over} short"
viewOrderLabel

Label of the view-order link.

string"View order"
pendingLabel

Button label while onPurchase runs.

string"Paying…"
doneLabel

Button label after a purchase.

string"Paid"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is Spend Cap Button accessible?

  • aria-disabled when a cap would break, aria-busy while pending, described by a polite hint
  • Escape disarms the second-click state; held Enter is ignored
  • Blocked reason uses role=alert
  • Each cap is a role=meter with value text; animations respect reduced motion

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Enforce spending caps and dedupe purchases (idempotency key, recent-purchase check) on the server.

  • Caps and recent purchases come from props; another tab or device isn't seen until you update them
  • The block is UI-only; the purchase API must enforce caps

What expensive mistakes does Spend Cap Button stop?

Same item bought twice by mistake

Also known as

buy now · spending limit · budget · in-app purchase · credits · top-up · wallet · duplicate purchase

Field type

What dependencies does Spend Cap Button require?

Spend Cap Button facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameSpend Cap Button
Registry identifier@bollard/spend-cap-button
Install commandnpx shadcn@latest add @bollard/spend-cap-button
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencies@number-flow/react, lucide-react, motion
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Spend Cap Button

How does Spend Cap Button prevent financial transaction errors?

Spend Cap Button prevents same item bought twice by mistake. Blocks A repeat purchase of the same item within duplicateWindow, including a double-click, Purchases that would break a daily or monthly cap, with the overage and reset time, This purchase as a slice of each cap, Held Enter (auto-repeat) firing a second purchase before processing. Limitation: apply idempotency keys for spend-cap-button.

How do I install spend-cap-button with shadcn?

Run `npx shadcn@latest add @bollard/spend-cap-button`. Sources added: registry/default/spend-cap-button/spend-cap-button.tsx. Package requirements: @number-flow/react, lucide-react, motion.

What props customize Spend Cap Button?

Spend Cap Button accepts `amount`, `currency`, `locale`, `itemId`, `purchases`. Configures buy now, spending limit, budget behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of spend-cap-button?

Caps and recent purchases come from props; another tab or device isn't seen until you update them. The block is UI-only; the purchase API must enforce caps Server requirement: Enforce spending caps and dedupe purchases (idempotency key, recent-purchase check) on the server.

How does Spend Cap Button meet accessibility guidelines?

aria-disabled when a cap would break, aria-busy while pending, described by a polite hint. Escape disarms the second-click state; held Enter is ignored. Blocked reason uses role=alert. Each cap is a role=meter with value text; animations respect reduced motion. Minimizes errors: bought same thing twice, double purchase.

Which components pair with Spend Cap Button?