Image
nexus-ui/imageFreeComponent
Image renderer for URLs, base64, and byte payloads with preview, loader, lightbox, and action slots
Live preview
live · rendered by the registry
Rendered by nexus-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nexus-ui.dev/r/image.jsonSource
1"use client";23import * as React from "react";4import * as DialogPrimitive from "@radix-ui/react-dialog";5import { Slot } from "@radix-ui/react-slot";67import {8 Tooltip,9 TooltipContent,10 TooltipProvider,11 TooltipTrigger,12} from "@/components/ui/tooltip";13import { Kbd } from "@/components/ui/kbd";14import { cn } from "@/lib/utils";1516type ImageData = {17 src?: string;18 base64?: string;19 uint8Array?: Uint8Array;20 mediaType?: string;21};2223function resolveBase64MediaType(base64: string, fallback: string) {24 const trimmed = base64.trim();2526 if (trimmed.startsWith("data:")) {27 return /^data:([^;,]+)/i.exec(trimmed)?.[1] ?? fallback;28 }2930 const normalized = trimmed.replace(/\s+/g, "").slice(0, 120);3132 if (normalized.startsWith("iVBORw0KGgo")) return "image/png";33 if (normalized.startsWith("/9j/")) return "image/jpeg";34 if (normalized.startsWith("R0lGOD")) return "image/gif";35 if (normalized.startsWith("UklGR") && normalized.includes("V0VCUA")) {36 return "image/webp";37 }38 if (normalized.startsWith("PHN2Zy") || normalized.startsWith("PD94bWwg")) {39 return "image/svg+xml";40 }4142 return fallback;43}4445function toDataUrl(base64: string, mediaType: string) {46 const trimmed = base64.trim();47 if (trimmed.startsWith("data:")) return trimmed;48 return `data:${mediaType};base64,${trimmed}`;49}5051function uint8ArrayToBase64(bytes: Uint8Array) {52 let binary = "";53 const chunkSize = 0x8000;54 for (let i = 0; i < bytes.length; i += chunkSize) {55 const chunk = bytes.subarray(i, i + chunkSize);56 binary += String.fromCharCode(...chunk);57 }58 return btoa(binary);59}6061type ImageContextValue = {62 src?: string;63 alt: string;64 mediaType?: string;65 hasError: boolean;66 setHasError: (value: boolean) => void;67};6869const ImageContext = React.createContext<ImageContextValue | null>(null);7071function useImageContext(component: string) {72 const ctx = React.useContext(ImageContext);73 if (!ctx) {74 throw new Error(`${component} must be used within <Image>`);75 }76 return ctx;77}7879export type ImageProps = Omit<80 React.HTMLAttributes<HTMLDivElement>,81 "children"82> &83 Omit<React.ComponentProps<typeof DialogPrimitive.Root>, "children"> &84 ImageData & {85 alt?: string;86 children?: React.ReactNode;87 };8889function Image({90 src,91 base64,92 uint8Array,93 mediaType,94 open,95 defaultOpen,96 onOpenChange,97 modal,98 alt = "",99 className,100 children,101 ...props102}: ImageProps) {103 const hasUint8BlobSource =104// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from nexus-ui
All 15 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Attachmentsattachments | nexus-ui | Components | Free | 4 deps · 2 files | |
| Chain of Thoughtchain-of-thought | nexus-ui | Components | Free | 2 deps · 2 files | |
| Citationcitation | nexus-ui | Components | Free | 4 deps | |
| Feedback Barfeedback-bar | nexus-ui | Components | Free | 1 dep | |
| Messagemessage | nexus-ui | Components | Free | 9 deps · 2 files | |
| Model Selectormodel-selector | nexus-ui | Components | Free | 3 deps | |
| Prompt Inputprompt-input | nexus-ui | Components | Free | 1 dep | |
| Questionsquestions | nexus-ui | Components | Free | 2 deps |
