Credit Card

Web/Mobile

A labeled card-number field with four digit groups, separators, description, and error. Values always display as Persian digits.

لطفاً شماره کارت را در چهار گروه چهاررقمی وارد کنید.

Installation

pnpm dlx cubix-ui@latest add credit-card --base aria

Usage

Import
import {
  CreditCard,
  CreditCardControl,
  CreditCardDescription,
  CreditCardGroup1,
  CreditCardGroup2,
  CreditCardGroup3,
  CreditCardGroup4,
  CreditCardLabel,
  CreditCardSeparator,
} from "@/components/cubix/credit-card"
Example
<CreditCard className="w-full max-w-sm">
  <CreditCardLabel>شماره کارت</CreditCardLabel>
  <CreditCardControl>
    <CreditCardGroup1 />
    <CreditCardSeparator />
    <CreditCardGroup2 />
    <CreditCardSeparator />
    <CreditCardGroup3 />
    <CreditCardSeparator />
    <CreditCardGroup4 />
  </CreditCardControl>
  <CreditCardDescription>
    لطفاً شماره کارت را در چهار گروه چهاررقمی وارد کنید.
  </CreditCardDescription>
</CreditCard>

Composition

Compose label, control, help text, and error under CreditCard. Inside the control, four groups of four digits sit between CreditCardSeparator parts. Digits always display in Persian. Filling a group moves focus to the next; Backspace on an empty group moves back. Paste a full number to fill all groups.

Structure
CreditCard
├── CreditCardLabel
├── CreditCardControl
│   ├── CreditCardGroup1
│   ├── CreditCardSeparator
│   ├── CreditCardGroup2
│   ├── CreditCardSeparator
│   ├── CreditCardGroup3
│   ├── CreditCardSeparator
│   └── CreditCardGroup4
├── CreditCardDescription
└── CreditCardError

Accessibility

Each group has its own accessible name. Auto-advance and Backspace keep keyboard entry on one path. CreditCardDescription and CreditCardError are announced through aria-describedby, and invalid sets aria-invalid on every group. Set name on the root to submit a single hidden value for the full card number.

Examples

Description

Add helper text below the control for format hints or guidance.

لطفاً شماره کارت را در چهار گروه چهاررقمی وارد کنید.

Filled

Pass defaultValue on each group to show a complete card number.

لطفاً شماره کارت را در چهار گروه چهاررقمی وارد کنید.

Invalid

Set invalid on the root to apply destructive styles and show CreditCardError.

Disabled

Disable the field to block every group. The control uses a muted fill; label and description stay readable.

این فیلد فعلاً قابل ویرایش نیست.

Sizes

Two heights ship by default: default (40px) and lg (48px). Use className for any other size.

ارتفاع ۴۰ پیکسل

ارتفاع ۴۸ پیکسل

In a form

Set name on the root so the combined number is submitted with the form, and pair the field with Cubix Button.

پرداخت

برای ادامه، شماره کارت خود را وارد کنید.

لطفاً شماره کارت را در چهار گروه چهاررقمی وارد کنید.

Custom styling

Every part accepts a className merged with the shipped cn helper. Here each group uses a filled surface instead of the default outline.

با className می‌توانید ظاهر را سفارشی کنید.

API Reference

Note: Parts render data-slot attributes (credit-card, credit-card-label, credit-card-control, credit-card-group-1, credit-card-group-2, credit-card-group-3, credit-card-group-4, credit-card-separator, credit-card-description, credit-card-error) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

CreditCard

PropTypeDefaultDescription
size"default" | "lg""default"Height for the control: default 40px, lg 48px. Inherited by CreditCardControl unless overridden. Use className for other heights.
disabledbooleanfalseDisables the field and prevents interaction. Forwarded to the segments on every base.
invalidbooleanfalseMarks the field as invalid and shows CreditCardError when present.
namestring-Writes a hidden input with the combined four-group value (Persian digits, hyphen-separated) for form submit.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

CreditCardControl

PropTypeDefaultDescription
size"default" | "lg"-Overrides the size from CreditCard. Height matches the default and lg sizes.
childrenReact.ReactNode-Compose CreditCardGroup1-4 with CreditCardSeparator between them. The control is a layout row only (dir=ltr) - each group has its own input box.
classNamestring-Additional Tailwind classes merged with the control styles (last one wins).

CreditCardGroup1 / 2 / 3 / 4

PropTypeDefaultDescription
part"group1" | "group2" | "group3" | "group4"-Fixed by CreditCardGroup1-4. Each group accepts 4 digits and always displays Persian digits.
placeholderstring-Hint text shown when the segment is empty. Empty by default.
inputMode"numeric""numeric"Locked to numeric so mobile keyboards show a number pad.
classNamestring-Additional Tailwind classes merged with the segment styles (last one wins).
...propsOmit<React.ComponentProps<'input'>, 'type' | 'inputMode' | 'spellCheck' | 'maxLength'>-Native input attributes (value, onChange, defaultValue, ...) are forwarded. type, inputMode, spellCheck, and maxLength stay locked. Use parseCreditCardValue / formatCreditCardValue for the combined string.

CreditCardSeparator

PropTypeDefaultDescription
childrenReact.ReactNode"-"Separator between card number groups. Defaults to -.
classNamestring-Additional Tailwind classes merged with the separator styles (last one wins).

CreditCardLabel / Description / Error

PropTypeDefaultDescription
childrenReact.ReactNode-For CreditCardDescription: shown as helper text until six digits match a known Iranian bank BIN, then replaced by the bank name (for example بانک ملت).
classNamestring-Additional Tailwind classes merged with the part styles (last one wins).
...propsHTML attributes-Native attributes for the rendered element are forwarded.