Skip to Content

Rich Text Editor

A Tiptap editor with a toolbar and @mentions whose value is markdown.

import { useState } from "react"
import { RichTextEditor } from "@dapplelight/signet-ui/components/rich-text-editor"

export function Demo() {
  const [note, setNote] = useState("Follow up with **Acme Corp** about the renewal.")
  return (
    <RichTextEditor
      value={note}
      onValueChange={setNote}
      aria-label="Account note"
      placeholder="Write a note"
    />
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  RichTextContent,
  RichTextEditor,
} from "@dapplelight/signet-ui/components/rich-text-editor"
import { useState } from "react"

const [note, setNote] = useState("")

<RichTextEditor value={note} onValueChange={setNote} aria-label="Account note" />

Needs the optional peers @tiptap/react, @tiptap/pm, @tiptap/starter-kit, @tiptap/extension-mention and @tiptap/extension-link. Mentions are stored as @[Name](user:id).

Examples

Mentions

import { RichTextEditor, RichTextPerson } from "@dapplelight/signet-ui/components/rich-text-editor"

const team: RichTextPerson[] = [
  { id: "u_1", name: "Priya Shah" },
  { id: "u_2", name: "Marcus Lee" },
  { id: "u_3", name: "Dana Ortiz" },
]

<RichTextEditor
  aria-label="Comment"
  placeholder="Type @ to mention a teammate"
  onMentionSearch={(q) =>
    team.filter((p) => p.name.toLowerCase().includes(q.toLowerCase()))
  }
/>

Fewer toolbar buttons

import { RichTextEditor } from "@dapplelight/signet-ui/components/rich-text-editor"

<RichTextEditor
  aria-label="Short reply"
  formats={["bold", "italic", "link"]}
  defaultValue="Thanks, the *refund* is on its way."
/>

Rendering stored text

Release notes

  • Faster invoice export
  • Fixed null totals
import { useState } from "react"
import { RichTextContent, RichTextEditor } from "@dapplelight/signet-ui/components/rich-text-editor"

const [value, setValue] = useState("")

<RichTextEditor value={value} onValueChange={setValue} aria-label="Release notes" />

<RichTextContent value={value} />

Disabled

import { RichTextEditor } from "@dapplelight/signet-ui/components/rich-text-editor"

<RichTextEditor disabled aria-label="Archived note" defaultValue="This ticket is closed." />

API Reference

RichTextEditor

PropTypeDefaultDescription
valuestring-Markdown. Controlled with onValueChange.
defaultValuestring""Initial markdown when uncontrolled.
onValueChange(markdown: string) => void-Called with the new markdown on every edit.
onMentionSearch(query: string) => Promise<RichTextPerson[]> | RichTextPerson[]-People matching the query. Leave out to turn mentions off.
onRequestLink(current: string) => Promise<string | null> | string | nullwindow.promptAsk for a link address. Unsafe addresses are ignored.
formatsreadonly RichTextFormat[]allToolbar buttons, in order: bold, italic, code, link, h2, h3, ul, ol.
placeholderstring-Hint shown while empty.
disabledbooleanfalseMake the editor read-only.
labelsPartial<RichTextLabels>-Override toolbar and mention strings.
iconsPartial<Record<RichTextFormat, ReactNode>>-Replace a button's content. The label stays its accessible name.
classNamestring-Class on the root.
classNamesPartial<Record<Part, string>>-Class per part: root, toolbar, button, content, mentions, option.
idstring-Id of the editable area.
aria-labelstring-Accessible name of the editor.

RichTextContent

PropTypeDefaultDescription
valuestring-Stored markdown, rendered as safe HTML.
classNamestring-Merged with RICH_TEXT_CLASSES.

RichTextPerson

PropTypeDefaultDescription
idstring-Stored in the mention token.
namestring-Shown in the picker and the mention.
emailstring | null-Optional.