组件

Sticker board

A page you can stick stickers on: drag them anywhere, turn them, size them, stack them, with the pointer or the keyboard. The value is plain JSON ({ id, name, x, y, rot, scale, z }) and it exports to one standalone SVG.

安装

terminal
npx shadcn@latest add @wobko/sticker-board

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

示例

Stick things down

Drag a sticker anywhere. Pick one and a dashed frame appears with a ring to turn it by and a square to size it; the toolbar and the keyboard do the same.

The value is JSON

The board keeps no secrets: every sticker is { id, name, x, y, rot, scale, z }. Store it, send it, restore it. addSticker puts a new one on top of the pile.

A reward chart

A read-only board is a display: the stickers a student has earned, lying where the teacher stuck them. No handles, no tab stops, no toolbar.

Board and picker

The picker chooses, addSticker sticks: the new sticker lands in the middle of the page, already picked, so it can be turned and sized straight away. Export downloads the whole page as one SVG.

API 参考

StickerBoard

The state and the layout: a column holding the canvas and the toolbar (pass children to arrange them yourself). Owns the stickers, the picked one, the live region and the export.

属性类型默认值说明
value / defaultValueStickerBoardItem[]-The stickers. x and y are the center of the visible sticker in px from the canvas's top-left; rot is degrees clockwise (-180 to 180); scale 1 is the drawn size; a higher z lies on top. Ids must be unique. JSON that lacks a rot, scale or z (written by hand, or by an older version) is completed on the way in (0, 1, its position in the list), and what comes out through onValueChange is always whole. Built for tens of stickers: each is about 35 KB of markup at 96 px.
onValueChange(value: StickerBoardItem[]) => void-Called once when a drag ends, and on every key press, toolbar action or removal. The pointer writes styles while it drags and does not render per move.
selectedId / defaultSelectedId / onSelectedIdChangestring | null-The picked sticker. Focusing or pressing a sticker picks it; pressing the bare page or Escape lets go.
sizenumber96Drawn size of a sticker at scale 1, px. Below 80 the 64 px redraw is used.
minScale / maxScalenumber0.3 / 3The limits of sizing.
bounds"center" | "inside" | "none""center"Where a sticker may go: its center stays on the canvas, all of it stays on the canvas, or anywhere (the canvas clips).
readOnly / disabledbooleanfalseLook but do not touch: no tab stops, no handles, toolbar actions off (Export still works when read-only).
labelstring"Sticker board"Accessible name of the canvas group.
onExport(data: StickerBoardExport) => void-Receives { items, json, svg, width, height, png() } when Export is pressed. Without it, Export downloads stickers.svg.

StickerBoardCanvas

The page the stickers lie on: a Paper (dot grid by default; any stock and edge work) whose stickers are clipped to it while its shadow and tape are not. Shows a hint while the board is empty.

属性类型默认值说明
emptyReactNode"Nothing stuck down yet."What the empty board says.
stock / edge / tape / …PaperProps-Everything Paper takes.

StickerBoardToolbar

Buttons for what the keyboard does, acting on the picked sticker: turn left and right, smaller and larger, send to back, backward, forward and to front, duplicate, delete and export. One row; every enabled button is a tab stop and left and right arrows also move along it.

属性类型默认值说明
actions("turn" | "size" | "layer" | "duplicate" | "delete" | "export")[]-Which groups to show, in order. Default all.

无障碍

  • The canvas is a named group; every sticker is a focusable group with aria-roledescription "sticker", the picked one carries aria-current, and one line of instructions describes them all.
  • Keys on a focused sticker: arrows move it 8 px (Shift 32, Alt 1); [ and ] (or R and Shift+R) turn it 5 degrees (Shift 15); + and - size it; 0 sets it upright at full size; PageUp and PageDown move it through the stack (Shift goes to the front or the back); Ctrl or Cmd D duplicates; Delete or Backspace removes it and moves focus on; Escape lets go.
  • Every change is announced politely, once, after the last key press ("Rocket at 216, 150.").
  • The turn ring and the size square are pointer handles only (aria-hidden); the keys and the toolbar do the same. Shift while turning snaps to 15 degrees. Deleting from the toolbar moves focus to the bare page with nothing picked (the button that was pressed is disabled by then), so a second press cannot take the next sticker.
  • A read-only or disabled board has no keys, so it offers no instructions: its stickers are named groups and nothing more.
  • The frame and the focus ring are drawn; Windows high contrast gives the picked sticker a real outline.
  • Reduced motion: the small growth on hover is instant. Calm density: stickers do not grow on hover and the frame is drawn thinner.

源码

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

正在加载源码