仕組み
The root only provides perspective; inside it, both faces share one grid cell and the inner wrapper rotates 180° while the back is pre-rotated and backface-visibility hides the far side. Only transform animates. The card is not one big button, because faces often hold buttons and links; an invisible real button (aria-pressed) under the card handles keyboard and screen readers. Add data-flip-toggle to a button in a face to flip from it.
向いている場面
- Membership cards and coupons: summary on the front, details or a QR code on the back.
- Flashcards: question on the front, answer on the back.
- Tight spaces where extra details should not need a dialog or a new page.
向かない場面
- Critical information such as prices or warnings: show it directly instead of hiding it on the back.
- Dozens of flippable cards in a list: use expandable details or a drawer.
- Faces of very different heights: the shorter one leaves a large gap; use an accordion.
使い方
import { FlipCard } from './FlipCard.jsx'
export function MemberCard({ member }) {
return (
<FlipCard
style={{ width: 300 }}
toggleLabel="Show member perks"
front={
<>
<h3>{member.title}</h3>
<p>Click for perks</p>
</>
}
back={
<>
<h3>Member perks</h3>
<p>Free size upgrade on your birthday.</p>
{/* Buttons in a face work as usual; one with data-flip-toggle flips back */}
<button data-flip-toggle>Got it</button>
</>
}
/>
)
}
// Controlled: <FlipCard flipped={flipped} onFlippedChange={setFlipped} trigger="hover" direction="vertical" ... />プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
front | ReactNode | — | Front face content. |
back | ReactNode | — | Back face content. The frame height is that of the taller face. |
flipped | boolean | — | Controlled: whether the back is showing. |
defaultFlipped | boolean | false | Uncontrolled: initial state. |
onFlippedChange | (flipped: boolean) => void | — | Called when the flip state changes. |
trigger | 'click' | 'hover' | 'click' | click flips on empty face space; hover flips while the pointer is over the card. Touch falls back to tap; keyboard focus also flips it. |
direction | 'horizontal' | 'vertical' | 'horizontal' | Turn around the vertical axis (left-right) or the horizontal axis (up-down). |
duration | number | 560 | Flip time in ms. When omitted it follows --ds-duration-slower. |
toggleLabel | string | 'Show back' | Screen reader name of the flip control. Make it specific, such as “Show member perks”. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes go to the root element: className, style (width and --ds-flip-* variables). |
アクセシビリティ
- The flip control is a real <button aria-pressed>: Tab reaches it, Enter and Space flip it; name it with toggleLabel.
- Buttons, links and inputs inside a face keep their own semantics, and clicking them does not flip.
- The hidden face is inert and aria-hidden, so it cannot be tabbed to, read or clicked.
- If focus is in the face being hidden, it moves to the flip control instead of being lost.
- Reduced motion replaces the rotation with a cross-fade.
モーション
A 560ms turn with a slight overshoot (cubic-bezier(0.34, 1.22, 0.64, 1)), transform only; the card shrinks to 0.98 while pressed. With reduced motion, a 240ms opacity cross-fade.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
FlipCard.jsxflip-card.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。







