Image Scan
An image under analysis, from a controlled status: a preview, a scan (a turning sweep or a progress line over the image, a progress bar, steps and Cancel), the detected regions as buttons over the image with a legend, or an error with Retry. Announces each change; agents get scan, cancel, retry and selectRegion.
Example
Drop a photo hereOr crop the sample below
image-scan-demo.tsxCopy code
Installation
Copy code
npm packages
lucide-reactUsage
ImportCopy code
Reach for it to show a photo while something analyses it, then what it found: drive status from your model's events, and pair it with FileUpload and ImageCropper to pick and crop first.
API reference
ImageScanStatusBar
| Prop | Type | Default |
|---|---|---|
statusrequired | ImageScanStatus | – |
progress | number | – |
statusText | string | – |
steps | readonly ImageScanStep[] | – |
step | string | – |
error | string | – |
actions | ReactNode | – |
countrequired | number | – |
labelsrequired | ImageScanLabels | – |
scan | (event: Event) => void | – |
cancel | (event: Event) => void | – |
retry | (event: Event) => void | – |
ImageScanSteps
| Prop | Type | Default |
|---|---|---|
stepsrequired | readonly ImageScanStep[] | – |
step | string | – |
labelrequired | string | – |
ImageScan
| Prop | Type | Default |
|---|---|---|
srcrequired | string | – |
altrequired | string | – |
widthIn pixels; keeps the frame's ratio before the image loads. | number | – |
height | number | – |
imageProps | Omit<ComponentProps<"img">, "src" | "alt" | "width" | "height"> | – |
status | ImageScanStatus | "uploaded" |
progressFrom 0 to 1 while scanning; leave it out while the scan can't tell how far it is. | number | – |
statusTextThe progress bar's label; `labels.scanning` by default. | string | – |
steps | readonly ImageScanStep[] | – |
stepThe id of the step running now; the steps before it show as done. | string | – |
regions | readonly ImageScanRegion[] | noRegions |
selectedRegion | string | null | – |
defaultSelectedRegion | string | null | – |
onSelectedRegionChange | (region: string | null, details: ImageScanChangeDetails) => void | – |
onCancelWithout it, no Cancel while scanning. | (details: ImageScanEventDetails) => void | – |
onRetryWithout it, no Retry after an error. | (details: ImageScanEventDetails) => void | – |
onScanWithout it, no Scan button while the image waits. | (details: ImageScanEventDetails) => void | – |
errorAnnounced at once in the error state; `labels.error` by default. | string | – |
fitHow the image fills a frame of another ratio; regions follow it. | ImageScanFit | "contain" |
aspectRatioThe frame's width over height; the image's own by default. | number | – |
legendLists the regions under the image. @defaultValue true | boolean | true |
actionsShown beside the state's own controls. | ReactNode | – |
labels | Partial<ImageScanLabels> | – |
Also takes <div> attributes and render except children.
Other exports
clampBoximageScanmapRegionBoxclampFractionimageScanLabelstype ImageScanActionReasontype ImageScanAnnouncementstype ImageScanBoxtype ImageScanFittype ImageScanOptionstype ImageScanRegionItemtype ImageScanSelectReasontype ImageScanSizetype ImageScanStatustype ImageScanLabelstype ImageScanStatusBarPropstype ImageScanSteptype ImageScanChangeDetailstype ImageScanEventDetailstype ImageScanPropstype ImageScanRegionAccessibility
- The image's alt names the group, which is aria-busy while it scans; the progress bar has the status text as its label.
- Scanning, progress (at most every tenth and two seconds), the result count and errors are announced; errors at once.
- Each region is a toggle button over the image, named by its label, in reading order; the legend below is pointer only and hidden from assistive tech.
- Under reduced motion the sweep and the line's glide stop: a still frame and the progress bar remain.
Agent actions
Agents see the image by its alt with the regions as items, and call scan, cancel, retry and selectRegion.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.