Sections
File Viewer
- Overview
- Anatomy
- Header
- Navigation
- Renderers
FileViewerProvider owns source identity, renderer routing state, resource
loading, controls registration, and sidebar open state. FileViewer is the
spatial root under that provider: it adapts the provider state into the generic
viewer frame and owns layout concerns like sidebarMode and
inlineBreakpoint. Sidebar configuration (side, collapsible, width)
lives on FileViewerSidebar itself.
"use client";
import * as React from "react";
import { useMediaQuery } from "@/hooks/use-media-query";
import { cn } from "@/lib/utils";
import {
FileViewer,
FileViewerContent,
FileViewerDocument,Usage
Use FileViewerPreview for a compact routed preview:
<FileViewerPreview source={source} />The composed form gives you the same file-scoped context with explicit slots:
<FileViewerProvider source={source} defaultSidebarOpen>
<FileViewer>
<FileViewerHeader>
<FileViewerSidebarTrigger />
<FileViewerTitle />
<FileViewerControls />
</FileViewerHeader>
<FileViewerContent>
<FileViewerSidebar aria-label="Document navigation" />
<FileViewerInset>
<FileViewerViewport>
<FileViewerDocument />
</FileViewerViewport>
</FileViewerInset>
</FileViewerContent>
</FileViewer>
</FileViewerProvider>Use FileViewerPreview to embed a single file inside your own layout:
<FileViewerPreview source={source} className="h-full" />Behavior
- Source routing.
FileViewerProviderresolves the source into a category andFileViewerDocumentselects a renderer (PDF, image, CSV, text, Markdown, HTML, Office, …). Passcategoryto force a category instead of detecting one. - Single source of truth. The resolved descriptor and resource are shared through context, so every part reads the same identity — there is no prop drilling between header, sidebar, and inset.
- Sidebar state. The provider owns open/collapsed state
(
defaultSidebarOpen, or controlledsidebarOpen/onSidebarOpenChange);FileViewerpasses that state into the frame and owns layout props such assidebarModeandinlineBreakpoint. The mountedFileViewerSidebaris the single source of sidebar configuration:side,collapsible, andwidth. - Deterministic geometry. Inline sidebar transitions run through one FileViewer motion store. The store publishes sidebar width, document width, progress, and renderer sizing through root CSS variables and the viewport contract, so the rail, inset, and fit-width renderers move from the same scalar.
- Ownership boundary.
FileViewerProviderowns file concerns only: source loading, type routing, download identity, sidebar state, and renderer control registration. Workflow semantics belong outside it.
API Reference
| Prop | Owner | Description |
|---|---|---|
source | FileViewerProvider | The file to display: a url, blob, or text source. Required. |
category | FileViewerProvider | Force a renderer category instead of detecting it from the source. |
isolateStyles | FileViewerProvider | Scope renderer styles so host page CSS cannot leak into the document. |
defaultSidebarOpen | FileViewerProvider | Whether the sidebar starts open. |
sidebarOpen | FileViewerProvider | Controlled sidebar open state. |
onSidebarOpenChange | FileViewerProvider | Fired when the sidebar open state should change. |
sidebarMode | FileViewer | "auto", "inline", or "overlay" sidebar layout mode. |
inlineBreakpoint | FileViewer | Width in px above which auto mode renders the sidebar inline. |
side | FileViewerSidebar | Which side the sidebar mounts on. |
collapsible | FileViewerSidebar | Whether the sidebar can collapse off-canvas. |
layout | FileViewer | "fill" to occupy the host, or "intrinsic" for caller-owned sizing. |
Source
file-viewer.tsx
"use client";
export type { ViewerSource } from "./file-viewer-core";
export {
FileViewerContent,
FileViewerInset,
FileViewerLegend,
FileViewerViewport,
type FileViewerContentProps,
type FileViewerInsetProps,
type FileViewerLegendProps,
type FileViewerViewportProps,