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 playgroundSelect 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
npm i @ashutoshswamy/smouiUsage
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
More inputs components
- AddressAutocompleteType a street and pick from live suggestions. Lookups wait for a pause, show a spinner and drop stale answers. Picking confirms the full address underneath.
- AvatarPickerPick an avatar from a grid. One accent ring glides to your choice, the big preview swaps on a spring, arrow keys move across the grid and Shuffle rolls a random one.
- AvatarUploadDrop or choose a photo, then frame it under a crop circle. The stage shows the whole photo, the circle shows what you keep, and three live previews follow every move. Drag, zoom or use the arrow keys.
- CheckboxBox squashes on press, fills with the accent and draws its tick in.
- ChipA selectable pill. Selecting it tints it and slides a tick in at the front while the pill grows; an optional close button removes it.
- ColorPickerSaturation field and hue strip with jelly thumbs on springs. Edit the hex, pick a swatch, or use arrow keys.