File Preview
Preview almost any file in the browser — images, video, PDF, Office, archives, e-mail, CAD, 3D models, maps and code — with a Liquid Glass toolbar and an all-viewer dialog. Every format library loads on demand.
FilePreview is a block (registry:block) built on open-file-viewer:
- Formats: images (incl. HEIC, PSD, TIFF), video (incl. HLS), audio, PDF, Word / Excel / PowerPoint, OFD, EPUB, XPS, archives (ZIP and friends), e-mail (
.eml/.msg), drawings (draw.io, Visio, EMF), XMind, CAD (DWG / DXF), 3D models, GIS data (GeoJSON, KML, GPX), Markdown and source code. Anything else, or any file that fails, shows a download card. - Dynamic imports all the way down: the viewer itself is a
React.lazychunk fetched the first time a preview renders, and each format's library (pdf.js, mammoth, the PPTX renderer, the CAD engine…) is a furtherimport()fetched only when a file of that format opens. A page that shows only PDFs never downloads the Office or CAD code. This works unchanged withoutput: 'export': dynamic imports are split into static chunks at build time. - Liquid Glass surface: inline, the viewer is a glass panel like
Card(mediummaterial); document pages stay paper-white and the glass shows around them.glass={false}renders it 100% opaque. - Liquid Glass toolbar: previous / next, zoom, rotate, text search with a match count, download and print, drawn from the viewer's state — controls a format doesn't support are hidden.
PreviewDialog: a dialog that is all viewer. Maximize and close are the last toolbar buttons; maximize fills the viewport, also on iPhone where the Fullscreen API is unavailable.
Supported formats
Built on @open-file-viewer/core with 6 major format families and 110+ extensions — every format parser loads lazily on demand:
PDF / Office
22Business documents
Image / Media
21Native and enhanced
FLV and M2TS require optional mpegts.js in the host app; otherwise a download fallback is shown.
Text / Code
26Highlight and editor mode
Engineering
24Engineering, layout and structure
Archive / Email
11Structure, body and attachments
Assets / Data
12Structure parsing and safe summaries
Installation (Shadcn Registry)
npx shadcn@latest add @apple-liquid/file-previewNext.js setup
pdfjs-dist installs @napi-rs/canvas (a native Node addon) as an optional dependency, and the EMF / WMF converter imports it as a Node-only fallback. Point it at the bundled stub so it stays out of the browser bundle:
const config = {
turbopack: {
resolveAlias: {
'@napi-rs/canvas': './components/blocks/file-preview/browser-canvas.ts',
},
},
};With webpack, use webpack: (config) => { config.resolve.alias['@napi-rs/canvas'] = false; return config; } instead. Vite and other bundlers need the same alias.
In a dialog
'use client';
import * as React from 'react';
import { FilePreview, PreviewDialog } from '@/components/blocks/file-preview';
export function Attachment({ url, name, mimeType }: { url: string; name: string; mimeType: string }) {
const [open, setOpen] = React.useState(false);
return (
<>
<button onClick={() => setOpen(true)}>{name}</button>
<PreviewDialog open={open} onOpenChange={setOpen} title={name}>
<FilePreview bare source={url} name={name} mimeType={mimeType} />
</PreviewDialog>
</>
);
}Sources and CORS
sourceacceptshttp(s):,blob:and same-origin paths; any other scheme is refused, even as a download link.- Files on another origin (object storage, a CDN) must send
Access-Control-Allow-Originfor your site. When a request fails the preview shows the download card and callsonError; passnoticetoPreviewDialogto offer a "Refresh link" action for expiring signed URLs. - A local
Fileworks throughURL.createObjectURL(file)(remember to revoke it).
Leaving formats out
All plugins are registered by default. excludePlugins drops format families — they fall back to the download card:
<FilePreview source={url} name={name} mimeType={mimeType} excludePlugins={['cad', 'model3d', 'gis']} />Plugin names: image, video, audio, pdf, office, ofd, epub, xps, archive, email, drawing, xmind, cad, model3d, gis, asset, text, fallback.
Excluded plugins never load their libraries, but the plugin code itself stays in the viewer chunk. For full control, build your own list with open-file-viewer's plugin factories and pass it as plugins — create it once at module level, since a new array recreates the viewer.
Externally hosted assets
Two assets come from jsDelivr by default so that nothing has to be copied into public/:
- pdf.js worker —
pdfjs-dist@<version>/build/pdf.worker.mjs. - CAD (LibreDWG WASM + worker) —
@mlightcad/libredwg-web@0.7.4. Self-host it withcadAssets={{ wasmBaseUrl, workerModuleUrl }}.
Props API
FilePreview
| Prop | Type | Default | Description |
|---|---|---|---|
source | string | — | http(s):, blob: or same-origin path |
name | string | — | File name; shown in the fallback, helps detect the format |
mimeType | string | — | MIME type of the file |
onError | (error: Error) => void | — | Load error, 120 s timeout or unsupported format |
excludePlugins | FilePreviewPluginName[] | [] | Format families to leave out |
cadAssets | { wasmBaseUrl, workerModuleUrl } | jsDelivr | LibreDWG assets for the CAD plugin |
plugins | PreviewPlugin[] | all | Replaces the plugin list (advanced) |
viewerLocale | 'zh-CN' | 'en-US' | from <html lang> | Language of the viewer's own panels |
bare | boolean | false | Borderless and filling its parent (inside PreviewDialog) |
glass | boolean | true | Liquid Glass surface (medium material, like Card) and toolbar; glass={false} is 100% opaque. Document pages stay white |
locale | LiquidGlassLocaleInput | Global locale | UI language of this instance; overrides <LiquidGlassProvider locale> |
messages | Partial<FilePreviewMessages> | Built-in text | Text overrides, deep-merged over the built-in text and the global messages.filePreview |
PreviewDialog
| Prop | Type | Default | Description |
|---|---|---|---|
open / onOpenChange | boolean / (open) => void | — | Controlled open state |
title | ReactNode | — | For screen readers only |
notice | ReactNode | — | Shown under the viewer, e.g. a "Refresh link" action |
glass | boolean | true | Glass dialog surface; glass={false} is 100% opaque |
children | ReactNode | — | Usually <FilePreview bare … /> |
DataTable
An admin list block powered by TanStack Table v9 with server-side pagination, sorting, filtering (text, select, date range), column visibility, row selection, and tree rows in Apple 27 Liquid Glass.
Filter Panel
Collapsible Liquid Glass filter area for list pages — a search field plus rows of single / multiple choice chips, kept as a draft until Search and reset in one tap.