Skip to main content

RichTextEditor Pro

RichTextEditor is a block editor in the style of Notion: every paragraph, heading, list item, to-do, quote, code block, callout, image and divider is its own block. Type / for a menu of blocks, @ to mention someone, or plain Markdown (# , - , [] , **bold**) and it formats as you go. Select text for the toolbar, drag a block by its handle, and undo anything. The value is plain JSON you can store as is, and toMarkdown turns it into GitHub-flavored Markdown. Use it for docs, notes, issue descriptions and long comments; for a quick message, the free TextArea is enough.

React Native's TextInput can't mix styles on its own, and a WebView editor costs a second runtime on every platform, so each block is its own input that draws its marks inside the text as you type (styled text children on iOS and Android, styled text under a transparent text area on the web): real formatting while you write, with React Native core only.

import { RichTextEditor, CommentComposer, toMarkdown, fromMarkdown } from '@patine-ui/pro';
Behaves like
Loading…
<RichTextEditor defaultValue={SPEC} mentions={PEOPLE} showCount style={{ width: '100%', maxWidth: 760 }} />

Try it: select a few words for the toolbar, press Enter at the end of a to-do, type / on an empty line, @ma anywhere, or **word**. Hover a block on the web for its + and drag handle.

Example: a job posting​

A hiring tool's job editor: the posting starts from a template, and the checklist beside it reads the document as you write, so Publish waits for the sections every posting needs.

Behaves like
Loading…
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 16, width: '100%' }}>
  <View style={{ flex: 2, minWidth: 280 }}>
    <RichTextEditor value={doc} onChange={setDoc} placeholder="Describe the role" />
  </View>
  <VStack gap="sm" style={{ flex: 1, minWidth: 200 }}>
    <Text weight="semibold">Before you publish</Text>
    {CHECKS.map((c) => (
      <HStack key={c.label} gap="xs" align="center">
        <Icon name={c.test(md) ? 'checkCircle' : 'alertCircle'} size="sm" color={c.test(md) ? 'success' : 'warning'} />
        <Text size="sm">{c.label}</Text>
      </HStack>
    ))}
    <Text size="sm" color="textSecondary">{words} words · aim for 300 to 700</Text>
    <Button disabled={!ready}>{ready ? 'Publish posting' : 'Add the missing parts'}</Button>
  </VStack>
</View>

Typing​

Markdown typed at the start of a block turns it into another kind; Markdown typed around a word formats it the moment it closes.

TypeBecomes
# , ## , ### Heading 1, 2, 3
- or * Bulleted list
1. Numbered list
[] or [x] To-do
> Quote
```Code block (Enter on an empty last line leaves it)
---Divider
**bold**, *italic*, ~~strike~~, `code`The mark, without the markers

Enter splits a block (a list continues; Enter on an empty item ends the list), Shift+Enter adds a line inside it, Backspace at the start of a block turns it back into text and then joins it to the one above, and Tab and Shift+Tab nest list items. On the web: Cmd/Ctrl+B, I, E (code), K (link), Shift+X (strike), Z and Shift+Z (undo and redo), and the arrow keys move between blocks.

Commands and mentions​

/ opens the block menu wherever a word could start; keep typing to filter it, then pick with the arrows and Enter, or a tap. @ does the same with mentions: people, pages, issues, anything with an id and a label. A mention is one piece in the text, stored with its id ([@Maya Chen](mention:maya) in Markdown), and onMentionPress hears presses on it in read-only mode.

Behaves like
Loading…
<VStack gap="sm" style={{ width: '100%', maxWidth: 560 }}>
  <RichTextEditor
    defaultValue={'Thanks for reporting this! Looping in [@Grace Hopper](mention:u2).\n\nType / or @ here…'}
    mentions={TEAM}
    commands={COMMANDS}
    onMentionPress={(m) => setPressed(m.label)}
  />
  {pressed ? <Text size="sm" color="textSecondary">Pressed {pressed}</Text> : null}
</VStack>

Value and Markdown​

The value is a RichTextDoc: { blocks: [{ id, type, text, marks?, checked?, indent?, language?, url?, tone? }] }. Marks are ranges over a block's plain text ({ type: 'bold', start: 0, end: 4 }), so the JSON stays readable and diffable. Control it with value and onChange, or start from a doc or a Markdown string with defaultValue. toMarkdown(doc) writes GitHub-flavored Markdown (task lists, callouts as > [!NOTE] alerts) and fromMarkdown(markdown) reads it back; pasting Markdown with line breaks into the editor makes blocks too.

Behaves like
Loading…
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 16, width: '100%' }}>
  <View style={{ flex: 1, minWidth: 280 }}>
    <RichTextEditor value={doc} onChange={setDoc} />
  </View>
  <VStack gap="xs" style={{ flex: 1, minWidth: 280 }}>
    <Text size="xs" color="textSecondary">Markdown · {words} words</Text>
    <ScrollView style={{ maxHeight: 260 }}>
      <Text style={{ fontFamily: 'Menlo, monospace', fontSize: 12, lineHeight: 18 }}>{toMarkdown(doc)}</Text>
    </ScrollView>
  </VStack>
</View>

Read-only​

readOnly renders the same document with no inputs: links open (or call onLinkPress), mentions call onMentionPress, and checkboxes show their state. Use it for published docs, comment threads and previews, from the same JSON or Markdown you store.

Behaves like
Loading…
<RichTextEditor readOnly defaultValue={POST} style={{ width: '100%', maxWidth: 640 }} />

Comment composer​

CommentComposer is the editor in a framed box with a toolbar, an attach button and a send button: the comment box of Linear and GitHub. Cmd/Ctrl+Enter sends. onSubmit gets the doc and its Markdown, and the box clears unless it returns false (or a promise of false), so a failed request keeps the text. Put chips or thumbnails in attachments; set allowEmpty to send attachments alone.

Behaves like
Loading…
<VStack gap="lg" style={{ width: '100%', maxWidth: 620 }}>
  {comments.map((c) => <Comment key={c.id} comment={c} />)}
  <CommentComposer
    mentions={PEOPLE}
    onSubmit={send}
    onAttach={() => setFiles((f) => [...f, `screenshot-${f.length + 1}.png`])}
    attachments={files.length ? (
      <HStack gap="xs" style={{ flexWrap: 'wrap' }}>
        {files.map((f) => (
          <View key={f} style={{ paddingHorizontal: 10, paddingVertical: 4, borderRadius: 999, borderWidth: 1, borderColor: 'rgba(127,127,127,0.3)' }}>
            <HStack gap="xs" align="center">
              <Icon name="paperclip" size={12} />
              <Text size="xs">{f}</Text>
            </HStack>
          </View>
        ))}
      </HStack>
    ) : null}
  />
</VStack>

Toolbar​

On the web the toolbar floats over a selection, Notion style; on phones it docks above the keyboard (an input accessory on iOS) while the editor has focus. toolbarMode picks either anywhere. toolbar lists the buttons in order, '|' for a divider, or false for none: bold, italic, strike, code, link, heading1, heading2, bullet, numbered, todo, quote, mention, undo, redo. Each button shows whether its mark or block type is on at the caret. With nothing selected, a mark button applies to what you type next.

Behaves like
Loading…
<RichTextEditor
  defaultValue="Click here: the toolbar under this text stays while the editor has focus."
  toolbarMode="docked"
  toolbar={['bold', 'italic', 'code', 'link', '|', 'bullet', 'numbered', 'quote', '|', 'undo', 'redo']}
  reorderable={false}
  style={{ width: '100%', maxWidth: 560, borderWidth: 1, borderColor: 'rgba(127,127,127,0.25)', borderRadius: 12 }}
/>

Images​

The /image command asks for a URL in a dialog. Pass onPickImage to use your own picker and upload instead: resolve the uploaded URL, or null to cancel. Images keep their aspect ratio and take a caption.

Behaves like
Loading…
<RichTextEditor
  onPickImage={pick}
  defaultValue={'## Moodboard\n\nType /image on the empty line below.\n\n![Morning light on the studio wall](https://picsum.photos/seed/studio/1200/600)'}
  style={{ width: '100%', maxWidth: 640 }}
/>

Accessibility​

  • Every block is a real text input with a name for screen readers (its placeholder: "Heading 1", "To-do"…); headings render with the heading role and level in read-only mode, and to-dos are checkboxes.
  • The toolbar has the toolbar role; its buttons are named with their shortcut on the web ("Bold (⌘B)") and report aria-pressed. The menus are listboxes whose options report aria-selected.
  • Everything works from the keyboard on the web: the menus' arrows, Enter, Tab and Escape, mark shortcuts, Tab to nest lists, arrows between blocks. Blocks also reorder with the keyboard (focus a row, Space, arrows, Space) and with the screen reader's Move up and Move down actions.
  • Touch targets are 44pt with hit slop; the drag handle shows on hover or on the focused block.

Props​

RichTextEditor​

PropTypeDefault
valueRichTextDoc
defaultValueRichTextDoc | string (Markdown)One empty paragraph
onChange(doc) => void, user changes only
readOnlybooleanfalse
placeholderstring, the focused empty paragraph's hint"Type '/' for commands"
mentionsMentionItem[]: { id, label, description?, avatar? }Mentions off
commandsBlockCommand[]BLOCK_COMMANDS
toolbarToolbarItem[] | falseMarks, link, headings, lists, undo, redo
toolbarMode'floating' | 'docked'Floating on the web, docked on phones
toolbarEndReactNode, after the docked toolbar's buttons (it then always shows)
showCountboolean, words and charactersfalse
reorderableboolean, drag handlestrue
onPickImage() => Promise<string | null>A URL dialog
onLinkPress(href) => void, read-onlyOpens http, mailto and tel links
onMentionPress({ id, label }) => void
onSubmit() => void, Cmd/Ctrl+Enter
onFocusChange(focused) => void
autoFocusbooleanfalse
menuPlacement'auto' | 'above''auto'
scrollEnabledboolean, scroll inside a fixed heightfalse (grows)
contentPaddingnumberTheme spacing
labelsPartial<EditorLabels>English
accessibilityLabel, style, testID, theme, design

CommentComposer​

PropTypeDefault
onSubmit(doc, markdown) => boolean | void | Promise<…>; false keeps the text
value, defaultValue, onChangeAs on the editor
placeholderstring'Leave a comment…'
mentionsMentionItem[]
toolbarToolbarItem[]Bold, italic, code, link, lists, mention
onAttach() => void; shows the paperclip
attachmentsReactNode, above the toolbar
allowEmptybooleanfalse
submittingbooleanfalse
submitLabelstring'Comment'
footerStartReactNode, before the attach and send buttons
menuPlacement'auto' | 'above', for a box docked at the bottom of a screen'auto'
autoFocus, disabled, labels, style, testID, theme, design
  • TextArea: plain multi-line text, free.
  • AI Chat: its composer for prompts, and Markdown rendering for replies.
  • Messenger: a chat thread with replies and reactions.