组件

Flip card

An index card with two sides. It turns over in 3D when you click it or press Space, lifting off the desk on the way; the side you cannot see is inert and hidden from assistive technology. For flashcards, reveals, and anything with a back.

安装

terminal
npx shadcn@latest add @wobko/flip-card

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

Click it, or Tab to it and press Space. The card lifts off the desk as it turns.

Notepad flip

axis="x" turns it like a page of a top-bound pad. Any paper works for either face.

Vocabulary deck

A real use: a controlled flip card as a study deck. Turning is the answer; Next shows the front of the following card.

Buttons on the faces

trigger={false} leaves the card free of the overlay, so a face can hold real buttons. The flip button is your own.

API 参考

FlipCard

The root: a perspective box holding the two faces in one grid cell (so it is as big as the bigger face) and, by default, a trigger button over the whole card. Size it with className (default h-48 w-72).

属性类型默认值说明
flipped / defaultFlipped / onFlippedChangeboolean / boolean / (flipped: boolean) => void-Controlled or uncontrolled: true shows the back.
axis"y" | "x""y"Turn like a page (y) or like a notepad (x).
triggerbooleantrueLay a button over the whole card. Turn it off when the faces hold links or buttons, and compose your own FlipCardTrigger.
labelstring"Flip card"Accessible name of the default trigger.

FlipCardTrigger

The button that turns the card, with aria-pressed. The default overlay carries a curled arrow in the corner that darkens on hover and a drawn focus ring round the card.

属性类型默认值说明
asChildboolean-Use your own element (a Button) as the trigger.
overlaybooleantrueCover the whole card. Off: it is an ordinary button placed by you.
hintboolean-The corner arrow; default on for the overlay.

无障碍

  • The trigger is a real <button> with aria-pressed (true while the back shows); Space and Enter turn the card. Give it a name that says what happens ("Show the answer").
  • The hidden face is inert and aria-hidden, so Tab and screen readers only see the side that is showing.
  • The default overlay covers the card, so faces should be static text. Faces with links or buttons: trigger={false} and a FlipCardTrigger placed beside them.
  • The card has a fixed size (h-48 w-72 unless you pass another) and its faces do not scroll: size it (`className="h-64 w-96"`) for the longer face, and keep answers short.
  • Reduced motion: the card swaps sides without turning or lifting (durations collapse to zero).
  • The corner arrow and the focus ring are drawn and aria-hidden; the focus ring is the same blue felt as every other control.

源码

CLI 会复制进你项目的文件。

正在加载源码