Skip to content
Eskais UI

Data

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
A plant, a mug and two books on a table

Installation

npx shadcn@latest add @eskais/image-scan
npm packageslucide-react

Usage

Import
import { clampBox, imageScan, mapRegionBox } from "@/components/ui/image-scan-primitive"import { clampBox, clampFraction, mapRegionBox } from "@/lib/image-scan-geometry"import { imageScanLabels, ImageScanStatusBar, ImageScanSteps } from "@/components/ui/image-scan-status"import { clampBox, ImageScan, imageScanLabels, mapRegionBox } from "@/components/ui/image-scan"

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

PropTypeDefault
statusrequiredImageScanStatus–
progressnumber–
statusTextstring–
stepsreadonly ImageScanStep[]–
stepstring–
errorstring–
actionsReactNode–
countrequirednumber–
labelsrequiredImageScanLabels–
scan(event: Event) => void–
cancel(event: Event) => void–
retry(event: Event) => void–

ImageScanSteps

PropTypeDefault
stepsrequiredreadonly ImageScanStep[]–
stepstring–
labelrequiredstring–

ImageScan

PropTypeDefault
srcrequiredstring–
altrequiredstring–
widthIn pixels; keeps the frame's ratio before the image loads.number–
heightnumber–
imagePropsOmit<ComponentProps<"img">, "src" | "alt" | "width" | "height">–
statusImageScanStatus"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–
stepsreadonly ImageScanStep[]–
stepThe id of the step running now; the steps before it show as done.string–
regionsreadonly ImageScanRegion[]noRegions
selectedRegionstring | null–
defaultSelectedRegionstring | 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 truebooleantrue
actionsShown beside the state's own controls.ReactNode–
labelsPartial<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 ImageScanRegion

Accessibility

  • 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.