Raft Design System

Components · Data Display

Markdown

The styled elements a Markdown renderer maps its nodes to — headings, paragraphs, links, lists, quotes, tables, images and task checkboxes — for text people and agents write.

StableAlso called Markdown parts, Rich text, Prose, MarkdownHeading, MarkdownTable
import { Markdown } from "@botiverse/raft-ui";

The Markdown parts style what people and agents write in Markdown: the body of a message, a task's description, an agent's notes. raft-ui exports one part per Markdown element and no parser. Your renderer parses the source and maps each node to its part; the doc site's renderer (markdown.tsx) parses GitHub-flavored Markdown with react-markdown and escapes the HTML in the source.

message-reference/compositions/mixed-long-message

When to use

SituationUse
Text someone wrote in MarkdownThe Markdown parts
A mention, a channel, a thread or a task inside that textThe message's reference parts, not MarkdownLink (MessageItem)
A fenced code blockCodeBlock
A table the product lays out, such as usage or billingTable
Text the product writes: labels, descriptions, empty statesThe component that holds it, or Text
Plain text someone wrote, quoted outside a message (a panel, a dialog)Quote

Anatomy

Each part renders the element of the same name.

  • MarkdownHeading: h1 to h6, from level.
  • MarkdownParagraph: a paragraph. The last one in a block has no space under it.
  • MarkdownLink: a link in running text.
  • MarkdownMark: a highlighted run, for a search hit.
  • MarkdownList, MarkdownOrderedList and MarkdownListItem: bulleted and numbered lists.
  • MarkdownCheckbox: the box of a task-list item (- [x]). A read-only Checkbox.
  • MarkdownBlockquote: a quote.
  • MarkdownRule: a thematic break.
  • MarkdownImage: an image, on a transparency checkerboard.
  • MarkdownInlineCode: code inside a sentence (InlineCode), at the size of the text around it.
  • MarkdownTableScroll, MarkdownTable, MarkdownTableRow, MarkdownHeaderCell and MarkdownCell: a table. MarkdownTableScroll is the container: a horizontal ScrollArea that scrolls sideways when the table is wider than the text, with the thin overlay scrollbar shown while the pointer is over it. It is Table's TableScroll in Markdown's frame, and takes ScrollArea's props but orientation.
ElementLooks
Headings 1 to 3text-title, text-headline and text-subhead, bold
Headings 4 to 6text-footnote, bold, in foreground-muted
Linkforeground-link with a 2px underline at 40%, the one clickable text underlined at rest (Clickable text): the link blue alone is 2.32:1 against foreground in light mode and 1.98:1 in dark mode, below 3:1. On hover the underline is full color and the text moves 20% toward the body ink, darker in light mode and lighter in dark mode, so its contrast with the paper goes up in both
Search hitA yellow fill, no edge, the text's own weight; the same as MessageItemSearchMatch
QuoteA 2px bar on the left, the same as Quote's, foreground-muted text
RuleA line-hairline
TableA line-hairline outline and dividers, radius-container; the header row on fill-muted (Built from existing parts)
ImageA line-hairline outline, radius-container, at most the width of the text

Behavior

  • The parts add no width of their own: text wraps to its container, and a long table scrolls inside MarkdownTableScroll instead of widening the message.
  • A wide table scrolls sideways only: a scroll that reaches its side stops there (no swipe back through history), and scrolling down over it scrolls the message list as usual. While it has something to scroll it is a tab stop, so the keyboard can scroll it too.
  • A task-list checkbox shows the state written in the source. People can't change it from the rendered text.

Content

  • Render what the author wrote, including Chinese text and emoji, as body text: emoji are content, not icons (Iconography).

Accessibility

  • The parts are plain HTML elements, so headings, lists, quotes and tables keep their native semantics.
  • MarkdownLink shows focus-ring on keyboard focus.
  • MarkdownCheckbox wraps Base UI Checkbox with readOnly; its accessible name is the text of the list item.
  • Pass the image's alt text from the source to MarkdownImage.

Rules

  • Escape or sanitize HTML in the source before rendering: Markdown people write must not inject markup.
  • Wrap every MarkdownTable in MarkdownTableScroll, so a wide table scrolls instead of overflowing the message.
  • Render fenced code as a CodeBlock, not as a styled pre.
  • Mark a search hit with MarkdownMark, not with bold or a color of your own: a hit looks the same in message text, Markdown and search results (Color).

API

MarkdownBlockquote, MarkdownCell

Takes the attributes of its element.

MarkdownCheckbox

Task-list checkbox. Markdown task items are display-only, so it defaults to read-only.
PropTypeDefault
shape"circle" | "square"
checkedWhether the checkbox is currently ticked.booleanundefined
defaultCheckedWhether the checkbox is initially ticked.booleanfalse
disabledWhether the component should ignore user interaction.booleanfalse
formIdentifies the form that owns the hidden input. Useful when the checkbox is rendered outside the form.string
idThe id of the input element.string
indeterminateWhether the checkbox is in a mixed state: neither ticked, nor unticked.booleanfalse
inputRefA ref to access the hidden `<input>` element.((instance: HTMLInputElement | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<HTMLInputElement | null>
nameIdentifies the field when a form is submitted.stringundefined
nativeButtonWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button.booleanfalse
onCheckedChangeEvent handler called when the checkbox is ticked or unticked.(checked: boolean, eventDetails: CheckboxRootChangeEventDetails) => void
parentWhether the checkbox controls a group of child checkboxes.booleanfalse
readOnlyWhether the user should be unable to tick or untick the checkbox.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
requiredWhether the user must tick the checkbox before submitting a form.booleanfalse
uncheckedValueThe value submitted with the form when the checkbox is unchecked. By default, unchecked checkboxes do not submit any value, matching native checkbox behavior.string
valueThe checkbox's value. Identifies it within a [Checkbox Group](https://base-ui.com/react/components/checkbox-group), falling back to `name` when omitted. When submitting a form, a checked box submits `value`; with no `value`, it submits the native "on".string

Also takes the attributes of its element.

MarkdownHeaderCell

Takes the attributes of its element.

MarkdownHeading

PropTypeDefault
level (required)1 | 2 | 3 | 4 | 5 | 6

Also takes the attributes of its element.

MarkdownImage

Takes the attributes of its element.

MarkdownInlineCode

PropTypeDefault
appearance`message` renders the borderless, baseline-aligned in-message treatment."default" | "message"

Also takes the attributes of its element.

Takes the attributes of its element.

MarkdownTableScroll

Table's `TableScroll` (a horizontal ScrollArea for a wide table, with its thin overlay scrollbar) under Markdown's own slot name and in Markdown's frame. It only overflows sideways, so it never holds back the page's vertical scroll.
PropTypeDefault
actionsRefMethods to scroll from code that the container doesn't have natively.((instance: ScrollAreaActions | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<ScrollAreaActions | null>
childrenThe scrolling content, in ScrollArea's own container.ReactNode
contentClassNameClass of a content element around `children`, inside the container: put padding and the content's own layout (grid, flex, `gap`, `stack-y-*`) here, so the scrollbars stay at the edges and the gutters layer is never one of the laid-out children. Only with it, `contentStyle` or `fade` is there one.string
contentRefAn element whose size is the content's, watched for size changes (such as a hidden mirror of a textarea's text). Without it each element child of the container is watched, and children added or removed.RefObject<HTMLElement | null>
contentStyleStyle of the content element; renders it, as `contentClassName` does.CSSProperties
fadeFade the content out toward an edge that has more past it. The scrollbars don't fade.boolean
hideDelayHow long the scrollbars stay after scrolling stops, in ms. At least 100 with `trigger="scroll"`.number
onEdgeChangeCalled when the area reaches or leaves an edge, and after mounting when the content overflows.(edges: ScrollAreaEdges) => void
onScrollThe container's scroll events.UIEventHandler<HTMLDivElement>
overscrollWhat a scroll that reaches the end does: stop there with no bounce (`none`, the default), stop there but let Mac trackpads and iOS bounce the area (`contain`), or carry on to the page behind (`auto`, which leaves the container's own `overscroll-behavior` alone). Only in the directions the area overflows right now.ScrollAreaOverscroll
railInsetRoom in px the scrollbars keep clear at each end, such as a sticky header's height, so they don't run over it. Also settable in CSS, on the root: `--r-scroll-area-rail-inset-{top,bottom,left,right}`, which don't inherit.ScrollAreaRailInset
renderAnother element in place of ScrollArea's own `<div>`, as the container (an element or a function that gets the props). It must hold children: the gutters are its first child.ReactElement | ((props, state) => ReactElement)
sizeThumb thickness: `small` is 5px, `medium` 7px; both grow while pointed at or dragged.ScrollAreaSize
tabIndexThe container's: by default `0` while there is something to scroll.number
triggerWhen the scrollbars show. They always show while scrolling or dragging.ScrollAreaTrigger

Also takes the attributes of its element.

Changes

  • 0.60.0 · ChangedMessageList, SidebarContent, MarkdownTableScroll and the composer's attachment row: built on the new ScrollArea, so they show the same thin overlay scrollbar. MarkdownTableScroll takes ScrollArea's props except orientation.
  • 0.35.0 · ChangedA search hit (searchHit: MessageItemSearchMatch, MarkdownMark, SearchMessageResultMatch) is a you fill with ink type, in the surrounding weight, with no ink ring, and 1px of fill above and below so descenders stay inside it. A mention of you keeps its sticker.