Create a toolbar with different slots for the default layout

This example demonstrates how we can reorganize the toolbar that is created by the Default Layout plugin.
By default, the toolbar will be displayed at the top of main viewer component. However, it is possible to create a custom toolbar by using the renderToolbar option.
import { ReactElement } from 'react';
import { ToolbarProps } from '@react-pdf-viewer/default-layout';
renderToolbar?: (Toolbar: ((props: ToolbarProps) => ReactElement)) => ReactElement;
Here is the sample code that organizes the toolbar slots:
const renderToolbar = (Toolbar: (props: ToolbarProps) => ReactElement) => (
<Toolbar>
{(slots: ToolbarSlot) => {
const {
CurrentPageInput,
Download,
EnterFullScreen,
GoToNextPage,
GoToPreviousPage,
NumberOfPages,
Print,
ShowSearchPopover,
Zoom,
ZoomIn,
ZoomOut,
} = slots;
return (
<div
style={{
alignItems: 'center',
display: 'flex',
}}
>
<div style={{ padding: '0px 2px' }}>
<ShowSearchPopover />
</div>
<div style={{ padding: '0px 2px' }}>
<ZoomOut />
</div>
<div style={{ padding: '0px 2px' }}>
<Zoom />
</div>
<div style={{ padding: '0px 2px' }}>
<ZoomIn />
</div>
<div style={{ padding: '0px 2px', marginLeft: 'auto' }}>
<GoToPreviousPage />
</div>
<div style={{ padding: '0px 2px' }}>
<CurrentPageInput /> / <NumberOfPages />
</div>
<div style={{ padding: '0px 2px' }}>
<GoToNextPage />
</div>
<div style={{ padding: '0px 2px', marginLeft: 'auto' }}>
<EnterFullScreen />
</div>
<div style={{ padding: '0px 2px' }}>
<Download />
</div>
<div style={{ padding: '0px 2px' }}>
<Print />
</div>
</div>
);
}}
</Toolbar>
);
const defaultLayoutPluginInstance = defaultLayoutPlugin({
renderToolbar,
});
Take a look at the toolbar plugin to know more about the toolbar slots.

See also