Skip to content

Default Layout plugin

The default-layout plugin brings the toolbar and a sidebar that contains the following tabs:

Install

> npm install @sse-ui/pdf-default-layout

OR

> yarn add @sse-ui/pdf-default-layout

Usage

1. Import the plugin and styles

javascript
import { defaultLayoutPlugin } from "@sse-ui/pdf-default-layout";

// Import styles
import "@sse-ui/pdf-default-layout/lib/styles/index.css";

2. Create the plugin instance

javascript
const defaultLayoutPluginInstance = defaultLayoutPlugin(
    props?: DefaultLayoutPluginProps
);

The optional parameter DefaultLayoutPluginProps represents an object of the following properties:

(? denotes an optional property)

PROPERTYTYPEDESCRIPTIONFROM
setInitialTab?FunctionSet the initial tab that will be activated in the sidebar.1.0.0
sidebarTabs?FunctionIndicate the tabs in the sidebar.1.0.0
toolbarPlugin?ToolbarPluginPropsThe options of the toolbar plugin.1.0.0
renderToolbar?FunctionCstom toolbar renderer.1.0.0

The plugin instance defaultLayoutPluginInstance provides the following property:

PROPERTYTYPEDESCRIPTIONFROM
activateTabFunctionActivate a given tab1.0.0
attachmentPluginInstanceAttachmentPluginThe instance of the Attachment plugin1.0.0
bookmarkPluginInstanceBookmarkPluginThe instance of the Bookmark plugin1.0.0
thumbnailPluginInstanceThumbnailPluginThe instance of the THumbnail plugin1.0.0
toggleTabFunctionToggle a given tab1.0.0
toolbarPluginInstanceToolbarPluginThe instance of the Attachment plugin1.0.0

3. Register the plugin

FInally, register the default-layout plugin instance:

javascript
const { Bookmarks } = defaultLayoutPluginInstance;

<Viewer plugins={[defaultLayoutPluginInstance]}> />;

Properties

The default-layout plugin provides other properties as following:

javascript
import {
  BookmarkIcon,
  FileIcon,
  ThumbnailIcon,
} from "@sse-ui/pdf-default-layout";
PROPERTYTYPEDESCRIPTIONFROM
BookmarkIconReactElementThe icon shown in the bookmark tab in the sidebar1.0.0
FileIconReactElementThe icon shown in the attachment tab in the sidebar1.0.0
FileIconReactElementThe icon shown in the thumbnail tab in the sidebar1.0.0

Customize the tabs in the sidebar

javascript
const defaultLayoutPluginInstance = defaultLayoutPlugin(
    sidebarTabs: defaultTabs => {
        ...
    },
);

The sidebarTabs property is a function that takes the default tabs and returns the list of tabs you want to display in the sidebar.

Each tab defines the following properties:

javascript
import { SidebarTab } from '@sse-ui/pdf-default-layout
PROPERTYTYPEDESCRIPTIONFROM
contentReactElementThe tab content1.0.0
iconReactElementThe tab icon1.0.0
titleReactElementThe tab title1.0.0

The default tabs is an array of tabs listing thumbnails, bookmark and attachments in that order.

INDEXDESCRIPTIONFROM
defaultTabs[0]The tab lists thumbnails1.0.0
defaultTabs[1]The tab lists bookmarks1.0.0
defaultTabs[2]The tab lists attachments1.0.0

Open a sidebar tab

To open a tab in the sidebar, you can invoke the activateTab function:

javascript
const { activateTab } = defaultLayoutPluginInstance;

// Open the first tab
activateTab(0);

// Open the second tab
activateTab(1);

Toggle a sidebar tab

Call the toggleTab function to toggle a given tab:

javascript
const { toggleTab } = defaultLayoutPluginInstance;

// Open the first tab
toggleTab(0);

// Open the second tab
toggleTab(1);

Released under the MIT License.