Callout
A callout separates a piece of information from the surrounding text. The icon and the colors are configurable, so a note, a warning, and a tip can each have a distinct appearance.
Introduction
In Univer Docs, callout blocks serve three purposes:
- They draw attention to a note, a warning, or a tip.
- They apply the icon and colors selected for the block, so its appearance matches the content.
- They divide a document into sections that are visually separate and read independently.
Plugin mode
Installation
pnpm add @univerjs-pro/docs-callout @univerjs-pro/docs-callout-uinpm install @univerjs-pro/docs-callout @univerjs-pro/docs-callout-uiyarn add @univerjs-pro/docs-callout @univerjs-pro/docs-callout-uibun add @univerjs-pro/docs-callout @univerjs-pro/docs-callout-uiUsage
import { UniverDocsCalloutPlugin } from '@univerjs-pro/docs-callout'import { UniverDocsCalloutUIPlugin } from '@univerjs-pro/docs-callout-ui'import DocsCalloutUIEnUS from '@univerjs-pro/docs-callout-ui/locale/en-US'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import '@univerjs-pro/docs-callout-ui/lib/index.css'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DocsCalloutUIEnUS, ), },})univer.registerPlugin(UniverDocsCalloutPlugin)univer.registerPlugin(UniverDocsCalloutUIPlugin)If your application uses Univer under a commercial license, configure it as described in Using License in Client.
Mobile support
Configure the mobile editor first. In the plugin-mode setup on this page, replace the desktop registrations listed below with the mobile exports from the same packages, and make the replacement before opening a document. Keep the model plugins, styles, locales, and Facade imports, and do not register both variants.
| Package | Desktop registration | Mobile registration |
|---|---|---|
@univerjs-pro/docs-callout-ui | UniverDocsCalloutUIPlugin | UniverDocsCalloutMobileUIPlugin |
Facade API
Import the facade before calling the API:
import '@univerjs-pro/docs-callout/facade'Get all callouts
const doc = univerAPI.getActiveDocument()const callouts = doc?.getCallouts() ?? []Get a callout by ID
const doc = univerAPI.getActiveDocument()const callout = doc?.getCallout('callout-block-id')Insert a callout
const doc = univerAPI.getActiveDocument()const callout = doc?.insertCallout({ startOffset: 12, endOffset: 35, config: { icon: '💡' },})Update callout config
const callout = univerAPI.getActiveDocument()?.getCallout('callout-block-id')callout?.updateConfig({ icon: '⚠️' })Set callout appearance
const callout = univerAPI.getActiveDocument()?.getCallout('callout-block-id')callout?.setIcon('📝')callout?.setBackgroundColor('#FFF4E5')callout?.setBorder({ color: '#E6A23C', width: 2 })callout?.setTextColor('#5C3B00')Appearance changes are applied through document commands, so undo, redo, and collaboration receive them. setTextColor() applies a color to all text in the callout; call resetTextColor() to remove that override and restore the text colors inherited from the document.
const callout = univerAPI.getActiveDocument()?.getCallout('callout-block-id')callout?.resetTextColor()How is this guide?