组件

Tear-off

A coupon, ticket or raffle strip with a stub you tear off along a perforated line. Pull the stub and it swings off its far corner, tap it or press Enter and it comes away; the ticket keeps a torn edge. Calls onTear once.

安装

terminal
npx shadcn@latest add @wobko/tear-off

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

示例

Default

Pull the stub away, tap it, or focus it and press Enter. The scissors have already started.

Stub below

orientation="vertical" hangs the stub under the ticket, like the free coffee on a punch card. Kraft stock, and it is pulled down.

Coupon book

A real use: onTear redeems the coupon, and a controlled torn state lets the book be reset. The confetti stays inside the ticket.

API 参考

TearOff

The ticket: an inline flex box holding the body and the stub. Keeps the state (attached or torn), announces the tear politely, and lays the stub beside the ticket or below it.

属性类型默认值说明
onTear() => void-Called once when a person tears the stub off (drag, tap or keyboard).
torn / defaultTorn / onTornChangeboolean-Controlled or uncontrolled. Setting a controlled `torn` back to false puts a fresh stub on, dropping onto the ticket.
orientation"horizontal" | "vertical""horizontal"The stub is at the end of the line (start side in right-to-left) or below the ticket.
disabledbooleanfalseThe stub cannot be pulled or torn.
tornMessagestring"Torn off."What the status line says when the stub comes off.

TearOffStub

The stub: a Paper (index card by default) that is a button. The perforation bites are the paper's own perf edge; on top of it are printed dashes, a pair of scissors at the start of the line, and a curled pencil arrow that says which way to pull.

属性类型默认值说明
labelstring-Accessible name. Default: the stub's own text.
stockStockName"index-card"What it is made of.

无障碍

  • The stub is role="button" named by its text (or `label`) and described by "Press Enter or Space to tear it off along the dotted line, or pull it away with a pointer". Enter and Space tear it; pointer dragging is an extra, never the only way.
  • When it comes off the status line says "Torn off." politely, once; the stub then leaves the tab order and the accessibility tree.
  • Pointer: pull at least half way (or all the way) to tear; a shorter pull springs back; a tap tears; a canceled pointer springs back.
  • Focus: when the stub is torn off with the keyboard, focus moves to the ticket itself (it becomes programmatically focusable, with no ring), so Tab carries on from the ticket instead of restarting at the top of the page. Keys typed in something inside the stub never tear it.
  • Reduced motion: the stub does not swing or fall, it is simply gone. Right-to-left layouts put the stub on the left and pull it that way.
  • The perforation and the scissors are decoration (aria-hidden). Calm density leaves the scissors out and keeps the dashes.

源码

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

正在加载源码