组件

Peel corner

A page whose corner curls back to show the sheet underneath. Hover the corner to lift it, drag it to peel along a diagonal crease, click or press Enter to open it. For a discount code, a hint, a secret, a P.S.

安装

terminal
npx shadcn@latest add @wobko/peel-corner

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

示例

Default

Hover the bottom-right corner, drag it, or click. The sheet underneath is out of reach until the corner is open.

Left corner, kraft page

corner="bottom-left" mirrors everything (use it for right-to-left pages); back="kraft" makes the flap the same stock as the page.

Voucher with a copy button

A real use: the code lives on the sheet underneath, with a working button. It is inert until the corner is open, then a normal control. Controlled, so the page can open it too.

API 参考

PeelCorner

The root: a positioned box that holds the page and the sheet under it, draws the turned-back flap (the back of the paper, with its stepped shadow on the sheet underneath) and puts a 56 px corner button over it. The flap is drawn once and scaled about the corner, so crease and shadow stay in proportion at every stage.

属性类型默认值说明
peeled / defaultPeeled / onPeeledChangeboolean-Controlled or uncontrolled: true when the corner is open and the sheet underneath can be read.
sizenumber120How big the turned-back corner is when open, px. A drag can go about a third further.
corner"bottom-right" | "bottom-left""bottom-right"Which corner curls; the bottom left mirrors the flap, the clip and the underneath content.
backPaintKey"paper"The token the flap (the back of the page) is made of: "kraft" for a kraft page, "sticky-yellow" for a sticky note.
labelstring"Peel back the corner"Accessible name of the corner button.

无障碍

  • The corner is a real <button> with aria-expanded and aria-controls (the sheet underneath). Enter and Space toggle it, a screen reader's activate works, and a drag is only an extra.
  • What is underneath is inert and aria-hidden while the corner is closed, so it is neither focusable nor read early; once open it is ordinary content.
  • The corner button is a 56 px square laid over the page's corner: keep links and buttons out of that square, or they cannot be reached with a pointer.
  • Controlled: if the parent declines a change (`peeled` stays as it was), the corner eases back to what the prop says instead of staying half open.
  • The hit area is 56 px, bigger than the curl. Dragging back toward the corner closes it; a short pull that never gets half way springs back; pointercancel springs back.
  • Reduced motion: the corner jumps between rest, open and closed instead of easing. Calm density keeps the flap and the button and trims the flap's shadow to two steps.
  • The flap and its shadow are drawn art, aria-hidden and click-through; the keyboard focus ring is drawn round the corner button.

源码

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

正在加载源码