UI / Interface
Guestbook
A wall of hand-drawn signatures. Visitors sign with real ink, then drag their own signature anywhere on the wall. You bring the storage.
No signatures yet. Be the first.
Installation
npx shadcn@latest add https://jiaweing.com/r/guestbook.jsonWith the @jiaweing namespace set up, use @jiaweing/guestbook in place of the URL.
Usage
tsx
import { Guestbook, type GuestbookEntry } from "@/components/guestbook";tsx
const [entries, setEntries] = useState<GuestbookEntry[]>([]);
<Guestbook
entries={entries}
onSign={async (draft) => {
const res = await fetch("/api/guestbook", {
method: "POST",
body: JSON.stringify(draft),
});
if (!res.ok) throw new Error("Could not save your signature");
const { entry } = await res.json();
setEntries((list) => [...list, entry]);
}}
/>- Built on the uiarc signature pad, which the install adds for you.
- The wall only draws what you pass in. Keep the entries wherever you like and check edits on your server, for example with an edit token per signature.
Props
Guestbook
| Prop | Type | Default | Description |
|---|---|---|---|
| entries | GuestbookEntry[] | - | { id, name?, paths, viewBox, x, y, rotation }. x and y are the centre as a fraction of the wall. |
| onSign | (draft: GuestbookDraft) => Promise<void> | void | - | Saves a new signature. Throw to show the message. Leave out for a read only wall. |
| onMove | (id, x, y) => void | - | A signature you can edit was dropped somewhere new. |
| onRemove | (id: string) => void | - | A signature you can edit was removed. |
| canEdit | (entry) => boolean | () => false | Which signatures this visitor may drag and remove. |
| canSign | boolean | true | Hides the sign button, for example once signed. |
| height | number | 640 | Wall height in pixels. |
| signatureWidth | number | 180 | Width of each signature in pixels. |
| inks | { black?, blue?, violet? } | - | Fill per ink. Black follows the text colour. |
| emptyText | ReactNode | "No signatures yet. Be the first." | Shown on an empty wall. |
| labels | { sign?, title?, description?, name?, submit?, saving?, remove? } | - | Button and dialog text, for other languages. |
| className | string | - | Extra classes, merged with cn. |
MIT licensed. Copy it, change it, ship it.