/** * The React viewer with two components of this app inside it: * * - a status picker in the main toolbar (`ToolbarItem`, placed by the layout), and * - a tab bar of its own in place of the viewer's (`Region name="tabs"`), which reads the open * documents through `usePDFViewer()` and switches and closes them through `viewer.documents`. * * Both live in the page's DOM, so this app's stylesheet (`index.css`) styles them. */ import { useEffect, useState } from 'react'; import { PDFViewer, Region, ToolbarItem, usePDFViewer } from '@embedpdf/viewer-react'; import type { DocumentInfo, LayoutFunction } from '@embedpdf/viewer-react'; const STATUS = { draft: { label: 'Draft', color: '#f59e0b' }, review: { label: 'In review', color: '#3b82f6' }, final: { label: 'Final', color: '#10b981' }, } as const; function DocStatus() { const [status, setStatus] = useState('draft'); return ( ); } /** This app's own tab bar: the open documents, from the viewer. */ function AcmeTabBar() { const viewer = usePDFViewer(); const [documents, setDocuments] = useState(viewer.documents.list()); const [activeId, setActiveId] = useState(viewer.documents.getActiveId()); useEffect(() => { const offDocuments = viewer.watch(() => viewer.documents.list(), setDocuments); const offActive = viewer.watch(() => viewer.documents.getActiveId(), setActiveId); return () => { offDocuments(); offActive(); }; }, [viewer]); return ( ); } const layout: LayoutFunction = (base) => base.add({ custom: 'status' }, { to: 'main', section: 'end' }); export function App() { return ( ); }