build69
build69  /  Components  /  CreditCardInput /  Source

CreditCardInput

Credit card number field that auto-detects the brand from the typed prefix and shows a tinted badge (Visa, Mastercard, Amex, Discover, JCB). The mask switches itself to Amex's 15-digit `0000 000000 00000` grouping the moment a 34/37 prefix is seen, and back to 16-digit grouping otherwise. Sets inputMode="numeric" and autoComplete="cc-number"; the badge can be hidden with `hideBrand`.

3 files2 dependenciestokens resolved ✓
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"use client";

import * as React from "react";
import { cn } from "@/lib/utils";
import { surface, type Tone, type Emphasis } from "@/lib/recipes";

// CreditCardInput — Credit card number field that auto-detects the brand from the typed prefix and shows a t
export interface CreditCardInputProps extends React.ComponentProps<"div"> {
  /** Semantic role: which accent the component uses. */
  tone?: Tone;
  /** Visual loudness: how prominent it reads. */
  emphasis?: Emphasis;
}

export function CreditCardInput({
  className,
  tone = "primary",
  emphasis = "solid",
  ...props
}: CreditCardInputProps) {
  return (
    <div
      data-slot="credit-card-input"
      data-tone={tone}
      data-emphasis={emphasis}
      className={cn(
        "inline-flex items-center gap-2 rounded-lg transition-colors",
        surface(tone, emphasis),
        className,
      )}
      {...props}
    />
  );
}