Skip to main content

Render Props

renderTopRightUI

(isMobile: boolean, appState:AppState) => JSX | null

A function returning JSX to render custom UI in the top right corner of the app.

Live Editor
Result
Loading...

renderCustomStats

A function that can be used to render custom stats (returns JSX) in the nerd stats dialog.

Nerd Stats

For example you can use this prop to render the size of the elements in the storage as do in excalidraw.com.

Live Editor
Result
Loading...

renderSidebar

() => JSX | null;

You can render custom sidebar using this prop. This sidebar is the same that the library menu sidebar is using, and can be used for any purposes your app needs.

You need to import the Sidebar component from excalidraw package and pass your content as its children. The function renderSidebar should return the Sidebar instance.

The <Sidebar> component takes these props (all are optional except children):

PropTypeDescription
childrenReact.ReactNodeContent you want to render inside the sidebar.
onClosefunctionInvoked when the component is closed (by user, or the editor). No need to act on this event, as the editor manages the sidebar open state on its own.
onDockfunctionInvoked when the user toggles the dock button. The callback recieves a boolean parameter isDocked which indicates whether the sidebar is docked
dockedbooleanIndicates whether the sidebar isdocked. By default, the sidebar is undocked. If passed, the docking becomes controlled, and you are responsible for updating the docked state by listening on onDock callback. To decide the breakpoint for docking you can use UIOptions.dockedSidebarBreakpoint for more info on docking.
dockablebooleanIndicates whether to show the dock button so that user can dock the sidebar. If false, you can still dock programmatically by passing docked as true.

The sidebar will always include a header with close / dock buttons (when applicable). You can also add custom content to the header, by rendering <Sidebar.Header> as a child of the <Sidebar> component. Note that the custom header will still include the default buttons.

Sidebar.Header

nametypedescription
childrenReact.ReactNodeContent you want to render inside the sidebar header as a sibling of close / dock buttons.

To control the visibility of the sidebar you can use toggleMenu("customSidebar") api available via ref.

Live Editor
Result
Loading...

renderEmbeddable

(element: NonDeleted<ExcalidrawEmbeddableElement>, appState: AppState) => JSX.Element | null

Allows you to replace the renderer for embeddable elements (which renders <iframe> elements).

ParameterTypeDescription
elementNonDeleted<ExcalidrawEmbeddableElement>The embeddable element to be rendered.
appStateAppStateThe current state of the UI.