dolfindevelopers

Document viewer

ComponentFoundationsSDK + UI

Shows a PDF in a frame or an image preview from a URL or Blob, with loading, empty and error states. It never fetches; pass the URL from a hook.

Component: A piece you place inside your own screens: a table, a form, a card or a dialog. You decide the layout around it. Pages vs components

Choose your integration

Works with Dolfin’s SDK context, with appearance and behaviour you can customise. Requires DolfinProvider.

Loading preview…

Installation

Needs the Dolfin registry token. The CLI copies the source into your app.

Terminal
bunx --bun shadcn@4.23.0 add @dolfin/base-document-viewer

Also installs: ui-base-document-viewer.

Usage

screen.tsx
import { DocumentViewer } from "@/components/dolfin/base/document-viewer";

// Place it anywhere inside your <DolfinProvider>.
<DocumentViewer />

Renders inside DolfinProvider (set it up once). It renders the data you pass as props.

API reference

PropTypeDescription
srcstring | BlobA URL (signed file URL, blob: URL) or the file itself. Fetching is the caller's job, usually a hook.
fileTypestringMIME type; defaults to the Blob's type, else guessed from the URL. Anything not an image renders as PDF.
titlestringAccessible title of the frame or image alt text.
loadingboolean
error{}
onRetry() => void
emptyStatestring | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re…Replaces the "No document available" state.
showOpenLinkbooleanShows an "Open in new tab" link above the document.
classNamestring

Customisation

Without editing the source, you can change:

Class names
className
Messages
base.documentViewerbase.statescore.errors

Or edit the installed file directly: it is your code. See theming for colours and fonts.

Hooks

The SDK hooks this component uses. Use them directly from @dolfinai/react to build your own version.

useMessages

Files

Written to your app by the install command:

  • components/dolfin/base/document-viewer.tsx 47 lines