Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Structure

DocumentViewport

A scrolling, zoomable document of pages, rendering only the pages near the view.

Pages one under another

When to useLink to "When to use"

  • Documents of pages: PDFs, scans, slides, where people read, zoom and work on a page.

Use something else when:

UsageLink to "Usage"

tsx
Copy
<ZoomControls zoom={zoom} percent={scale * 100} onZoomChange={setZoom} />
<DocumentViewport
  label="Contract.pdf"
  pages={pages}
  zoom={zoom}
  onZoomChange={setZoom}
  onScaleChange={setScale}
  renderPage={({ id, scale, visibleRect }) => <PageCanvas id={id} scale={scale} only={visibleRect} />}
/>

pages are { id, width, height } at 100%. renderPage draws a page at scale; for very large pages draw only visibleRect. Use onCurrentPageChange to keep a page rail in step, and scrollTo (with a new nonce each time) to go to a page or centre a spot on it.

PropsLink to "Props"

Every prop of DocumentViewport
PropWhat it doesTypeDefault
labelRequired
Names the viewport ("Document", "Contract.pdf").string
pagesRequired
The pages, top to bottom, each with its size at 100%.readonly ViewportPage[]
renderPageRequired
Draws one page. Called for each page in or near the view.(page: RenderPageProps) => ReactNode
zoom
The zoom setting, when you control it: fit width, fit page or a percent.ZoomSetting
defaultZoom
Default fit-width.ZoomSettingfit-width
onZoomChange
Gestures and keys ask for a percent.((zoom: ZoomSetting) => void)
onVisiblePagesChange
The pages in view, top to bottom.((ids: string[]) => void)
onCurrentPageChange
The page with the most of itself in view.((id: string | null) => void)
onScaleChange
The scale the zoom came to (fit modes depend on the viewport).((scale: number) => void)
scrollTo
Scrolls to a page, or to a rect on it. A new nonce scrolls again.ScrollRequest
labels
Replace the built-in English text: page names and the zoom announcement.Partial<DocumentViewportLabels>
className
Added to the scrolling root element, for layout.string
style
Layout only (give it a height). Restyle through --cy-document-viewport-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Roles: a named region and tab stop; each page is a group named "Page 3 of 12". Go-to-page with scrollTo.focus moves focus to the page.
  • Zoom: Ctrl/Cmd+wheel or a pinch zooms around the pointer; Ctrl/Cmd and =, - or 0 zoom in, out and to 100% while focus is inside. Changes are announced ("Zoom 125%").
  • Pan: hold Space and drag with a mouse or pen; one finger scrolls.
Behaviour and accessibility, table 1
KeyDoes
Arrow keys, Page Up/DownScroll
Ctrl/Cmd + = / -Zoom in / out a step
Ctrl/Cmd + 0100%
Space (held) + dragPan
Ctrl wheel zooms around the pointer

ThemingLink to "Theming"

Tokens: --cy-document-viewport-background, --cy-document-viewport-gap and --cy-document-viewport-page-shadow.

ZoomControls · SelectionFrame · VirtualList

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog