Numbered notes pinned to places on a picture, listed beside it, such as feedback on a design or a bug on a screenshot.
- 4.5 kB JS 4.0 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 8 tests
Click the picture to add a note.
3 open notes
- Priya Raman2h ago
The Pay button looks disabled while it isn't. Use the accent color.
- Wei Chen1h ago
Card number needs the card brand's mark once it's typed.
- Tomás García20m ago
This line fails contrast. Darken it, and link the terms.
Press Add a note to place one with the keyboard.
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { ImageAnnotator, ImageNote } from "./ui/uicontext/components/ImageAnnotator.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { checkoutScreen } from "./checkout-screen.ts"const styles = stylex.create({ wrap: { inlineSize: "100%" } })const start: ReadonlyArray<ImageNote> = [ { id: "n1", x: 0.33, y: 0.75, author: "Priya Raman", when: "2h ago", text: "The Pay button looks disabled while it isn't. Use the accent color." }, { id: "n2", x: 0.31, y: 0.44, author: "Wei Chen", when: "1h ago", text: "Card number needs the card brand's mark once it's typed." }, { id: "n3", x: 0.9, y: 0.6, author: "Ada Okafor", when: "Yesterday", text: "Show the tax line, even when it's zero.", resolved: true }, { id: "n4", x: 0.2, y: 0.93, author: "Tomás García", when: "20m ago", text: "This line fails contrast. Darken it, and link the terms." },]const Message = UiSchema.TaggedEnum({ Added: { x: Schema.Number, y: Schema.Number, text: Schema.String }, Resolved: { id: Schema.String, resolved: Schema.Boolean },})// a design review: the app keeps the notes and saves them; here they live in the pageexport const DesignReview = Html.component({ name: "DesignReview", model: Schema.Struct({ notes: Schema.Array(ImageNote), next: Schema.Number }), message: Message,}).make({ init: () => ({ notes: start, next: 5 }), update: { Added: ($, { x, y, text }) => $.evolve({ notes: [...$.model.notes, { id: `n${$.model.next}`, x, y, text, author: "You", when: "Just now" }], next: $.model.next + 1 }), Resolved: ($, { id, resolved }) => $.evolve({ notes: $.model.notes.map((n) => (n.id === id ? { ...n, resolved } : n)) }), }, view: (h, model) => h.div.attrs(sx(styles.wrap)).children( ImageAnnotator(h, { key: "review", props: { label: "Checkout screen, v3", src: checkoutScreen, alt: "A checkout page: a card form with a Pay button, and the order beside it", notes: model.notes }, onEmit: { RequestedAdd: ({ x, y, text }) => Message.Added({ x, y, text }), RequestedResolve: ({ id, resolved }) => Message.Resolved({ id, resolved }), }, }), ),})When to use
Numbered notes pinned to places on a picture, listed beside it, such as feedback on a design or a bug on a screenshot. Use Canvas instead when people draw and arrange shapes, not leave notes on a fixed picture.
Usage
import { ImageAnnotator, type ImageNote } from "./ui/uicontext/components/ImageAnnotator.ts"export const Review = <M>(h: Html.H<M>, src: string, notes: ReadonlyArray<ImageNote>, onAdd: (x: number, y: number, text: string) => M, onResolve: (id: string, resolved: boolean) => M) => ImageAnnotator(h, { props: { label: "Design review", src, alt: "The design under review", notes }, onEmit: { RequestedAdd: ({ x, y, text }) => onAdd(x, y, text), RequestedResolve: ({ id, resolved }) => onResolve(id, resolved), }, })Examples
Read only
readOnly keeps the notes for reading: no adding, no resolving.
Read only
2 open notes
- Customer
Pressed Pay three times, nothing happened.
- Support
Total is right; the card was charged once.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { ImageAnnotator } from "./ui/uicontext/components/ImageAnnotator.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { checkoutScreen } from "./checkout-screen.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 44rem)" } })// a bug report's screenshot, read by the engineer who picks it up: notes to read, not to addexport const BugScreenshot = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( ImageAnnotator(h, { key: "bug", props: { label: "Screenshot attached to BUG-3120", src: checkoutScreen, alt: "The checkout page as the customer saw it", readOnly: true, notes: [ { id: "b1", x: 0.42, y: 0.75, author: "Customer", text: "Pressed Pay three times, nothing happened." }, { id: "b2", x: 0.9, y: 0.6, author: "Support", text: "Total is right; the card was charged once." }, ], }, }), )API reference
Props
| Name | Type | Description |
|---|---|---|
labelrequired | string | What the picture is: "Checkout screen, v3". |
srcrequired | string | — |
altrequired | string | — |
notesrequired | ImageNote[] | — |
readOnly | boolean | Notes can't be added or resolved: a review that's closed. |
locale | string | For the counts; the browser's by default. |
Events
| Event | Payload | Description |
|---|---|---|
RequestedAdd | { x: number; y: number; text: string } | A note was written: where it goes and what it says. |
RequestedResolve | { id: string; resolved: boolean } | Resolve or Reopen was pressed on a note. |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/image-annotator