Rich Text Parameter Utilities
Rich text parameters store structured content with formatting (headings, lists, links, bold, italic, etc.) managed through the Uniform rich text editor. The SDK provides the UniformRichText component and the @uniformdev/richtext package for working with rich text data.
Rendering rich text with UniformRichText#
The UniformRichText component renders rich text parameters with full formatting support and inline editing capabilities in the Uniform visual editor:
UniformRichText props#
| Prop | Type | Default | Description |
|---|---|---|---|
component | Pick<ComponentContext, '_id'> | required | Component context (from ComponentProps) |
parameter | ComponentParameter<ParameterRichTextValue> | required | The rich text parameter value |
as | React.ElementType | "div" | Wrapper HTML element. Set to null for no wrapper. |
className | string | — | CSS class applied to the wrapper |
placeholder | string | ((parameter) => string) | — | Placeholder text shown in the editor when empty |
resolveRichTextRenderer | RenderRichTextComponentResolver | — | Custom renderer for rich text nodes |
The RenderRichTextComponentResolver type is not exported from the public API, so you cannot import it directly. It has the shape (node: RichTextNode) => RichTextRendererComponent | null | undefined, where returning null or undefined falls back to the default renderer for that node type.
Custom rich text node renderers#
By default, UniformRichText maps rich text nodes to standard HTML elements. You can override the rendering of specific node types using resolveRichTextRenderer:
Default node type mappings#
The SDK provides default renderers for these rich text node types:
| Node Type | Default Rendering |
|---|---|
heading | <h1> through <h6> based on tag level |
paragraph | <p> |
text | Inline text with formatting (bold, italic, underline, etc.) |
link | <a> |
list | <ul> or <ol> |
listitem | <li> |
quote | <blockquote> |
code | <pre><code> |
linebreak | <br> |
table | <table><tbody> |
tablerow | <tr> |
tablecell | <td> or <th> |
asset | <img> or media element |
tab | Tab content wrapper |
Rendering rich text to plain text#
For non-visual use cases (SEO meta descriptions, search indexing, summaries), use renderToText from @uniformdev/richtext:
Rendering rich text to HTML string#
For server-side HTML generation (e.g., RSS feeds, emails), use renderToHtml:
Import reference#
| Export | Package | Description |
|---|---|---|
UniformRichText | @uniformdev/next-app-router/component | React component for rendering rich text |
ParameterRichTextValue | @uniformdev/richtext | Type for rich text parameter values |
renderToText | @uniformdev/richtext | Convert rich text to plain text |
renderToHtml | @uniformdev/richtext | Convert rich text to HTML string |
walkRichTextTree | @uniformdev/richtext | Walk and transform the rich text node tree |
isRichTextValue | @uniformdev/richtext | Type guard for rich text values |
isRichTextValueConsideredEmpty | @uniformdev/richtext | Check if rich text is empty |