UNPKG

@ryzeup/richtexteditor

Version:

A React Rich Text Editor component

221 lines (151 loc) β€’ 5.68 kB
# πŸ“ texteditor β€” A Modern React Rich Text Editor ![NPM Version](https://img.shields.io/npm/v/texteditor.svg?style=flat&color=blue) ![License](https://img.shields.io/npm/l/texteditor.svg?style=flat&color=green) ![Build](https://img.shields.io/badge/build-passing-brightgreen.svg) ![Vite](https://img.shields.io/badge/bundler-vite-orange.svg) ![TypeScript](https://img.shields.io/badge/language-typescript-blue.svg) > ✨ A lightweight, fully customizable **Rich Text Editor for React** β€” built with **TypeScript**, **Vite**, and **React 19**. > Create visually appealing messages with custom fonts, colors, media, and more β€” in just a few lines of code. --- ## πŸš€ Features βœ… Built with **React + TypeScript** βœ… Bundled using **Vite** (super fast builds) βœ… Customizable toolbar β€” bold, italic, underline, color, alignment, etc. βœ… Supports **images**, **links**, **videos**, and **emojis** βœ… Includes **TypeScript types** βœ… CSS bundled or importable separately βœ… Lightweight & dependency-minimal βœ… Plug-and-play usage --- ## πŸ“¦ Installation ```bash # Using npm npm install @ryzeup/richtexteditor # Or yarn yarn add @ryzeup/richtexteditor # Or pnpm pnpm add @ryzeup/richtexteditor --- ## βš™οΈ Peer Dependencies Make sure your project includes React: npm install react react-dom --- ## 🧩 Usage 1️⃣ Import the component import React from 'react'; import { RichTextEditor } from 'texteditor'; import 'texteditor/dist/style.css'; // import styles if not auto-bundled 2️⃣ Use it in your app function App() { return ( <RichTextEditor atSuggestions={["@Arshad", "@Irfan", "@Meera"]} showOutput={true} showPreview={true} toolbarConfig={{ link: true, image: true, emoji: true, table: true, color: true, fontFamily: true, fontSize: true, }} /> ); } export default App; --- ## 🧠 Props Reference The RichTextEditor component is fully customizable via the following props: Prop Type Default Description atSuggestions string[] [] List of mention suggestions (e.g., ["@Arshad", "@Irfan", "@Meera""]). When the user types β€œ@”, a popup appears showing these names. showOutput boolean false Displays a live HTML preview of the editor’s content below the editor box. Useful for debugging or data preview. showPreview boolean false Displays a rendered HTML preview beside the editor (using <RtePreview />). toolbarConfig ToolbarConfig All false Controls which toolbar actions are visible. Example: { link: true, image: true, emoji: true }. classNames { wrapper?: string; toolbar?: string; editor?: string; preview?: string; output?: string } {} Custom class names for different sections of the editor (useful for applying your own CSS). styles { wrapper?: React.CSSProperties; toolbar?: React.CSSProperties; editor?: React.CSSProperties; preview?: React.CSSProperties; output?: React.CSSProperties } {} Inline styles for each section (wrapper, toolbar, editor, etc.). handleGetHtml (html: string) => void () => {} Callback triggered whenever the editor’s HTML content changes. Returns sanitized HTML. --- ### 🧰 ToolbarConfig Type You can control toolbar buttons selectively via this object: Key Type Default Description link boolean false Enables inserting hyperlinks. image boolean false Enables inserting images (from local files). emoji boolean false Enables emoji picker. table boolean false Enables inserting and resizing tables. color boolean false Enables text color picker. fontFamily boolean false Enables font family dropdown. fontSize boolean false Enables font size dropdown. --- ## 🧰 Build & Development If you cloned or downloaded this repository, use the following scripts: # Install dependencies npm install # Start dev server npm run dev # Build the library (for npm publish) npm run build # Lint code npm run lint # Preview the build npm run preview The build will output into the dist/ folder: dist/ β”œβ”€β”€ index.js (CommonJS build) β”œβ”€β”€ index.esm.js (ES Module build) β”œβ”€β”€ index.d.ts (TypeScript types) └── style.css (Editor styles) --- ## πŸ—‚ Folder Structure texteditor/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ components/ β”‚ β”‚ β”œβ”€β”€ RteToolbar.tsx β”‚ β”‚ β”œβ”€β”€ RtePreview.tsx β”‚ β”‚ β”œβ”€β”€ ... β”‚ β”œβ”€β”€ data/ β”‚ β”‚ └── emojis.json β”‚ β”œβ”€β”€ RichTextEditor.tsx β”‚ β”œβ”€β”€ index.ts β”‚ └── style.css β”œβ”€β”€ dist/ β”‚ β”œβ”€β”€ index.js β”‚ β”œβ”€β”€ index.esm.js β”‚ └── style.css β”œβ”€β”€ package.json β”œβ”€β”€ tsconfig.json β”œβ”€β”€ vite.config.ts └── README.md --- ## βš’οΈ Tech Stack React 19 TypeScript Vite 7 ESLint React Icons Rollup (via Vite) for library bundling --- ## 🎨 Styling Option 1 – Manual Import If your build does not automatically include styles: import 'texteditor/dist/style.css'; Option 2 – Automatic Bundling If you import your CSS in src/index.ts: import './style.css'; Vite will automatically bundle your styles in the JS build. --- ## πŸ§ͺ Example Output --- ## πŸ›  Troubleshooting Issue Solution CSS not applied import "../node_modules/@ryzeup/richtexteditor/dist/richtexteditor.css" Cannot find module '../data/emojis.json' Add "resolveJsonModule": true to tsconfig.json TypeScript import error (.tsx) Remove .tsx from imports (use import App from './App') Toolbar icons missing Ensure react-icons is installed --- 🧾 License This project is licensed under the MIT License β€” free for personal and commercial use. πŸ’¬ Author - Ryzeup team πŸ‘¨β€πŸ’» Ryzeup ```