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.
pnpm dlx shadcn@latest add @haze/credit-card---
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>When to use
- 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.
When not to use
- 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.
Installation
Add the Haze registry to components.json once, then install Credit card with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/credit-cardnpx shadcn@latest add @haze/credit-cardyarn dlx shadcn@latest add @haze/credit-cardbunx --bun shadcn@latest add @haze/credit-cardFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| network | string | Visa | Network name rendered as text. It is never drawn as a logo. |
| last4 | string | 4242 | Last four digits. The rest of the number is always masked. |
| holder | string | Ingrid Solheim | Name on the card. |
| expiry | string | 08/28 | Expiry date as MM/YY. |
| label | string | Business card | Name the owner gave the card. |
| status | "active" | "frozen" | "expired" | active | Shown as a tag with an icon and text. |
| statusLabel | string | – | Replaces the default status word, for translation. |
| chip | boolean | true | Draws the small chip mark. |
| endingLabel | string | Card ending in | Screen reader words read before the last four digits. |
| expiryLabel | string | Expires | Word before the expiry date. |
| class | string | – | 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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.