Zoomable Image
inferencesh/zoomable-imageFreeBlock
Click-to-zoom image component with medium.com-style lightbox.
Install it
npx shadcn@latest add https://ui.inference.sh/r/zoomable-image.jsonSource
1"use client"23import Zoom from "react-medium-image-zoom"4import "react-medium-image-zoom/dist/styles.css"5import "./zoomable-image.css"6import { ImageOff } from "lucide-react"7import { DetailedHTMLProps, ImgHTMLAttributes, useState } from "react"89export interface ZoomableImageProps10 extends DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement> {11 /** Disable zoom behavior */12 disabled?: boolean13 /** Higher quality image src to load when zoomed */14 zoomSrc?: string15 /** Offset in pixels from window boundaries when zoomed */16 zoomMargin?: number17}1819export default function ZoomableImage({20 src,21 alt,22 className,23 onLoad,24 onError,25 disabled = false,26 zoomSrc,27 zoomMargin = 16,28 ...rest29}: ZoomableImageProps) {30 const [hasError, setHasError] = useState(false)3132 if (!src) return null3334 const handleError = (e: React.SyntheticEvent<HTMLImageElement, Event>) => {35 setHasError(true)36 onError?.(e)37 }3839 if (hasError) {40 return (41 <div className="aspect-square w-full h-24 flex items-center justify-center rounded-md">42 <div className="flex flex-col items-center gap-2 text-muted-foreground">43 <ImageOff strokeWidth={1} className="w-8 h-8" />44 </div>45 </div>46 )47 }4849 const image = (50 <img51 src={src}52 alt={alt || ""}53 className={className}54 onLoad={onLoad}55 onError={handleError}56 {...rest}57 />58 )5960 if (disabled) {61 return image62 }6364 return (65 <Zoom66 classDialog="zoomable-image-dialog"67 zoomMargin={zoomMargin}68 zoomImg={zoomSrc ? { src: zoomSrc } : undefined}69 >70 {image}71 </Zoom>72 )73}
What it pulls in
npm packages
More from inferencesh
All 14 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Agent Chatagent | inferencesh | Blocks | Free | 1 dep | |
| Chat UI Primitiveschat | inferencesh | Blocks | Free | 1 dep | |
| Code Blockcode-block | inferencesh | Blocks | Free | no deps | |
| Markdown Renderer (legacy)markdown | inferencesh | Blocks | Free | 2 deps | |
| pretext-mdpretext-md | inferencesh | Blocks | Free | 4 deps | |
| Sidebar Lightsidebar-light | inferencesh | Blocks | Free | no deps | |
| Stepssteps | inferencesh | Blocks | Free | no deps | |
| Table of Contentstable-of-contents | inferencesh | Blocks | Free | no deps |
