API reference
type Pin = { top: number; left: number; id?: string | number;};top and left are percentages (0â100) of the visible image content box.
PinnerComponentProps
Section titled âPinnerComponentPropsâUsed with custom pin components on the composite ImagePinner:
type PinnerComponentProps = { top: number; left: number; itemNumber: number;};ImagePinnerImageRenderProps
Section titled âImagePinnerImageRenderPropsâProps passed to ImagePinner.Imageâs render function (spread onto <img />):
type ImagePinnerImageRenderProps = ComponentPropsWithoutRef<"img"> & { ref: Ref<HTMLImageElement>; "data-react-image-pinner-image"?: "";};ImagePinner (composite)
Section titled âImagePinner (composite)âA convenience wrapper. Combines Root, Image, Overlay, and `Item.
| Prop | Type | Description |
|---|---|---|
src | string | Image URL. |
pins | T[] where T extends Pin | Pin list. |
onAddPin | (pin: Pin) => void | Called when the user clicks the image to add a pin (optional). |
pinnerComponent | ComponentType<PinnerComponentProps & T> | Custom pin UI (optional). |
alt | string | Image alt text (default ""). |
imageClassName | string | Class on the <img> (default ""). |
containerClassName | string | Class on the outer wrapper. |
renderDefaultPinner | (itemNumber: number, pin: T) => ReactElement | Fallback when pinnerComponent is omitted. |
renderImage | (props: ImagePinnerImageRenderProps) => ReactElement | Same as ImagePinner.Image render. |
Composable components
Section titled âComposable componentsâImagePinner.Root
Section titled âImagePinner.RootâContext provider and relative wrapper (data-react-image-pinner). Renders a <div> element.
| Prop | Type |
|---|---|
pins | T[] |
onAddPin | (pin: Pin) => void (optional) |
children | ReactNode |
className | string (optional) |
style | CSSProperties (optional) |
ImagePinner.Image
Section titled âImagePinner.ImageâRegisters the image, handles resize, and click-to-add when onAddPin is set. Renders an <img> element.
| Prop | Type |
|---|---|
render | (props: ImagePinnerImageRenderProps) => ReactElement (optional) |
ImagePinner.Overlay
Section titled âImagePinner.OverlayâAbsolutely positioned overlay aligned to the image for rendering items. Renders a <div> element.
ImagePinner.Item
Section titled âImagePinner.ItemâSingle pin container. Positions children at pin.left% / pin.top% with translate(-50%, -50%). Renders a <div> element.
| Prop | Type |
|---|---|
pin | Pin |
ImagePinner.Items
Section titled âImagePinner.ItemsâMaps pins from context. Renders each pin with <ImagePinner.Item>.
| Prop | Type |
|---|---|
render | ({ pin, itemNumber }) => ReactNode |
getKey | (pin, itemNumber) => string | number (optional) |
ImagePinner.DefaultPinner
Section titled âImagePinner.DefaultPinnerâSmall numbered circle fallback (itemNumber is 0-based). Renders a <span> element.
Utilities
Section titled âUtilitiesâgetRenderedContentBox(image: HTMLImageElement)
Section titled âgetRenderedContentBox(image: HTMLImageElement)âReturns { left, top, width, height } of the image content as drawn. For advanced layout outside the provided overlay.