本文へ移動
日本語
「カード詳細とロック」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

The component is the whole scene, so the card, the blur and the sheet share one timeline. Opening: the card tips its top edge toward you (rotateX −18° and 28px closer at 38% of 620ms) and lands flat while it shrinks to 64% toward the top; a veil with a 10px backdrop blur fades in over the screen content in 360ms; the sheet rises in 460ms after 60ms, and its title, details panel and lock row follow 40ms apart. Closing runs the other way, quicker: the sheet drops in 280ms, the card folds back with a small tip the other way and springs to full size. Locking frosts the card: a cool tint with fine rime and a backdrop desaturate fades in, a glint crosses once, and a Locked badge springs onto the middle. Copy writes the value without spaces to the clipboard and swaps its icon for a check for 1.6s.

向いている場面

  • The card screen of a banking, wallet or expense app.
  • Revealing sensitive details on demand, with copy buttons for paying online.
  • Letting people freeze a card themselves when it goes missing.

向かない場面

  • Card pickers or lists of several cards: show them as a list first.
  • Forms where people type card details: use input fields.
  • Anything that is not a card: the scene is built around one.

使い方

import { useState } from 'react'
import { CardLockSheet } from './CardLockSheet.jsx'

export function WalletCard({ card, balance, setCardFrozen }) {
  const [open, setOpen] = useState(false)
  return (
    <CardLockSheet
      card={{ holder: card.holderName, number: card.number, expiry: card.expiry, cvc: card.cvc }}
      open={open}
      onOpenChange={setOpen}
      locked={card.frozen}
      onLockedChange={(frozen) => setCardFrozen(card.id, frozen)}
      onCopy={(field) => track('card_copy', { field })}
    >
      <Balance value={balance} />
      <button onClick={() => setOpen(true)}>Details</button>
    </CardLockSheet>
  )
}

プロパティ

プロパティ型既定値説明
card{ holder, number, expiry, cvc, kind? }—What the card and the sheet show. The card face shows only the last four digits; the sheet shows everything.
artReactNode—Replaces the default graphite card face; it fills the card and is clipped to its corners.
childrenReactNode—The screen under the card (balance, actions). It blurs and becomes inert while the sheet is open.
openboolean—Whether the details sheet is open (controlled). Pressing the card opens it.
defaultOpenbooleanfalseInitial state when uncontrolled.
onOpenChange(open) => void—Called when the card, the close button, the blurred area or Escape opens or closes the sheet.
lockedboolean—Whether the card is locked (controlled). Locked frosts the card and shows the badge.
defaultLockedbooleanfalseInitial lock state when uncontrolled.
onLockedChange(locked) => void—Called when the Lock switch changes. Update your backend here, and pass locked back once it succeeds.
onCopy(field, text) => void—Called after a Copy button writes the value (spaces removed) to the clipboard; field is number, expiry or cvc.
cardWidthnumber240Width of the card in pixels; the height follows the standard card ratio.
labelsobject—Replaces built-in text: kind, show, title, close, number, expiry, cvc, copy, copied, copiedNote(field), lock, lockHint, lockedHint, locked. Shallow-merged over the English defaults.
...restHTMLAttributes—Other attributes go to the root; set its size through style or a class (the sheet needs about 230px under the shrunken card).

アクセシビリティ

  • The card is a native button with aria-expanded, named by labels.show (plus labels.locked when locked).
  • The sheet is a dialog labelled by its title; focus moves into it on open and returns to the element that opened it on close. Escape and the close button close it.
  • While the sheet is open the card and the screen content are inert, so keyboard and screen-reader focus stay in the sheet.
  • Each copy button is an icon button named "Copy: <field>" (then "Copied: <field>"); a status region announces what was copied.
  • The Lock control is a native checkbox with role switch inside its label, so the whole row toggles it.
  • Reduced motion shows the sheet, blur and frost at once; nothing tips, rises or glints.

モーション

Open: card tip 620ms ease-out, shrink to 64% 560ms; veil 360ms; sheet 460ms ease-out after 60ms; rows 240–360ms, 160ms in and 40ms apart. Close: sheet 280ms ease-in; card 520ms fold and spring. Lock: frost 360ms, glint 900ms, badge 420ms spring after 120ms.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

CardLockSheet.jsxcard-lock-sheet.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

カード
「動く枠線カード」は Pro に含まれます。解除するとプレビューが表示されます。
「ビームボーダー」は Pro に含まれます。解除するとプレビューが表示されます。
「封筒を開く」は Pro に含まれます。解除するとプレビューが表示されます。