Preview
Preview

Displays prepared Markdown, text, CSV, email HTML, PDF, and image content in a composable preview surface.

Overview

Preview is a composable shell for displaying prepared content in a panel, dialog, or other constrained surface. Compose its fixed translucent header with Toolbar, then render the appropriate content component inside Preview.Content.

Cubitt owns the preview layout, presentation, read-only renderers, HTML isolation, and PDF controls. Consumers own file loading, authorization, MIME type detection, CSV parsing, document conversion, email attachment resolution, remote-content approval, download actions, and error state. Pass content to Preview only once it is ready to display.

Usage

import { Preview } from "@tilt-legal/cubitt-components/preview";
import { Toolbar } from "@tilt-legal/cubitt-components/toolbar";
<Preview aria-label="Attachment preview">
  <Preview.Header>
    <Toolbar>
      <Toolbar.Heading>
        <Toolbar.Title className="truncate text-base">
          {fileName}
        </Toolbar.Title>
      </Toolbar.Heading>
      <Toolbar.Actions>{actions}</Toolbar.Actions>
    </Toolbar>
  </Preview.Header>
  <Preview.Content>
    <Preview.Markdown content={markdown} />
  </Preview.Content>
</Preview>

Examples

Markdown

Use Preview.Markdown for prepared Markdown content. It uses the Cubitt Editor in read-only Markdown mode.

Plain Text

Use Preview.Text for plain text. Blank lines become ordinary Markdown paragraphs while the editor remains read-only.

CSV

Parse the CSV in the consuming application, then pass prepared columns and rows to Preview.Csv. It renders the standard Cubitt Table and does not own parsing, schema inference, sorting, or filtering.

Email HTML

Use Preview.Html for prepared email body HTML. It renders the markup in an opaque-origin sandbox with scripts, forms, embeds, and remote resources blocked. Inline email styles remain available, and images resolved by the consumer to data: or blob: URLs can render.

The consumer fetches the email and decides whether remote content is trusted. Resolve approved CID, attachment, or remote image references before passing the HTML to Cubitt; Preview.Html does not fetch or approve them.

PDF

Preview.Pdf receives a ready PDF URL and provides the context shared by its controls and view. Put Preview.Pdf.Controls in the header toolbar so zoom controls sit alongside consumer-owned actions.

Image

Preview.Image accepts normal image attributes. The consumer supplies the URL, alternative text, and any load or error handling. The image retains its natural dimensions and aspect ratio, shrinking only when the available preview area is smaller.

Loading

Keep the normal header and actions mounted while the consumer prepares the content. Disable actions that cannot run until the preview is ready.

In a Dialog

Use DialogContent with fullscreen when the PDF viewer should temporarily take over the workspace while preserving its page rail and toolbar controls.

API Reference

Preview

Root layout for the preview header and content.

PropTypeDefaultDescription
childrenReactNode-Header and prepared preview content.
classNamestring-Overrides or extends the root layout.

Also accepts standard section props.

Preview.Header

Fixed translucent header region intended for a consumer-composed Toolbar.

PropTypeDefaultDescription
childrenReactNode-Usually a Toolbar with a title and actions.
classNamestring-Overrides or extends the header layout.

Also accepts standard header props.

Preview.Content

Flexible content region containing one preview renderer.

PropTypeDefaultDescription
childrenReactNode-Prepared preview renderer or loading state.
classNamestring-Overrides or extends the content layout.

Also accepts standard div props.

Preview.Markdown and Preview.Text

Read-only Cubitt Editor renderers using the Markdown content format.

PropTypeDefaultDescription
contentstring-Prepared Markdown or plain text content.
classNamestring-Overrides or extends the editor root.

Also accept standard div props except the native content attribute.

Preview.Csv

Standard Cubitt Table presentation for consumer-parsed CSV data.

PropTypeDefaultDescription
columnsPreviewCsvColumn[]-Ordered column definitions with id and label.
rowsPreviewCsvRow[]-Rows with a stable id and a string cell record keyed by column id.
captionstring-Optional accessible table caption.

Also accepts ScrollArea props except children.

type PreviewCsvColumn = {
  id: string;
  label: string;
};

type PreviewCsvRow = {
  id: string;
  cells: Readonly<Record<string, string>>;
};

Preview.Html

Isolated renderer for consumer-prepared email HTML.

PropTypeDefaultDescription
htmlstring-Prepared email body HTML. Document-level meta and base elements are ignored.
titlestring-Required accessible title for the isolated document.
classNamestring-Overrides or extends the iframe layout.

Also accepts standard iframe props except security-sensitive source, sandbox, permission, referrer, title, child-content, and fullscreen props. The iframe security policy cannot be weakened through component props.

Preview.Pdf

Root provider for a prepared PDF URL, zoom controls, and rendered pages.

PropTypeDefaultDescription
srcstring-Ready PDF URL or data URL.
childrenReactNode-Header and content containing the PDF controls and view.
onReady() => void-Called after the first page renders successfully.
onError() => void-Called once when the PDF source or first page fails.

Preview.Pdf.Controls renders the built-in zoom controls. Preview.Pdf.View renders the page rail and document pages. Both must be used inside Preview.Pdf.

Preview.Image

PropTypeDefaultDescription
srcstring-Ready image URL or data URL.
altstring-Accessible image description.
classNamestring-Overrides or extends image styles.

Also accepts standard img props. alt is required; width and height remain optional when the consumer wants to provide intrinsic metadata.

Preview.Loading

Presentation-only loading state. The consumer decides when loading starts, finishes, or fails.

PropTypeDefaultDescription
childrenReactNode"Loading preview"Loading message.
classNamestring-Overrides or extends the loading layout.

Also accepts standard output props.

On this page