File PreviewPRO
Preview an attached or generated file with page thumbnails, zoom, a rolling page counter and a pulsing cited passage.
Code
2 files · 522 lines of TypeScriptPRO
File Preview is part of Pro
Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.
Motion notes
- Pages swap vertically in the direction you travel, with a blur, so paging forward and back feel different. The thumbnail ring glides along the strip on the layout spring and the counter rolls with Animated Number.
- Zoom springs the page's box and its scale together, so the viewport's scroll area grows with the page instead of jumping once the animation ends.
- Setting highlight jumps to its page, waits for the zoom to settle, scrolls the viewport (never the page) to the passage, and pulses a ring out from it three times. Its thumbnail keeps a slow beacon.
- The viewport is a focusable region: ←/→ or PageUp/PageDown change page, + and − zoom, 0 resets. Page and zoom changes are announced politely. With reduced motion, pages cross-fade, zoom snaps and the pulse is removed.
Usage
Example
<FilePreview
name="Q3 report.pdf"
meta="PDF · 12 pages · 2.4 MB"
pages={12}
highlight={citation ? { page: citation.page, top: 0.42, height: 0.12, label: "Quoted" } : null}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| name | string | — | File name, also the viewport's accessible name. |
| meta | string | — | Secondary line, e.g. “PDF · 2.4 MB”. |
| pages | number | { image?, alt?, heading?, lines? }[] | — | Page count, or a description of each page. Pages render as placeholder text lines, with an optional image on top. |
| page | number | — | Controlled 1-based page. |
| defaultPage | number | 1 | Initial page when uncontrolled. |
| onPageChange | (page: number) => void | — | Called on navigation, and with the highlight's page when a new highlight arrives while controlled. |
| zoom | number | — | Controlled zoom. 1 fits the page to the viewport height. |
| defaultZoom | number | 1 | Initial zoom when uncontrolled. |
| onZoomChange | (zoom: number) => void | — | Called when zoom changes. |
| zoomLevels | number[] | [0.5, 0.75, 1, 1.25, 1.5, 2] | Steps for the zoom buttons and keys. |
| highlight | { page, top, height, left?, width?, label? } | null | — | A cited region as fractions (0–1) of the page. Setting it jumps to its page and pulses the passage. |
| showThumbnails | boolean | true | Shows the page strip. |
| height | number | 320 | Viewport height in px. |
| className | string | — | Classes for the card. |
