Skip to main content
Complete technical reference for the Template Builder component.

Component props

Required props

None - the component works with zero configuration.

Optional props

document
object
Document loading configuration
fields
object
Field configuration
menu
object
Field insertion menu configuration
list
object
Field list sidebar configuration
toolbar
boolean | string | ToolbarConfig
Document editing toolbar.
  • true: render a default toolbar container
  • string: CSS selector of an existing element to mount the toolbar into
  • object: full toolbar configuration (see ToolbarConfig)
defaultLockMode
'unlocked' | 'sdtLocked' | 'contentLocked' | 'sdtContentLocked'
Lock mode for all inserted fields. Per-field lockMode overrides this. See lock modes.
fieldColors
Record<string, string>
Colors for field types in the document and sidebar. Keys are fieldType values, values are CSS colors (e.g. { owner: '#629be7', signer: '#d97706' }). Generates scoped CSS automatically: no stylesheet import needed.
cspNonce
string
Content Security Policy nonce for dynamically injected styles
className
string
CSS class name for the root container
style
React.CSSProperties
Inline styles for the root container
documentHeight
string
default:"'600px'"
Height of the document editor area
telemetry
object
Telemetry configuration. Enabled by default with source: 'template-builder' metadata. See Telemetry for details.
licenseKey
string
License key for SuperDoc. Passed directly to the underlying SuperDoc instance.
onReady
() => void
Called when the document is loaded and ready
onTrigger
(event: TriggerEvent) => void
Called when the trigger pattern is typed
onFieldInsert
(field: TemplateField) => void
Called when a field is inserted
onFieldUpdate
(field: TemplateField) => void
Called when a field is modified
onFieldDelete
(fieldId: string | number) => void
Called when a field is removed
onFieldsChange
(fields: TemplateField[]) => void
Called whenever the complete field list changes
onFieldSelect
(field: TemplateField | null) => void
Called when a field is selected/deselected in the document
onFieldCreate
(field: FieldDefinition) => void | Promise<FieldDefinition | void>
Called when user creates a new field (requires fields.allowCreate = true). Return a modified FieldDefinition to override the field before insertion, or void to use the field as-is.
onExport
(event: ExportEvent) => void
Called when template is exported via exportTemplate(). Use this to persist field metadata to your database alongside the document.

Types

FieldDefinition

Available fields that users can insert:
presetContent is applied only for mode: "block" fields. Inline fields ignore it.

TemplateField

Fields that exist in the template document:

TriggerEvent

Information about trigger detection:

ExportEvent

Data provided when a template is exported:

FieldMenuProps

Props passed to custom menu components:

FieldListProps

Props passed to custom list components:

ExportConfig

Configuration for template export:

Ref methods

Access these methods via a ref:

insertField()

Insert an inline field at the current cursor position:
Returns boolean - true if inserted successfully.

insertBlockField()

Insert a block-level field:
Returns boolean - true if inserted successfully.

updateField()

Update an existing field:
Returns boolean - true if updated successfully.

deleteField()

Remove a field from the template:
Returns boolean - true if deleted successfully. If the deleted field was the last in a group with two members, the remaining field’s group tag is automatically removed.

selectField()

Programmatically select a field:

nextField()

Navigate to the next field (equivalent to Tab key):

previousField()

Navigate to the previous field (equivalent to Shift+Tab):

getFields()

Get all fields in the template:

refresh()

Re-discover fields from the editor and trigger onFieldsChange. Use this when field data arrives asynchronously or after external changes to the document:

exportTemplate()

Export the template as a .docx file:
Returns Promise<void | Blob> depending on triggerDownload setting.

getSuperDoc()

Access the underlying SuperDoc editor instance:
Returns SuperDoc | null.

Field type styling

Use the fieldColors prop to color-code fields by type:
This generates scoped CSS automatically. Each color controls the field border and label in the document. Sidebar badges match. For manual control, you can still import the standalone stylesheet and use CSS variables:

CSS classes

Target these classes for custom styling:

Import types

All TypeScript types are exported: