Skip to main content

Custom Toolbar

Windoc's React package exports every toolbar tool as an individual component. You can compose your own toolbar with exactly the tools you need.

Using Individual Tools

import {
Editor,
UndoTool, RedoTool,
BoldTool, ItalicTool, UnderlineTool,
FontTool, FontSizeTool,
LeftAlignTool, CenterAlignTool, RightAlignTool,
TableTool, ImageTool,
} from '@windoc/react'

function MyToolbar() {
return (
<div style={{ display: 'flex', gap: 4, padding: 8, borderBottom: '1px solid #e5e7eb' }}>
<UndoTool />
<RedoTool />
<BoldTool />
<ItalicTool />
<UnderlineTool />
<FontTool />
<FontSizeTool />
<LeftAlignTool />
<CenterAlignTool />
<RightAlignTool />
<TableTool />
<ImageTool />
</div>
)
}

export default function App() {
return (
<Editor toolbar={false} renderToolbar={<MyToolbar />} />
)
}

Available Tools

ComponentDescription
UndoToolUndo last action
RedoToolRedo last action
BoldToolToggle bold
ItalicToolToggle italic
UnderlineToolToggle underline
StrikeoutToolToggle strikethrough
ColorToolText color picker
HighlightToolBackground highlight
FontToolFont family selector
FontSizeToolFont size selector
TitleToolHeading level selector
LineHeightToolLine height selector
LeftAlignToolAlign left
CenterAlignToolAlign center
RightAlignToolAlign right
JustifyToolJustify text
ListToolOrdered/unordered lists
TableToolInsert table
ImageToolInsert image
ColumnToolColumn layout
SeparatorToolHorizontal separator
PageBreakToolPage break
WatermarkToolWatermark settings

Building Fully Custom Tools

Use the useEditor hook to access the editor instance and build any custom tool:

import { useEditor } from '@windoc/react'

function PrintButton() {
const { editorRef } = useEditor()

return (
<button onClick={() => editorRef.current?.command.executePrint()}>
Print
</button>
)
}

The useEditor hook also gives you rangeStyle — the current selection's style state — so you can show active states:

function MyBoldButton() {
const { editorRef, rangeStyle } = useEditor()

return (
<button
onClick={() => editorRef.current?.command.executeBold()}
style={{ fontWeight: rangeStyle?.bold ? 'bold' : 'normal' }}
>
B
</button>
)
}