Raft 设计系统

组件 · 数据展示

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.

稳定也叫 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

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 and scrolls sideways when the table is wider than the text.
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.75:1 against foreground in light mode and 1.44: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 small yellow sticker, the same as MessageItemSearchMatch
QuoteA 2px bar on the left, 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 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

接受其元素的全部属性。

MarkdownCheckbox

Task-list checkbox. Markdown task items are display-only, so it defaults to read-only.
Prop类型默认值
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

接受其元素的全部属性。

MarkdownHeading

Prop类型默认值
level (required)1 | 2 | 3 | 4 | 5 | 6

Also takes the attributes of its element.

MarkdownImage

接受其元素的全部属性。

MarkdownInlineCode

Prop类型默认值
appearance`message` renders the borderless, baseline-aligned in-message treatment."default" | "message"

Also takes the attributes of its element.

接受其元素的全部属性。