Skip to content

PaymentMethodCard

The physical card object. 3D flip, pointer tilt.
Implemented
Status
Implemented
Family
2 of 13
Registry
@lopifi/payment-method-card
npx shadcn@latest add @lopifi/theme @lopifi/payment-method-card

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

The physical object. Two of the four sanctioned delight moments — the flip and the tilt.

Geometry, from ISO/IEC 7810 ID-1:

aspect-ratio: 1.586          (85.60 × 53.98 mm)
border-radius: 3.7% / 5.9%     (3.18mm — 3.7% of width, 5.9% of height)

Real proportions matter — a card at 16:9 with a 24px radius reads as a rectangle, not as a card.

Face: flat, single tint from the issuer color, network mark bottom-right, masked PAN in tnum with ss02 (so a 0 isn't an O), holder name in label uppercase, expiry MM/YY.

Motion:

  • Flip to reveal CVV — rotateY(0→180deg), spring.playful, real 3D with preserve-3d + backface-visibility: hidden. Not a crossfade. Spec.
  • Pointer tilt — ±6° from pointer position via spring.track, plus a specular sheen at opacity 0→0.12. Desktop only, gated behind @media (hover: hover) and (pointer: fine). Springs home on leave.
  • Reduced motion: instant swap, no tilt.

The tilt is decorative and it's licensed only because the card is decorative. The same effect on a KpiCard is a review failure.

Security: CVV and full PAN are never in the DOM until revealed, never in analytics, never in a screenshot-able state without an explicit user action.

Lifted verbatim from Cards. The doc and this page are the same paragraphs, so they cannot disagree.

What lands in your repository

One component is never one file. Everything below is copied into your project, where you own it.

Files

components/ledger/payment-method-card.tsx

Lopifi dependencies · 2
cnuse-media-query
npm packages
clsxtailwind-merge
Registry entry
/r/payment-method-card.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/payment-method-card.tsx
"use client";

import * as React from "react";
import { useFinePointer, useReducedMotion } from "@/hooks/ledger/use-media-query";
import { cn } from "@/lib/ledger/cn";

export interface PaymentMethodCardProps extends Omit<React.ComponentPropsWithoutRef<"div">, "onChange"> {
  cvv?: string;
  expiry: string;
  holder: string;
  last4: string;
  network: "visa" | "mastercard" | "amex";
  tint?: string;
}

/**
 * The physical object, at ISO/IEC 7810 ID-1 proportions.
 *
 * 85.60 × 53.98 mm → aspect-ratio 1.586, radius 3.18mm → 3.7% of width, 5.9% of height.
 * A card at 16:9 with a 24px radius reads as a rectangle, not as a card.
 *
 * The pointer tilt is decorative and is licensed only because the card
 * itself is decorative. The same effect on a KpiCard is a review failure.
 */
export const PaymentMethodCard = React.forwardRef<HTMLDivElement, PaymentMethodCardProps>(
  ({ className, holder, last4, expiry, network, cvv, tint = "oklch(0.34 0.06 258)", ...props }, ref) => {
    const [flipped, setFlipped] = React.useState(false);
    const [tilt, setTilt] = React.useState({ sheen: 0, x: 0, y: 0 });
    /* Two motions share one transform. The tilt follows the pointer, so it has
       to land almost at once or the card lags behind the hand; the flip is a
       turn the reader asked for and wants to watch. Each gets its own curve. */
    const [turning, setTurning] = React.useState(false);
    const fine = useFinePointer();
    const reduced = useReducedMotion();

    const onMove = (e: React.PointerEvent<HTMLDivElement>) => {
      if (!fine || reduced) return;
      const rect = e.currentTarget.getBoundingClientRect();
      const px = (e.clientX - rect.left) / rect.width - 0.5;
      const py = (e.clientY - rect.top) / rect.height - 0.5;
      setTilt({ sheen: 0.12, x: -py * 8, y: px * 8 });
    };

    const onLeave = () => setTilt({ sheen: 0, x: 0, y: 0 });

    return (
      <div className={cn("w-full max-w-[360px] [perspective:1200px]", className)} ref={ref} {...props}>
        <div
          className="relative w-full [transform-style:preserve-3d]"
          onPointerLeave={onLeave}
          onPointerMove={onMove}
          onTransitionEnd={(e) => {
            if (e.target === e.currentTarget) setTurning(false);
          }}
          style={{
            aspectRatio: "1.586",
            transform: `rotateX(${tilt.x}deg) rotateY(${tilt.y + (flipped ? 180 : 0)}deg)`,
            transition: reduced
              ? "none"
              : turning
                ? "transform 480ms var(--ease-in-out)"
                : "transform var(--duration-3) var(--ease-out)",
          }}
        >
          {/* Face */}
          <div
            className="absolute inset-0 flex flex-col justify-between overflow-hidden p-5 [backface-visibility:hidden]"
            style={{
              background: tint,
              borderRadius: "3.7% / 5.9%",
              color: "oklch(0.98 0.005 258)",
            }}
          >
            <div
              aria-hidden="true"
              className="pointer-events-none absolute inset-0 transition-opacity duration-2 ease-out"
              style={{
                background:
                  "linear-gradient(115deg, transparent 30%, oklch(1 0 0 / 0.5) 50%, transparent 70%)",
                opacity: tilt.sheen,
              }}
            />
            <div className="flex items-start justify-between">
              <div aria-hidden="true" className="h-7 w-9 rounded-[3px] bg-[oklch(0.82_0.08_85)]" />
              <NetworkMark network={network} />
            </div>
            <div>
              <p className="reference-numeric text-title-md">
                <span aria-hidden="true">•••• •••• •••• {last4}</span>
                <span className="sr-only">card ending {last4}</span>
              </p>
              <div className="mt-3 flex items-end justify-between">
                <p className="text-label uppercase tracking-[0.06em]">{holder}</p>
                <p className="reference-numeric text-label">{expiry}</p>
              </div>
            </div>
          </div>

          {/* Reverse — the CVV is not in the DOM until revealed. */}
          <div
            className="absolute inset-0 flex flex-col justify-center gap-4 overflow-hidden py-5 [backface-visibility:hidden] [transform:rotateY(180deg)]"
            style={{ background: tint, borderRadius: "3.7% / 5.9%", color: "oklch(0.98 0.005 258)" }}
          >
            <div aria-hidden="true" className="h-10 w-full bg-[oklch(0.2_0.01_258)]" />
            <div className="flex items-center justify-end gap-3 px-5">
              <span className="text-caption opacity-80">CVV</span>
              <span className="reference-numeric rounded-xs bg-[oklch(1_0_0/0.9)] px-3 py-1 text-label text-[oklch(0.2_0.01_258)]">
                {flipped && cvv ? cvv : "•••"}
              </span>
            </div>
          </div>
        </div>

        <button
          aria-pressed={flipped}
          className="mt-3 text-label font-medium text-accent hover:underline"
          onClick={() => {
            setTurning(!reduced);
            setFlipped((f) => !f);
          }}
          type="button"
        >
          {flipped ? "Hide security code" : "Show security code"}
        </button>
      </div>
    );
  },
);
PaymentMethodCard.displayName = "PaymentMethodCard";

function NetworkMark({ network }: { network: "visa" | "mastercard" | "amex" }) {
  if (network === "mastercard") {
    return (
      <svg aria-label="Mastercard" height="24" role="img" viewBox="0 0 40 24" width="40">
        <circle cx="15" cy="12" fill="oklch(0.7 0.17 40)" r="8" />
        <circle cx="25" cy="12" fill="oklch(0.75 0.15 75)" opacity="0.85" r="8" />
      </svg>
    );
  }
  return (
    <span className="text-label font-semibold uppercase tracking-[0.08em]">
      {network === "amex" ? "Amex" : "Visa"}
    </span>
  );
}

Also in Cards

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where PaymentMethodCard sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Cards changes

Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.