Examples

Local preview picker

Preview
Example.tsx
import { useState } from 'react';
import { FilePreview } from '@reactloom/files';
import { Stack } from '@reactloom/ui';

export default function Example() {
  const [file, setFile] = useState<File>();
  return <Stack gap="3">
    <label>Choose an image or PDF <input type="file" accept="image/png,image/jpeg,image/webp,application/pdf"
      onChange={(event) => setFile(event.target.files?.[0])} /></label>
    {file && <FilePreview file={file} />}
  </Stack>;
}

Download fallback

Preview

Preparing preview…

reconciliation.txt · 29 bytes
Example.tsx
import { FilePreview } from '@reactloom/files';
import { useState } from 'react';

export default function Example() {
  const [file] = useState(() => new File(['Payment reconciliation report'], 'reconciliation.txt', { type: 'text/plain' }));
  return <FilePreview file={file} messages={{ unavailable: 'Download this report to view it in a text editor.' }} />;
}

API reference

FilePreview props
PropTypeDefault
file
The browser File to display.
File—
alt
Image description. Falls back to the filename.
string—
messages
Customize preview and download text.
Partial<FilePreviewProps["messages"]>—

Keyboard interaction

Keyboard interactions
KeyAction
TabFocus the download link or the native PDF viewer
EnterDownload the file

Usage guidelines

The root figure accepts className, style, and a ref.

Do

  • Supported raster image formats include PNG, JPEG, GIF, WebP, BMP, and AVIF. In browsers with an inline PDF viewer, PDFs open within the preview. Downloads are available for other formats.

Don’t

  • Avoid requiring an inline preview to access the file.