Classes, data attributes and custom properties

These are the classes and data attributes that charts and diagrams carry, and the custom properties their CSS reads, for your stylesheet. Start your selectors at .tiptap.

Classes

A chart in the editor is built from these elements:

ClassElement
tiptap-chartThe root of a chart, with role="figure" and an aria-label from the description or the title, else <type> chart
tiptap-chart-viewportAround the canvas. The user scrolls inside it while the chart is zoomed in
tiptap-chart-zoom-boxBetween the viewport and the canvas. Takes the room of the zoomed chart
tiptap-chart-canvasThe area the chart takes in the text
tiptap-chart-stageThe element the Renderer draws into. Scaled down by minRenderWidth
tiptap-chart-captionBelow the chart: the description, while the spec has caption: true
tiptap-chart-text-inputThe field a double click opens over a text of the chart (Editing text in a chart)
tiptap-chart-attributionBelow the chart: the link the Renderer's rules ask for, hidden while there is none (Rules of your Renderer)
tiptap-chart-errorThe message shown when drawing failed
tiptap-chart-unavailableWhat unavailable returns, when no Renderer here draws the chart
tiptap-chart-resize-handleA handle that resizes the selected chart, with resizable
tiptap-diagram-inputThe Quick Input, the field where the user types rows after :::
tiptap-diagram-input-placeholderIn the Quick Input, below a line that names the type: the example rows of the placeholder option, until a row is typed
tiptap-diagram-input-errorIn the Quick Input, below the text: why confirming failed, with role="alert", until the user changes the text, the type or the delimiter (Quick Input)

Data attributes

Data attributes carry an element's state, such as .tiptap-chart[data-tt-chart-state='error'].

On a chart

On .tiptap-chart:

AttributeValues
data-tt-chart-typeThe chart's spec.type, such as line or bar, or a type you registered
data-tt-chart-rendererThe id of the Renderer that draws it
data-tt-chart-stateidle (with the layout 'table'), empty, loading, ready, unavailable, error
data-tt-chart-sourcenone, linked, detached
data-tt-chart-readonlyPresent while the data is read-only
data-tt-chart-legendtop, right, bottom, left, none
data-tt-chart-selectedPresent while the chart is selected
data-tt-chart-zoomfit, or the zoom factor, such as 1.5
data-tt-chart-maximizedPresent while the chart is laid over the window
data-tt-chart-borderPresent while the spec or its style has border: true
data-tt-chart-hiddenPresent while only the table the chart follows is shown
data-tt-chart-panningPresent while the user drags the zoomed chart
data-tt-chart-sizedPresent while the spec has a size
data-tt-chart-alignleft or right for a chart with a size that is not centered
data-tt-chart-resizingPresent while the user drags a handle

On a resize handle

ElementAttributeValues
.tiptap-chart-resize-handledata-tt-chart-resizeleft, right, bottom, bottom-left, bottom-right

On the Quick Input

On .tiptap-diagram-input:

AttributeValues
data-tt-diagram-input-typeThe chart type the Quick Input becomes
data-tt-chart-delimitercomma, semicolon, pipe, tab, none: the delimiter, set with setDiagramInputDelimiter or detected
data-tt-chart-placeholderWhile the Quick Input is empty: the text of the placeholder option, which the extension's CSS shows
data-tt-diagram-input-errorAfter confirming failed, until the user changes the text, the type or the delimiter: the message, such as Line 3: "many" is not a number., with aria-invalid="true"

In the HTML output and on other nodes

getHTML() writes a chart as figure[data-type="chart"], with data-tt-chart-type, hidden for a hidden chart, and these attributes:

AttributeValue
data-tt-chart-specThe Chart Spec as JSON
data-tt-chart-linkThe Data Source as JSON
data-tt-chart-synced-atWhen the data was last read from its Data Source, as ISO
data-tt-chart-rendererThe chosen Renderer
data-tt-chart-delimiterThe delimiter the data was typed with

Other elements carry these attributes:

AttributeElement
data-tt-diagram-inputA table used as a chart's input
data-tt-chart-table-idA table that a chart follows
data-tt-chart-image-sourceAn image made by convertChartToImage with keepData, from its chartSource attribute
data-tt-attributionThe <a> in an exported SVG, when the Renderer asks for an attribution link

Custom properties

Set these properties on .tiptap, or on one chart or diagram, to replace their defaults.

Chart

PropertyDefault
--tt-chart-padding12px
--tt-chart-border1px solid transparent
--tt-chart-radius8px
--tt-chart-backgroundtransparent. A spec's background sets it on that chart
--tt-chart-border-color#d4d4d8, the frame of a chart with border: true
--tt-chart-border-width1px
--tt-chart-caption-color#71717a
--tt-chart-caption-size0.875em
--tt-chart-caption-aligncenter
--tt-chart-text-input-border1px solid #6a00f5, around the field for a chart's text
--tt-chart-text-input-backgroundCanvas, the system's background color
--tt-chart-attribution-color#71717a
--tt-chart-attribution-size0.75em
--tt-chart-aspect-ratio16 / 9. A chart with a size sets it to its ratio
--tt-chart-max-height480px. Not applied to a chart with a size
--tt-chart-widthSet on a chart with a size: its share of the editor's text width, such as 50%
--tt-chart-handle-color#6a00f5, the fill of a resize handle
--tt-chart-handle-border#ffffff
--tt-chart-handle-radius4px
--tt-chart-selected-outline2px solid #6a00f5
--tt-chart-loading-opacity0.5
--tt-chart-error-color#e5484d
--tt-chart-unavailable-color#71717a
--tt-chart-maximized-inset0: the distance of a maximized chart from the window's edges, as for inset
--tt-chart-maximized-z-index50
--tt-chart-maximized-background--tt-chart-background, or Canvas when that is unset

A maximized chart is position: fixed. So if an ancestor of the editor sets transform, filter or contain, the chart is placed relative to that ancestor instead of the window.

Drawing

Every Renderer reads these properties when it draws a chart. Sizes are pixels, with or without px, and other units are not converted. A palette in the Chart Spec overrides the series colors, the colors of the bars or lines, for that chart.

PropertyDefault
--tt-chart-series-1 … --tt-chart-series-8#6a00f5, #00a3a3, #f59e0b, #e5484d, #3b82f6, #16a34a, #d946ef, #64748b
--tt-chart-axis-color#9ca3af
--tt-chart-grid-color#e5e7eb
--tt-chart-label-color#4b5563
--tt-chart-title-color#111827
--tt-chart-font-familyArial, Helvetica, "Liberation Sans", sans-serif
--tt-chart-font-size12px
--tt-chart-title-size16px
--tt-chart-title-weight600
--tt-chart-legend-gap16px
--tt-chart-legend-marker-size10px

Fonts in exports and Word

An exported image can only use fonts installed on the machine that exports it, not a web font the page loaded.

A native Word chart, which exportDocx writes, uses one typeface. Word takes the first family of --tt-chart-font-family that it ships with. A generic family such as sans-serif becomes its Word counterpart. Without either, Word uses the fallbackFont option of exportDocx, 'Arial' by default.

To check a stack before exporting, call wordFontFor from @tiptap-pro/extension-diagrams/core:

import { wordFontFor } from '@tiptap-pro/extension-diagrams/core'

wordFontFor('Inter, Helvetica, sans-serif')
// { typeface: 'Arial', requested: 'Inter', substituted: true }

WORD_FONTS from the same entry lists the families Word ships with.

Quick Input

PropertyDefault
--tt-diagram-input-radius8px
--tt-diagram-input-background#f4f4f5
--tt-diagram-input-colorinherit
--tt-diagram-input-font-familyui-monospace, monospace
--tt-diagram-input-delimiter-color#6a00f5, the caret while a delimiter is detected
--tt-diagram-input-placeholder-color#a1a1aa
--tt-diagram-input-error-color#cd2b31
--tt-diagram-input-placeholder-linesSet on an empty Quick Input to the number of lines of its placeholder
--tt-diagram-input-cell-background#f4f4f5

Highlighted source

Source text is colored in the Quick Input, in a Mermaid diagram's code view, and in any element with the class tiptap-diagram-source, such as a source editor of your own. The sourceHighlighting option turns the colors off in the Quick Input and the code view only.

ClassPartColor propertyLight default
tiptap-diagram-source-keywordThe diagram or chart type, statement words--tt-diagram-source-keyword#1e40af
tiptap-diagram-source-labelLabels in shapes, quotes and the first column--tt-diagram-source-label#3f6212
tiptap-diagram-source-numberNumbers--tt-diagram-source-number#7c2d12
tiptap-diagram-source-operatorArrows, delimiters, brackets, colons--tt-diagram-source-operator#52525b
tiptap-diagram-source-commentComments (%%)--tt-diagram-source-comment#4b4b53

Each dark value is derived as for every default color, and each color has a contrast of 4.5:1 or more against the input background in both schemes. To make one part colorless, set its property to inherit.

Diagrams

A diagram, the flowDiagram node (see Flow diagrams), follows the same pattern as a chart with its own names.

Diagram classes

ClassElement
tiptap-flow-diagramThe root of a diagram, with role="figure" and an aria-label from the description or the title
tiptap-flow-diagram-viewportAround the canvas. The user scrolls inside it while the diagram is zoomed in
tiptap-flow-diagram-zoom-boxBetween the viewport and the canvas. Takes the room of the zoomed diagram
tiptap-flow-diagram-canvasHolds the drawn diagram as an <img>
tiptap-flow-diagram-codeThe source text, shown instead of the drawing while the view is code
tiptap-flow-diagram-captionBelow the diagram: the title
tiptap-flow-diagram-attributionBelow the diagram: the link the Diagram Renderer's rules ask for, hidden while there is none
tiptap-flow-diagram-errorThe message shown when drawing failed
tiptap-flow-diagram-unavailableWhat unavailable returns, when no Renderer here draws the diagram
tiptap-flow-diagram-resize-handleA handle that resizes the selected diagram, with resizable
tiptap-flow-diagram-label-inputThe field a double click opens over a text in a Mermaid diagram, not in draw.io or BPMN (Editing in the diagram)

Diagram data attributes

On .tiptap-flow-diagram:

AttributeValues
data-tt-flow-diagram-formatmermaid, drawio, bpmn, or the id of a format a Diagram Renderer of your own draws
data-tt-flow-diagram-kindA Mermaid kind such as flowchart, or unknown
data-tt-flow-diagram-viewdiagram or code
data-tt-flow-diagram-stateidle (the code view), empty, loading, ready, unavailable, error
data-tt-flow-diagram-rendererThe id of the Diagram Renderer that draws it
data-tt-flow-diagram-selectedPresent while the diagram is selected
data-tt-flow-diagram-zoomfit, or the zoom factor, such as 1.5
data-tt-flow-diagram-maximizedPresent while the diagram is laid over the window
data-tt-flow-diagram-panningPresent while the user drags the zoomed diagram
data-tt-flow-diagram-sizedPresent while the diagram has a size
data-tt-flow-diagram-alignleft or right for a diagram with a size that is not centered
data-tt-flow-diagram-resizingPresent while the user drags a handle

On .tiptap-flow-diagram-resize-handle:

AttributeValues
data-tt-flow-diagram-resizeleft, right, bottom, bottom-left, bottom-right

In HTML, on figure[data-type="flow-diagram"]:

AttributeValue
data-tt-flow-diagram-formatThe format
data-tt-flow-diagram-descriptionThe description
data-tt-flow-diagram-viewcode, while the source is shown
data-tt-flow-diagram-optionsThe options as JSON, when set

Diagram custom properties

PropertyDefault
--tt-flow-diagram-padding12px
--tt-flow-diagram-border1px solid transparent
--tt-flow-diagram-radius8px
--tt-flow-diagram-max-height640px. Not applied to a diagram with a size
--tt-flow-diagram-widthSet on a diagram with a size: its share of the editor's text width
--tt-flow-diagram-aspect-ratioSet on a diagram with a size: its ratio, the shape the drawing fits into
--tt-flow-diagram-handle-color#6a00f5, the fill of a resize handle
--tt-flow-diagram-handle-border#ffffff
--tt-flow-diagram-handle-radius4px
--tt-flow-diagram-code-radius8px
--tt-flow-diagram-code-background#f4f4f5
--tt-flow-diagram-code-colorinherit
--tt-flow-diagram-code-font-familyui-monospace, monospace
--tt-flow-diagram-empty-text"Empty diagram", a CSS string shown while the source is empty
--tt-flow-diagram-caption-color#71717a
--tt-flow-diagram-caption-size0.875em
--tt-flow-diagram-caption-aligncenter
--tt-flow-diagram-attribution-color#71717a
--tt-flow-diagram-attribution-size0.75em
--tt-flow-diagram-loading-opacity0.5
--tt-flow-diagram-error-color#e5484d
--tt-flow-diagram-unavailable-color#71717a
--tt-flow-diagram-selected-outline2px solid #6a00f5
--tt-flow-diagram-label-input-border1px solid #6a00f5, around the field for a diagram's text
--tt-flow-diagram-label-input-backgroundCanvas

A maximized diagram uses --tt-chart-maximized-inset, --tt-chart-maximized-z-index and --tt-chart-maximized-background, so charts and diagrams leave the same room around them.

Diagram drawing

The Diagram Renderer reads these properties when it draws a diagram, and an export reads them too.

PropertyDefault
--tt-flow-diagram-backgroundtransparent
--tt-flow-diagram-node-color#f4eeff, the fill of a node
--tt-flow-diagram-node-border-color#6a00f5
--tt-flow-diagram-text-color#18181b
--tt-flow-diagram-line-color#52525b, edges and arrows
--tt-flow-diagram-group-color#fafafa, the fill of a subgraph or lane
--tt-flow-diagram-note-color#fff8db
--tt-flow-diagram-font-familyArial, Helvetica, "Liberation Sans", sans-serif
--tt-flow-diagram-font-size14px. Pixels only