minimal-wysiwyg-editor
v0.1.0
Published
A minimal React WYSIWYG editor component with basic formatting and inserts.
Maintainers
Readme
minimal-wysiwyg-editor
A minimal React WYSIWYG editor component that uses a native contentEditable surface with a tiny toolbar.
Features:
- Bold, Italic, Underline, Strikethrough
- Bullet list (
ulwithli) - Checkbox insertion
- Image insertion (URL or custom picker)
- Link creation
Install
npm i minimal-wysiwyg-editorPeer deps:
reactandreact-dom(v17+)
Usage
import React, { useState } from "react";
import { MinimalEditor } from "minimal-wysiwyg-editor";
export default function App() {
const [html, setHtml] = useState("");
return (
<div style={{ maxWidth: 640, margin: "40px auto" }}>
<MinimalEditor
value={html}
onChange={setHtml}
placeholder="Type here..."
/>
<h3>Output</h3>
<div dangerouslySetInnerHTML={{ __html: html }} />
</div>
);
}API
<MinimalEditor /> props:
value?: stringinitial/controlled HTMLonChange?: (html: string) => voidcalled on input/blur with HTMLplaceholder?: stringplaceholder text when emptyclassName?: stringwrapper classstyle?: React.CSSPropertieswrapper inline stylesonImagePick?: () => Promise<string|null> | string | nullcustom image URL provider
Ref:
getHTML(): stringsetHTML(html: string): voidfocus(): void
Notes
- The editor uses
document.execCommandfor formatting and inserts. While deprecated, it remains widely supported for basic operations and keeps this package dependency-free. - If you persist user-generated HTML, you should sanitize it before storing or rendering to avoid XSS. This package does not include a sanitizer to remain minimal.
Build
npm run buildOutputs ESM/CJS builds with type declarations into dist/.
