1280px
Install
One command installs the files and packages this item needs.
TerminalTerminalTerminalbash
npx shadcn@latest add https://dsui.vercel.app/r/payment-card.jsonFiles
components/arc/payment-card/payment-card.module.csscomponents/arc/payment-card/payment-card.tsx
npm packages
motion@^14.2.0
Registry items it pulls in
- v1.0.0First release.
payment-card.module.csspayment-card.module.csspayment-card.module.csscss
/* The ISO card ratio (85.6 x 53.98mm). The face is the accent, so its shadow is the accent's too. */
.card { --card-ink: var(--accent-foreground); --card-soft: var(--accent-foreground-muted); position: relative; display: flex; box-sizing: border-box; width: min(100%, 22rem); aspect-ratio: 1.586; flex-direction: column; justify-content: space-between; overflow: hidden; border: 1px solid var(--accent); border-radius: var(--radius-panel); padding: var(--space-5); background: var(--accent); color: var(--card-ink); box-shadow: var(--shadow-accent-raised); letter-spacing: var(--tracking-body); user-select: none; -webkit-user-select: none; will-change: transform; transition: box-shadow var(--duration-standard) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) { .card:hover { box-shadow: var(--shadow-accent-floating); } }
.top, .bottom { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.bottom { align-items: flex-end; }
.brand { display: inline-flex; min-width: 0; align-items: baseline; gap: var(--space-2); font-size: var(--text-lg); font-weight: var(--label-weight); }
.tier { color: var(--card-soft); font-size: var(--text-xs); font-weight: 500; }
/* The contact chip: a rounded tile with one seam. */
.chip { position: relative; flex: none; width: 2.5rem; height: 1.875rem; border-radius: .5rem; background: color-mix(in oklab, var(--card-ink) 28%, transparent); }
.chip::after { content: ""; position: absolute; inset: 0 50% 0 auto; width: 1px; background: color-mix(in oklab, var(--card-ink) 36%, transparent); }
.number { font-size: clamp(1rem, 5.4cqi, 1.375rem); font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: .08em; white-space: nowrap; }
.card { container-type: inline-size; }
.entry { display: grid; min-width: 0; gap: 2px; }
.caption { color: var(--card-soft); font-size: var(--text-xs); }
.value { overflow: hidden; font-size: var(--text-sm); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.network { display: flex; flex: none; margin-left: auto; }
.network span { width: 1.75rem; height: 1.75rem; border-radius: var(--radius-pill); background: color-mix(in oklab, var(--card-ink) 82%, transparent); }
.network span + span { margin-left: -.75rem; background: color-mix(in oklab, var(--card-ink) 42%, transparent); }
/* Liquid glass: the layer paints the slab; the ink is the page's so it reads on any backdrop. */
.glass { --card-ink: var(--foreground); --card-soft: color-mix(in oklab, var(--foreground) 66%, transparent); }
.glass.glass:hover { box-shadow: none; }
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }
payment-card.tsxpayment-card.tsxpayment-card.tsxtsx
"use client";
import { useRef } from "react";
import type { HTMLAttributes, PointerEvent } from "react";
import { motion, useMotionTemplate, useMotionValue, useMotionValueEvent, useSpring } from "motion/react";
import { useReducedMotion } from "../lib/use-reduced-motion";
import { motionTokens } from "../lib/motion-tokens";
import { LiquidGlassLayer, liquidGlassHost, type LiquidGlassTilt } from "../liquid-glass/liquid-glass-layer";
import styles from "./payment-card.module.css";
export interface PaymentCardProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart"> {
/** The issuer or product name in the top corner. */
brand: string;
/** The grade or plan next to the brand, such as "Platinum". */
tier?: string;
/** The number as it should be shown. Mask it yourself (`•••• •••• •••• 8042`) when the full number must not appear. */
number: string;
holder: string;
/** Expiry as shown on the card, such as "08 / 29". */
validThru: string;
/** Leans toward the pointer. Off for touch and for visitors who asked for less motion. */
tilt?: boolean;
/** The steepest lean in degrees. */
maxTilt?: number;
/** `liquid-glass` draws the card as a thick slab of glass. Put it over a photo, a gradient or a busy page. */
variant?: "default" | "liquid-glass";
}
/** A payment or membership card preview in the ISO card ratio. It is a picture of a card, not a form. */
export function PaymentCard({ brand, tier, number, holder, validThru, tilt = true, maxTilt = 12, variant = "default", className, style, onPointerMove, onPointerLeave, ...props }: PaymentCardProps) {
const reduced = useReducedMotion() ?? false;
const glass = variant === "liquid-glass";
const leaning = useRef<LiquidGlassTilt | null>(null);
const targetX = useMotionValue(0), targetY = useMotionValue(0), targetScale = useMotionValue(1);
const rotateX = useSpring(targetX, motionTokens.spring.smooth), rotateY = useSpring(targetY, motionTokens.spring.smooth), scale = useSpring(targetScale, motionTokens.spring.smooth);
const transform = useMotionTemplate`perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(${scale})`;
// The glass leans with the card: the layer reads this every frame.
const report = () => { leaning.current = { rotX: rotateX.get(), rotY: rotateY.get(), scale: scale.get() }; };
useMotionValueEvent(rotateX, "change", report);
useMotionValueEvent(rotateY, "change", report);
useMotionValueEvent(scale, "change", report);
const active = tilt && !reduced;
const move = (event: PointerEvent<HTMLDivElement>) => {
onPointerMove?.(event);
if (!active || event.pointerType !== "mouse") return;
const box = event.currentTarget.getBoundingClientRect();
const x = (event.clientX - box.left) / box.width - .5, y = (event.clientY - box.top) / box.height - .5;
targetX.set(-y * 2 * maxTilt);
targetY.set(x * 2 * maxTilt);
targetScale.set(1.03);
};
const leave = (event: PointerEvent<HTMLDivElement>) => { onPointerLeave?.(event); targetX.set(0); targetY.set(0); targetScale.set(1); };
return (
<motion.div
{...props}
role="img"
aria-label={props["aria-label"] ?? `${brand} 카드, ${holder}, 번호 끝자리 ${number.replace(/\D/g, "").slice(-4)}`}
className={[styles.card, glass ? `${liquidGlassHost} ${styles.glass}` : undefined, className].filter(Boolean).join(" ")}
style={{ ...style, transform: active ? transform : undefined }}
onPointerMove={move}
onPointerLeave={leave}
>
{glass ? <LiquidGlassLayer preset="card" tilt={leaning} /> : null}
<div className={styles.top}>
<span className={styles.brand}>{brand}{tier ? <span className={styles.tier}>{tier}</span> : null}</span>
<span className={styles.chip} aria-hidden="true" />
</div>
<span className={styles.number}>{number}</span>
<div className={styles.bottom}>
<span className={styles.entry}><span className={styles.caption}>이름</span><span className={styles.value}>{holder}</span></span>
<span className={styles.entry}><span className={styles.caption}>유효 기간</span><span className={styles.value}>{validThru}</span></span>
<span className={styles.network} aria-hidden="true"><span /><span /></span>
</div>
</motion.div>
);
}
export default PaymentCard;
Used items
- Liquid glassComponent
A glass surface with refraction, dispersion and flowing caustics. Wrap your own content or fill a word with glass.