RichTextToolbar

Format actions over a selection. The bar springs up from the middle of what you selected, a nub points at it, each button shows whether its format is on, and it flips below when there is no room above. Inputs.

Open playground
Select some of this text to format it. You can make a word bold, italic, or underlined.

About

RichTextToolbar is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { RichTextToolbar } from "@ashutoshswamy/smoui" and set editorRef, onFormat.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { useRef } from "react";
import { RichTextToolbar } from "@ashutoshswamy/smoui";

function Editor() {
  const editor = useRef<HTMLDivElement>(null);
  return <>
    <div ref={editor} contentEditable suppressContentEditableWarning>Highlight text to format it.</div>
    <RichTextToolbar editorRef={editor} />
  </>;
}

Props 2

editorRef

The contenteditable element containing the selection.

RefObject<HTMLElement | null>
onFormat

Optional command handler; otherwise uses browser formatting.

(format: "bold" | "italic" | "underline") => void