File Thumbnail
retab-ui/file-thumbnailFreeComponent
Render complete file thumbnails from browser files, URLs, blobs, text sources, external images, or custom preview content.
Install it
npx shadcn@latest add https://ui.retab.com/r/file-thumbnail.jsonSource
1"use client";23import type { ViewerSource } from "@/lib/viewer-source";4import { GeneratedFileThumbnail } from "@/components/file-thumbnail/generated-preview";56import {7 FileThumbnailFrame,8 FileThumbnailShimmer,9 hasRenderablePreviewContent,10 resolveFileThumbnailState,11} from "./file-thumbnail-frame";12import type {13 FileThumbnailFrameProps,14 FileThumbnailProps,15 FileThumbnailShape,16 FileThumbnailSize,17 FileThumbnailSource,18 FileThumbnailState,19 ThumbnailFile,20} from "./file-thumbnail-types";2122export {23 FileThumbnailFrame,24 FileThumbnailShimmer,25 hasRenderablePreviewContent,26 resolveFileThumbnailState,27};28export type {29 FileThumbnailFrameProps,30 FileThumbnailProps,31 FileThumbnailShape,32 FileThumbnailSize,33 FileThumbnailSource,34 FileThumbnailState,35 ThumbnailFile,36};3738/**39 * Render a complete file thumbnail from a browser File, a viewer source, an40 * externally generated image, custom preview content, or plain file metadata.41 */42export function FileThumbnail({43 source,44 file,45 as,46 anchor,47 presentation = "document",48 retryKey,49 onError,50 ...frameProps51}: FileThumbnailProps) {52 const resolvedSource = resolveFileThumbnailSource(source, file);53 const accessibilityProps =54 presentation === "decorative"55 ? ({56 "aria-hidden": true,57 role: "presentation",58 } as const)59 : {};60 const {61 previewClassName: _previewClassName,62 previewContent: _previewContent,63 previewImageUrl: _previewImageUrl,64 onPreviewError: _onPreviewError,65 state: _state,66 ...thumbnailProps67 } = frameProps;6869 if (shouldUseFrame(frameProps) || !resolvedSource) {70 return (71 <FileThumbnailFrame72 {...frameProps}73 {...accessibilityProps}74 file={file ?? fileFromSource(resolvedSource)}75 />76 );77 }7879 return (80 <GeneratedFileThumbnail81 {...thumbnailProps}82 {...accessibilityProps}83 source={resolvedSource}84 as={as}85 anchor={anchor ?? "top-left"}86 retryKey={retryKey}87 onError={onError}88 />89 );90}9192function shouldUseFrame({93 previewContent,94 previewImageUrl,95 state,96}: Pick<97 FileThumbnailProps,98 "previewContent" | "previewImageUrl" | "state"99>): boolean {100 return (101 hasRenderablePreviewContent(previewContent) ||102 Boolean(previewImageUrl) ||103 state !== undefined104 );105}106107function resolveFileThumbnailSource(108 source: FileThumbnailProps["source"],109 file: FileThumbnailProps["file"],110): ViewerSource | null {111// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from retab-ui
All 130 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alertalert | retab-ui | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | retab-ui | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | retab-ui | Components | Free | no deps | |
| Attachment Sidebarattachment-sidebar | retab-ui | Components | Free | 1 dep | |
| Autocompleteautocomplete | retab-ui | Components | Free | 2 deps | |
| Calendarcalendar | retab-ui | Components | Free | 2 deps | |
| Code Viewercode-viewer | retab-ui | Components | Free | 2 deps · 32 files | |
| Commandcommand | retab-ui | Components | Free | 2 deps |
