Browse docs
Build a custom preview
Use the views when your application already has parsed data or needs its own
layout. A CSV result goes to TableView; an object goes to JsonTreeView; media
views take playable URLs.
The example below combines a loader, table and persistent header. Use FilePreview when its built-in layout is sufficient.
Usage
Keep the header visible while CSV data loads:
Choose a view from the data you already have:
| Data | View |
|---|---|
| Columns and rows | TableView |
| Ordered metadata pairs | KeyValueView |
| One JSON value | JsonTreeView |
| A list of JSON records | JsonlView |
| Image URL | ImageView |
| Video URL | VideoView |
| Audio URL | AudioView |
| Text | TextView |
| Loading, error or another empty state | StatusView |
Header & sub-bar
PreviewHeader
Shows the filename, parent directory and supplied metadata. size is in bytes;
a missing parent directory displays as /.
Code PreviewHeaderSpec.tsx
PreviewSubBar
Use the left slot for a summary and the right for actions or status, such as row count and truncation, or line count and Save. Both accept React content.
Code PreviewSubBarSpec.tsx
Tabular data
TableView
Pass columns and rows in matching order. Optional types appear below column names. Values render as supplied; the view does not parse or sort them.
| # | idint64 | episodestring | stepint32 | rewardfloat32 | donebool |
|---|---|---|---|---|---|
| 1 | 1 | ep-0001 | 0 | 0 | false |
| 2 | 2 | ep-0001 | 1 | 0.12 | false |
| 3 | 3 | ep-0001 | 2 | 0.34 | false |
| 4 | 4 | ep-0001 | 3 | 0.87 | true |
| 5 | 5 | ep-0002 | 0 | 0 | false |
| 6 | 6 | ep-0002 | 1 | null | false |
| 7 | 7 | ep-0002 | 2 | 0.51 | true |
Code TableViewSpec.tsx
For a sample, set truncated and, if known, totalRows. shownRows changes
only the summary label: every supplied row renders. Slice or page rows first.
Replace summaries with subInfoLeft and subInfoRight, or hide them with
hideSubBar.
KeyValueView
Pass string pairs for metadata such as array shape, dtype or recording duration. The view preserves their order.
| format | Apache Parquet v2.9 |
|---|---|
| compression | ZSTD (level 3) |
| rows | 5,000 |
| row groups | 4 |
| created by | pyarrow 15.0.2 |
| schema sha | a31b…f902 |
Code KeyValueViewSpec.tsx
JSON & JSONL
JsonTreeView
Expand object and array labels to inspect a parsed value.
defaultOpenDepth={1} opens the root; larger values open more levels.
Code JsonTreeViewSpec.tsx
JsonlView
Pass the records returned by loadJsonl to display numbered lines.
Code JsonlViewSpec.tsx
Long records are truncated visually. Use JsonTreeView for full-record inspection.
Media
ImageView
Fits the image while preserving aspect ratio. Supply alt text; onLoad
reports natural resolution as W×H.
Code ImageViewSpec.tsx
VideoView
Uses native video controls. onLoadedMetadata reports seconds and W×H
resolution. Playback depends on browser codec support; partial seeking reads
depend on server Range support.
Code VideoViewSpec.tsx
Handle VideoErrorInfo through onError. Loading without metadata or an error
shows an advisory after 15 seconds; change stallMs or set it to 0 to disable
the advisory. See error demos.
AudioView
Uses native audio controls and reports duration in seconds through its metadata callback.
Text
TextView shows line-numbered text. onSave enables Edit; without it the view
is read-only. ext labels the format without syntax highlighting or Markdown rendering.
# notes.md
- Verify the value-function head still trains on the new env.
- Re-run sweep at gamma in {0.99, 0.995, 0.999}.
- File regressions land in the parquet under datasets/2026-05/.
> The reward shaping change is responsible for the ~7% bump on
> success-rate. Roll forward.
Code TextViewSpec.tsx
Cmd/Ctrl-S saves; Escape discards edits. Resolve onSave after persistence and
update the parent text value. Reject the promise to display an inline error.
A new text prop replaces unsaved edits and exits editing. Apply refreshes only
when the application intends that replacement.
Status states
Render a status in the content area while the preview is unavailable:
Code StatusViewSpec.tsx
kind | When to use it | Relevant props |
|---|---|---|
empty | No file is selected. | — |
loading | Fetching or parsing. | label describes the operation. |
error | Loading or parsing failed. | message, optional label and hint. |
too-large | The file exceeds your preview limit. | sizeBytes, capBytes, optional hint. |
unsupported | No preview handles the format. | ext names the extension. |
Use hint for recovery instructions or a download link. Keep the same container
size while switching between status and content.
Props reference
PreviewHeader props
| Prop | Type | Default | Meaning |
|---|---|---|---|
name | string | required | Filename. |
ext | string | omitted | Extension used for the file icon. |
path | string | omitted | Full path; its parent directory appears above the filename. |
size | number | omitted | Byte size. |
modified | Date | string | omitted | Dates are formatted as YYYY-MM-DD HH:mm; strings display as supplied. |
PreviewSubBar props
| Prop | Type | Default | Meaning |
|---|---|---|---|
left | ReactNode | required | Summary or other content on the left. |
right | ReactNode | required | Actions or status on the right; pass null if unused. |
TableView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
cols | TableColumn[] | required | { name, type? } definitions in display order. |
rows | unknown[][] | required | Rows with values in column order. All supplied rows render. |
totalRows | number | null | shown count | Total row count when known. |
shownRows | number | rows.length | Count used in summary labels; does not slice rows. |
truncated | boolean | false | Shows the partial-result notice. |
subInfoLeft | ReactNode | counts | Replaces the left summary. |
subInfoRight | ReactNode | truncation notice | Replaces the right summary. |
hideSubBar | boolean | false | Omits the summary bar. |
KeyValueView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
items | Array<[string, string]> | required | Key/value pairs in display order. |
JsonTreeView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
value | unknown | required | Parsed JSON object, array or scalar. |
defaultOpenDepth | number | 2 | Levels initially open. 0 starts collapsed; Infinity opens all levels. |
JsonlView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
records | unknown[] | required | Parsed records, displayed one per line. |
ImageView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
src | string | required | Image URL. |
alt | string | '' | Alternative text; supply a useful description. |
onLoad | (resolution: string) => void | omitted | Receives natural dimensions as W×H. |
VideoView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
src | string | required | Video URL. |
ext | string | omitted | Extension included in error messages. |
onLoadedMetadata | (info: { duration: number; resolution: string }) => void | omitted | Receives seconds and W×H dimensions. Zero-sized video calls onError instead. |
onError | (info: VideoErrorInfo) => void | omitted | Receives { kind, code, title, message, hint } for a failure. |
stallMs | number | 15000 | Delay before the loading advisory; 0 disables it. |
AudioView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
src | string | required | Audio URL. |
onLoadedMetadata | (info: { duration: number }) => void | omitted | Receives duration in seconds. |
TextView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
text | string | required | Text content. Changes replace local edits. |
ext | string | omitted | Format label. |
onSave | (text: string) => Promise<void> | omitted | Enables editing. Resolve after saving; reject to display an error. |
StatusView props
| Prop | Type | Default | Meaning |
|---|---|---|---|
kind | 'empty' | 'loading' | 'error' | 'too-large' | 'unsupported' | required | State to display. |
label | string | state-specific | Loading caption or error headline. |
message | string | 'Preview failed' | Error detail. |
ext | string | omitted | Extension in the unsupported-format message. |
sizeBytes | number | 0 | Actual file size for too-large. |
capBytes | number | 0 | Preview limit for too-large. |
hint | ReactNode | omitted | Additional error help, or replacement size-limit explanation. |