nook
Browse the docs

Components

Payment form

Native

Masked card inputs, a live card preview and payment method selection without processing payments.

See the prompt

Studio plan · annual subscription. This demo checks the form only and does not process a payment.

Payment details
Payment method
Card

▪▪▪▪ ▪▪▪▪ ▪▪▪▪ ▪▪▪▪

Cardholder nameMM/YY
Card brand will appear here
Total due$252.00

Review your details before paying.

Installation

npx nook-ui@latest add payment-form

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Payment form" component to this project, exactly as Nook ships it.

Masked card inputs, a live card preview and payment method selection without processing payments.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add payment-form`. It writes `components/ui/payment-form.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/payment-form.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
"use client";

import * as React from "react";
import { PaymentForm } from "@/components/ui/payment-form";

export default function PaymentDefault() {
  const [submitted, setSubmitted] = React.useState(false);
  return (
    <div className="grid w-full justify-items-center gap-4">
      <p className="max-w-md text-sm text-muted-foreground">
        Studio plan · annual subscription. This demo checks the form only and
        does not process a payment.
      </p>
      <PaymentForm
        total={252}
        onSubmit={() => setSubmitted(true)}
        bankDetails="Pay by bank transfer. Your studio subscription starts after the transfer is confirmed."
        walletDetails="Your wallet will ask you to approve the annual subscription."
      />
      <p role="status" className="text-sm">
        {submitted ? "Details checked. No payment was processed." : ""}
      </p>
    </div>
  );
}
```

API
- `CardNumberInput / CardExpiryInput / CardCvcInput`: Paste-friendly masks with controlled or uncontrolled values. The number field detects the brand and checks Luhn on blur. Formatting preserves the edited digit position.
  - `value / defaultValue / onValueChange` (`string / string / (value: string) => void`): Number and CVC callbacks return digits; expiry returns MM/YY.
  - `error` (`string`): An app-provided error, linked to the field.
  - `...props` (`React.InputHTMLAttributes<HTMLInputElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.
- `CardPreview`: A drawn card showing number, name, expiry and brand. Never shows the security code.
  - `number / name / expiry` (`string`): Current typed values.
  - `masked` (`boolean`, default false): Only reveal the final four digits.
- `PaymentForm`: Card, bank transfer or wallet with validation. Card data is local React state only; no logging, storage, fetching or payment processing.
  - `total / currency` (`number / string`): Amount due in major units and currency code.
  - `onSubmit` (`(values: PaymentValues) => void | Promise<void>`): Receives validated values. Non-card methods receive empty card fields. Rejecting displays a retry message.
  - `value / defaultValue / onValueChange` (`PaymentValues / Partial<PaymentValues> / callback`): Controlled or local method, billing name, card number, expiry and CVC.
  - `loading / preview` (`boolean`, default false / true): External loading state and whether to show the masked preview.
  - `bankDetails / walletDetails` (`ReactNode`): Instructions for the alternative methods.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Fields use cc-number, cc-exp and cc-csc autocomplete and numeric input modes. Labels, brand text and linked plain-language errors are available to assistive technology. Submission focuses the first invalid field; method and field groups are native fieldsets.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

"use client";

import * as React from "react";
import { PaymentForm } from "@/components/ui/payment-form";

export default function PaymentDefault() {
  const [submitted, setSubmitted] = React.useState(false);
  return (
    <div className="grid w-full justify-items-center gap-4">
      <p className="max-w-md text-sm text-muted-foreground">
        Studio plan · annual subscription. This demo checks the form only and
        does not process a payment.
      </p>
      <PaymentForm
        total={252}
        onSubmit={() => setSubmitted(true)}
        bankDetails="Pay by bank transfer. Your studio subscription starts after the transfer is confirmed."
        walletDetails="Your wallet will ask you to approve the annual subscription."
      />
      <p role="status" className="text-sm">
        {submitted ? "Details checked. No payment was processed." : ""}
      </p>
    </div>
  );
}

Examples

While paying

Payment details
Payment method
Card

▪▪▪▪ ▪▪▪▪ ▪▪▪▪ ▪▪▪▪

Cardholder nameMM/YY
Card brand will appear here
Total due$49.00

Review your details before paying.

Small total

Payment details
Payment method
Card

▪▪▪▪ ▪▪▪▪ ▪▪▪▪ ▪▪▪▪

Cardholder nameMM/YY
Card brand will appear here
Total due€9.50

Review your details before paying.

Card declined

Payment details
Payment method
Card

▪▪▪▪ ▪▪▪▪ ▪▪▪▪ ▪▪▪▪

Cardholder nameMM/YY
Card brand will appear here
Total due$129.00

Review your details before paying.

Props

CardNumberInput / CardExpiryInput / CardCvcInput

Paste-friendly masks with controlled or uncontrolled values. The number field detects the brand and checks Luhn on blur. Formatting preserves the edited digit position.

PropTypeDefaultDescription
value / defaultValue / onValueChangestring / string / (value: string) => void–Number and CVC callbacks return digits; expiry returns MM/YY.
errorstring–An app-provided error, linked to the field.
...propsReact.InputHTMLAttributes<HTMLInputElement>–Everything the native element accepts, such as `id`, `aria-*` and event handlers.

CardPreview

A drawn card showing number, name, expiry and brand. Never shows the security code.

PropTypeDefaultDescription
number / name / expirystring–Current typed values.
maskedbooleanfalseOnly reveal the final four digits.

PaymentForm

Card, bank transfer or wallet with validation. Card data is local React state only; no logging, storage, fetching or payment processing.

PropTypeDefaultDescription
total / currencynumber / string–Amount due in major units and currency code.
onSubmit(values: PaymentValues) => void | Promise<void>–Receives validated values. Non-card methods receive empty card fields. Rejecting displays a retry message.
value / defaultValue / onValueChangePaymentValues / Partial<PaymentValues> / callback–Controlled or local method, billing name, card number, expiry and CVC.
loading / previewbooleanfalse / trueExternal loading state and whether to show the masked preview.
bankDetails / walletDetailsReactNode–Instructions for the alternative methods.

Accessibility

Fields use cc-number, cc-exp and cc-csc autocomplete and numeric input modes. Labels, brand text and linked plain-language errors are available to assistive technology. Submission focuses the first invalid field; method and field groups are native fieldsets.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.