react ~8 KB 0 deps v0.1.0 ↗ GitHub ↗

@mshafiqyajid/react-rich-text

Headless rich text hook and styled component. contentEditable-based WYSIWYG editor. Bold, italic, underline, strikethrough, lists, alignment. No external deps.

Playground #

Props
TSX
import { RichTextStyled } from "@mshafiqyajid/react-rich-text/styled";
import "@mshafiqyajid/react-rich-text/styles.css";

<RichTextStyled
  value={value}
  onChange={setValue}
/>

Install #

npm install @mshafiqyajid/react-rich-text

Quick start #

import { RichTextStyled } from "@mshafiqyajid/react-rich-text/styled";
import "@mshafiqyajid/react-rich-text/styles.css";

const [html, setHtml] = useState("");
<RichTextStyled
  value={html}
  onChange={setHtml}
  placeholder="Write something..."
  tone="primary"
/>

API #

PropTypeDefaultDescription
valuestringControlled HTML string
defaultValuestring""Uncontrolled initial HTML
onChange(html) => voidCalled on content change
placeholderstringPlaceholder text when empty
showToolbarbooleantrueShow formatting toolbar
toolbarItemsToolbarItem[]allWhich toolbar buttons to show
minHeightstring"120px"Minimum editor height
maxHeightstringMaximum editor height (scrolls)
size"sm" | "md" | "lg""md"Font and padding size
tone"neutral" | "primary""neutral"Accent color
disabledbooleanfalseMake editor read-only
onFocus() => voidFocus callback
onBlur() => voidBlur callback
wordCountbooleanfalseShow word/character count
spellCheckbooleantrueEnable spell check
allowedTagsstring[]Allowed HTML tag whitelist
Edit this page on GitHub