组件

Stamp button

A button that is a rubber stamp: a wooden knob on an inked die, in the color of the impression it will leave. Press it and APPROVED, PAID or VOID lands on the page with a thump. The stamps on a page are JSON, so they can be state.

安装

terminal
npx shadcn@latest add @wobko/stamp-button

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

示例

Stamp the page

Press the stamp and an impression lands on the document with a thump; the page gives a little. Press it again and a fresh strike replaces the last (Approve twice is still one APPROVED).

Inks and shapes

The tool takes the color of the pad it will leave: green, red, blue felt, black. Any preset from the sticker sheet works, or give the words and the shape yourself.

An approval

A real review step: the stamps are the state. Approving or rejecting leaves its impression on the expense report (a second decision replaces the first), the status badge follows it, and Reset clears the page.

API 参考

StampSurface

The page that takes stamps: a positioned box holding your document and any number of StampButtons (a footer, a toolbar, anywhere inside). It shows the impressions above its content, gives 2 px under each stamp and announces it politely.

属性类型默认值说明
value / defaultValueStampImpression[]-The impressions on the page: { id, press, x, y (fractions of the surface), name or text, shape, ink, turn, seed, … }. Plain JSON; clear it with [] or restore a saved one.
onValueChange(value: StampImpression[]) => void-Called on every strike.
maxnumber-Keep only the most recent N impressions.

StampButton

The tool: pad ink from the preset (or `ink`), a label on the die, a handle on top. Hover lifts the die on a drop-line, press sinks it and inks it heavier. Striking a stamp again replaces its own impression with a new one (own wear, own turn, one in five a double strike).

属性类型默认值说明
stampstring-A preset from the sticker sheet: stamp-approved, stamp-paid, stamp-void, stamp-urgent, stamp-received, stamp-draft, stamp-new, stamp-member. Other props override it.
text / shape / ink / sub / ring / w / h / size / ghost / dashedas on Stamp-The impression, when there is no preset or to change one. `ink` is red, ink-you, green or ink.
impressionIdstring-Names the stamp on the page. The same id replaces its impression instead of adding one. Default the preset or the text.
place{ x: number; y: number }{ x: .72, y: .6 }Where to aim, as fractions of the surface. Every strike wanders up to 3 percent from it.
onStamp(impression: StampImpression) => void-Called with the impression that was made.
asChildbooleanfalseDraw the tool on your own element. With disabled, the element gets aria-disabled and the stamp does nothing.
childrenReactNode-The label; default the stamp's word.

无障碍

  • The tool is a real button named by its label; Enter and Space stamp exactly like a click. Outside a StampSurface it stamps on itself, so it still does something.
  • Each impression is an image named by its words (role=img, "Approved"), so the stamped state is in the reading order; a polite status line says "Approved stamped." once per strike.
  • Only a stamp struck now lands with the thump: impressions restored from saved JSON, a defaultValue or the server's markup are simply on the page, so a reload does not stamp everything again. The thump is an enter animation on the impression and a 2 px give on the page; with reduced motion (the OS setting, data-motion="reduced", or the provider) the impression simply appears and the page holds still.
  • The drawn tool is decoration (aria-hidden); its label is DOM text on the die at 4.5:1 or better; focus draws a ring round the whole tool, knob included. Windows high contrast hides the drawing and gives the button a real outline.
  • Do not carry the decision by color alone: the impression says the word, and the label says what pressing does.

源码

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

正在加载源码