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 (
Studio plan ยท annual subscription. This demo checks the form only and
does not process a payment.
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."
/>
{submitted ? "Details checked. No payment was processed." : ""}
);
}
```
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`): 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`): Receives validated values. Non-card methods receive empty card fields. Rejecting displays a retry message.
- `value / defaultValue / onValueChange` (`PaymentValues / Partial / 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.