Examples
Responsive image with preview
Preserve a meaningful alt description and open a larger version in the shared Dialog.
Responsive preview image
import { Image } from "@phuctech/ui/components/image";
const sample = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='360'%3E%3Crect width='100%25' height='100%25' fill='%23dbeafe'/%3E%3Ccircle cx='320' cy='180' r='72' fill='%232563eb'/%3C/svg%3E";
export function Example() {
return <Image src={sample} alt="Blue circle on a light blue background" preview width={640} height={360} className="w-full rounded-lg" />;
}
Contain inside a fixed frame
Use contain for artwork that should stay fully visible inside a known frame.
Contained poster image
import { Image } from "@phuctech/ui/components/image";
const sample = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='480'%3E%3Crect width='100%25' height='100%25' fill='%23dcfce7'/%3E%3Cpath d='M40 400 160 80l120 320Z' fill='%2315803d'/%3E%3C/svg%3E";
export function Example() {
return <Image src={sample} alt="Green triangle poster" fit="contain" width={320} height={480} className="h-64 w-48 rounded-lg border border-border bg-muted" />;
}
Load failure fallback
A failed image shows an accessible fallback in the same reserved region.
Image fallback state
import { Image } from "@phuctech/ui/components/image";
export function Example() {
return <Image src="data:image/png;base64,invalid" alt="Workspace avatar" fallback="Avatar preview unavailable" className="w-48" />;
}
Try the image
Inspect a wide image with preview enabled.
Image property playground
import { Image } from "@phuctech/ui/components/image";
const sample = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='360'%3E%3Crect width='100%25' height='100%25' fill='%23fef3c7'/%3E%3Cpath d='M0 360 220 90l130 140 95-90 195 220Z' fill='%23b45309'/%3E%3C/svg%3E";
export function Example() {
return <Image src={sample} alt="Amber mountain landscape" preview width={640} height={360} className="w-full rounded-lg" />;
}
Usage
import { Image } from "@phuctech/ui/components/image";
<Image src={src} alt="Quarterly results chart" preview loading="lazy" />Behavior
Image renders a native responsive img, forwards native image attributes such as dimensions, loading, and decoding, and does not fetch metadata. The shared package does not choose a framework-specific image optimizer. When loading fails, the supplied fallback (or default message) replaces the image. Preview opens the same source in the shared Dialog.
API
Accessibility
Meaningful images require a text alternative. The preview trigger names the image, the modal title repeats that description, and load failure keeps the same accessible name. The decorative fit and frame styling carry no meaning.