Synertech Web/ui v0.57.5 Site Storybook

Documentation / Feedback & overlays

MarkdownEditor

Client@synertech/ui/markdown-editor

A WYSIWYG Markdown editor (built on @mdxeditor/editor) with a toolbar: undo / redo, block type, bold, italic, underline, code, link, lists and divider. It ships from a separate entry, @synertech/ui/markdown-editor, because @mdxeditor/editor is an optional peer dependency: install it (pnpm add @mdxeditor/editor) before importing it. The main entry never references it, so applications that do not edit Markdown have nothing to install.

Its primary use is the markdownEditor prop of HelpButton, but it also works on its own: value sets the initial content and onChange receives the Markdown on every keystroke. A "use client" component.

Examples

Standalone editor

onChange returns the generated Markdown; here it is shown raw below the editor.

Open in a tab
import { useState } from "react";
import { MarkdownEditor } from "@synertech/ui/markdown-editor";

export function Standalone() {
  const [markdown, setMarkdown] = useState("## Notes de version\n\n- Export **CSV** des factures");

  return (
    <div className="space-y-3">
      <MarkdownEditor value={markdown} onChange={setMarkdown} />
      <pre className="rounded-md bg-gray-100 p-3 text-xs text-gray-800 dark:bg-gray-800 dark:text-gray-200">
        {markdown}
      </pre>
    </div>
  );
}

Placeholder text

placeholder is shown while the document is empty.

Open in a tab
import { useState } from "react";
import { MarkdownEditor } from "@synertech/ui/markdown-editor";

export function Placeholder() {
  const [markdown, setMarkdown] = useState("");

  return (
    <MarkdownEditor value={markdown} onChange={setMarkdown} placeholder="Décrivez le ticket…" />
  );
}

In an editable HelpButton

With markdown and editable, the popup’s pencil opens this editor instead of a text area.

Open in a tab
import { useState } from "react";
import { HelpButton } from "@synertech/ui";
import { MarkdownEditor } from "@synertech/ui/markdown-editor";

export function InHelpButton() {
  const [help, setHelp] = useState("**Astuce :** glissez un fichier sur la zone pour l’importer.");

  return (
    <HelpButton
      markdown
      editable
      width="xl"
      title="Importer des fichiers"
      content={help}
      markdownEditor={MarkdownEditor}
      onSave={(content) => {
        setHelp(content);
        return true;
      }}
    />
  );
}

API reference

Components

MarkdownEditor

ComponentClient

Markdown editor for <HelpButton markdown editable>.

Published from @synertech/ui/markdown-editor, never from the main entry. @mdxeditor/editor is an optional peer dependency, and bundlers resolve any reference to it at build time — even a dynamic import() — so reaching it from the main entry breaks the build of every app that did not install it.

import { MarkdownEditor } from "@synertech/ui/markdown-editor";

Props — MarkdownEditorProps

PropTypeDefaultDescription
onChange• (markdown: string) => void —
value• string —
placeholder string —

+ 2 inherited native attributes from RefAttributes, Attributes (className, id, aria-*, event handlers…).