# Credit card

> A bank-card face at the 1.586 ID-1 ratio with masked number, holder, expiry, network name and a frozen or expired tag.

- Kind: ui · Category: Data display · Interactivity: none
- Install: `npx shadcn@latest add @haze/credit-card`
- File: `src/components/haze/ui/credit-card.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/credit-card

## Use when
- A wallet or billing page lists the cards on file and each needs a recognizable face.
- The card status, frozen or expired, must be visible without opening a menu.
- A saved card is confirmed after checkout with only the last four digits.

## Avoid when
- The customer types a new card number; use payment-card-input.
- A card must turn over to show a back face; use card-flip.
- The content is generic, not a payment card; use card.

## Alternatives
- [payment-card-input](https://hazeui.com/ui/payment-card-input.md)
- [card-flip](https://hazeui.com/ui/card-flip.md)
- [card](https://hazeui.com/ui/card.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| network | `string` | Visa | no | Network name rendered as text. It is never drawn as a logo. |
| last4 | `string` | 4242 | no | Last four digits. The rest of the number is always masked. |
| holder | `string` | Ingrid Solheim | no | Name on the card. |
| expiry | `string` | 08/28 | no | Expiry date as MM/YY. |
| label | `string` | Business card | no | Name the owner gave the card. |
| status | `"active" \| "frozen" \| "expired"` | active | no | Shown as a tag with an icon and text. |
| statusLabel | `string` |  | no | Replaces the default status word, for translation. |
| chip | `boolean` | true | no | Draws the small chip mark. |
| endingLabel | `string` | Card ending in | no | Screen reader words read before the last four digits. |
| expiryLabel | `string` | Expires | no | Word before the expiry date. |
| class | `string` |  | no | Classes for the card, such as a max width. |

## Accessibility
- The masked dots are hidden from screen readers, which hear 'Card ending in 4242' instead.
- Status is a word plus an icon, so frozen and expired never depend on color.
- Both surfaces use the theme's foreground pairs, so text keeps its contrast in light and dark.
- The face is not interactive. Put a button or link beside it for actions such as freezing.

## Agent prompts

### Install and use

Install the Haze UI component "Credit card" with `npx shadcn@latest add @haze/credit-card`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import CreditCard from "@/components/haze/ui/credit-card.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/credit-card.md

### Customize with real content

Adapt the Haze credit-card ui for our product. Replace the demo values of these props with our real content: network, last4, holder, expiry, label, status, statusLabel, chip, endingLabel, expiryLabel, class. Keep the layout, the heading level rules and these accessibility details: The masked dots are hidden from screen readers, which hear 'Card ending in 4242' instead. Status is a word plus an icon, so frozen and expired never depend on color. Both surfaces use the theme's foreground pairs, so text keeps its contrast in light and dark. The face is not interactive. Put a button or link beside it for actions such as freezing. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using credit-card, check it fits: use it when a wallet or billing page lists the cards on file and each needs a recognizable face.; the card status, frozen or expired, must be visible without opening a menu.; a saved card is confirmed after checkout with only the last four digits.. Avoid it when the customer types a new card number; use payment-card-input.; a card must turn over to show a back face; use card-flip.; the content is generic, not a payment card; use card.. Alternatives: @haze/payment-card-input, @haze/card-flip, @haze/card.

## Example requests that should lead here
- Show my saved cards on the billing page, one of them frozen.
- Add a business card to the wallet summary with the last four digits.
- List expired cards with an Expired tag next to a Replace button.

## Source

```astro
---
import { Check, CircleAlert, Snowflake } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

type Status = "active" | "frozen" | "expired";

interface Props {
  /** Card network written as text, such as "Visa". Never drawn as a logo. */
  network?: string;
  /** Last four digits. Only these are ever shown. */
  last4?: string;
  holder?: string;
  /** Expiry as MM/YY. */
  expiry?: string;
  /** Name of the card, such as "Business card". */
  label?: string;
  status?: Status;
  /** Text next to the status icon. Defaults to Active, Frozen or Expired. */
  statusLabel?: string;
  /** Draws the small chip mark. */
  chip?: boolean;
  /** Screen reader prefix for the masked number. */
  endingLabel?: string;
  expiryLabel?: string;
  class?: string;
}

const {
  network = "Visa",
  last4 = "4242",
  holder = "Ingrid Solheim",
  expiry = "08/28",
  label = "Business card",
  status = "active",
  statusLabel,
  chip = true,
  endingLabel = "Card ending in",
  expiryLabel = "Expires",
  class: className,
} = Astro.props;

const frozen = status === "frozen";
const statusText: Record<Status, string> = { active: "Active", frozen: "Frozen", expired: "Expired" };
const StatusIcon = { active: Check, frozen: Snowflake, expired: CircleAlert }[status];
const digits = last4.replace(/\D/g, "").slice(-4);
const muted = "text-muted-foreground";
---

<div
  class={cn(
    "relative flex aspect-[1.586] w-full min-w-0 flex-col justify-between overflow-hidden rounded-xl border p-4",
    "border-frame bg-card text-foreground",
    className,
  )}
>
  <div class="flex items-start justify-between gap-2">
    <p class={cn("min-w-0 text-[0.8125rem]/5 font-medium wrap-anywhere", muted)}>{label}</p>
    <span
      class={cn(
        "inline-flex shrink-0 items-center gap-1 rounded-full px-2 py-0.5 text-xs/4 font-medium",
        "bg-muted text-foreground",
      )}
    >
      <StatusIcon aria-hidden="true" class="size-3" />
      {statusLabel ?? statusText[status]}
    </span>
  </div>

  {
    chip && (
      <svg aria-hidden="true" viewBox="0 0 36 28" fill="none" stroke="currentColor" stroke-width="1.5" class={cn("h-6 w-8 shrink-0", muted, frozen && "opacity-60")}>
        <rect x="1" y="1" width="34" height="26" rx="5" />
        <path d="M1 10h34M1 18h34M13 1v26M23 1v26" />
      </svg>
    )
  }

  <div class={cn(frozen && "text-muted-foreground")}>
    <p class="text-[0.9375rem]/6 font-medium tabular-nums">
      <span aria-hidden="true" class="flex gap-2">
        <span>••••</span><span>••••</span><span>••••</span><span>{digits}</span>
      </span>
      <span class="sr-only">{endingLabel} {digits}</span>
    </p>
    <div class="mt-2 flex items-end justify-between gap-2">
      <div class="min-w-0">
        <p class="truncate text-xs/4 font-medium tracking-wide uppercase">{holder}</p>
        <p class={cn("text-xs/4 tabular-nums", muted)}>{expiryLabel} {expiry}</p>
      </div>
      <p class="shrink-0 text-[0.8125rem]/5 font-semibold tracking-tight">{network}</p>
    </div>
  </div>
</div>
```
