import React from 'react'; import { resolveStackableColor } from '../../utils'; import { JsonRte } from '../../utils/jsonRte'; import type { CslpTag, StackableColorValue } from '../../types'; export interface RichTextBlockProps { className?: string; /** * The text: a Contentstack JSON rich-text document, as a JSON RTE field * delivers it. An HTML string (an HTML RTE field) also renders. */ content?: unknown; /** How the text lines up inside its column. The column itself is always centered on the page. */ alignment?: 'Left' | 'Center' | string; /** How long a line of text may run: Narrow reads best for long passages. */ column_width?: 'Narrow' | 'Medium' | 'Wide' | string; /** Unset leaves the section transparent, on the page's own background. */ background_color?: StackableColorValue; /** Unset inherits the page's text color. */ text_color?: StackableColorValue; /** Contentstack Live Preview edit tags, one per editable field. See `CslpTag`. */ $?: { content?: CslpTag; }; } const COLUMN_MAX: Record = { Narrow: '40rem', Medium: '48rem', Wide: '64rem' }; /** * A built-in page-builder block: free-form rich text — headings, paragraphs, * lists, links, quotes, tables and embedded images — in the page's own fonts. * Not listed in the component catalog; added from the builder's Basic blocks. */ export function RichTextBlock({ className = '', content, alignment = 'Left', column_width = 'Medium', background_color, text_color, $, }: RichTextBlockProps) { const bg = resolveStackableColor(background_color); const text = resolveStackableColor(text_color); const centered = alignment === 'Center'; const isHtml = typeof content === 'string'; if (!content || (isHtml && !content.trim())) return null; return (
{isHtml ? undefined : }
); } export default RichTextBlock;