New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-mui-richtext

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mui-richtext

Rich text editor component for React with Material-UI, based on React Quill

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

React MUI RichText Editor

A flexible and extensible rich text editor component for React with Material-UI, based on React Quill.

Features

  • 📝 Full-featured WYSIWYG Editor - Based on React Quill with comprehensive formatting options
  • 🖼️ Image Upload & Management - Upload, compress, crop, and manage images
  • 🎨 Material-UI Integration - Seamless integration with Material-UI components
  • ⚙️ Highly Configurable - Extensive configuration options for customization
  • 🔌 Extensible - Support for custom toolbar items, formats, modules, and render functions
  • 📱 Responsive - Works well on desktop and mobile devices
  • 🎯 TypeScript Support - Full TypeScript definitions included

Installation

npm install react-mui-richtext
# or
yarn add react-mui-richtext

Peer Dependencies

npm install react react-dom @mui/material @mui/icons-material

Note: The following dependencies are automatically installed with this package:

  • react-quill
  • react-easy-crop
  • quill-emoji

CSS Import

You need to import the required CSS files in your application:

import 'react-quill/dist/quill.snow.css';
import 'quill-emoji/dist/quill-emoji.css';

Add these imports in your main entry file (e.g., main.tsx, index.tsx, or App.tsx).

Basic Usage

import React, { useState } from 'react';
import { RichTextEditor } from 'react-mui-richtext';
// Don't forget to import CSS files
import 'react-quill/dist/quill.snow.css';
import 'quill-emoji/dist/quill-emoji.css';

function App() {
  const [content, setContent] = useState('');

  return (
    <RichTextEditor
      name="editor"
      value={content}
      onChange={setContent}
      placeholder="Start typing..."
    />
  );
}

Props

Basic Props

PropTypeDefaultDescription
namestringrequiredField name for the editor
valuestringrequiredHTML content value
onChange(value: string) => voidrequiredCallback when content changes
onBlur() => void-Callback when editor loses focus
disabledbooleanfalseDisable the editor
placeholderstring''Placeholder text
rowsnumber10Number of rows (affects height)
heightstring | number-Custom height (overrides rows)
errorbooleanfalseShow error state

Image Upload Props

PropTypeDefaultDescription
allowImageUploadbooleantrueEnable image upload button
maxImageSizenumber2097152 (2MB)Maximum image size in bytes
maxImageCountnumber5Maximum number of images
enableImageCompressbooleantrueEnable automatic image compression
maxImageWidthnumber1920Maximum image width in pixels
maxImageHeightnumber1080Maximum image height in pixels
imageQualitynumber0.8Image quality (0-1)
enableImageCropbooleantrueEnable image cropping before upload
cropAspectRationumber-Fixed aspect ratio for cropping (e.g., 210/297 for A4)
allowOriginalImageUploadbooleanfalseEnable original size image upload button

Feature Props

PropTypeDefaultDescription
allowEmojibooleantrueEnable emoji picker

Extension Props

PropTypeDefaultDescription
configRichTextEditorConfig{}Configuration object (see below)
renderToolbar(defaultToolbar: ReactNode) => ReactNode-Custom toolbar renderer
renderCropDialog(props: CropDialogProps) => ReactNode-Custom crop dialog renderer

Configuration Object

The config prop allows you to customize various aspects of the editor:

interface RichTextEditorConfig {
  // Alert function for notifications
  handleAlert?: (message: string, type?: 'success' | 'error' | 'warning' | 'info') => void;
  
  // Custom LoadingButton component
  LoadingButton?: React.ComponentType<LoadingButtonProps>;
  
  // Custom toolbar items
  customToolbarItems?: ToolbarItem[];
  
  // Custom formats
  customFormats?: string[];
  
  // Custom modules
  customModules?: Record<string, any>;
  
  // Custom styles
  customStyles?: RichTextEditorStyles;
}

Example with Configuration

import { RichTextEditor, RichTextEditorConfig } from 'react-mui-richtext';
import { useSnackbar } from 'notistack';
import { LoadingButton } from '@mui/lab';

function MyEditor() {
  const { enqueueSnackbar } = useSnackbar();
  
  const config: RichTextEditorConfig = {
    handleAlert: (message, type = 'info') => {
      enqueueSnackbar(message, { variant: type });
    },
    LoadingButton: LoadingButton,
    customStyles: {
      container: {
        '& .ql-toolbar': {
          backgroundColor: '#f5f5f5',
        },
      },
    },
  };

  return (
    <RichTextEditor
      name="editor"
      value={content}
      onChange={setContent}
      config={config}
    />
  );
}

Advanced Usage

Custom Toolbar

<RichTextEditor
  name="editor"
  value={content}
  onChange={setContent}
  renderToolbar={(defaultToolbar) => (
    <Box>
      {defaultToolbar}
      <Button onClick={handleCustomAction}>Custom Action</Button>
    </Box>
  )}
/>

Custom Crop Dialog

<RichTextEditor
  name="editor"
  value={content}
  onChange={setContent}
  renderCropDialog={(props) => (
    <CustomCropDialog {...props} />
  )}
/>

A4 Aspect Ratio Cropping

<RichTextEditor
  name="editor"
  value={content}
  onChange={setContent}
  enableImageCrop={true}
  cropAspectRatio={210 / 297} // A4 size
/>

Disable Image Upload

<RichTextEditor
  name="editor"
  value={content}
  onChange={setContent}
  allowImageUpload={false}
/>

Styling

The component uses Material-UI's sx prop for styling. You can customize styles through the config.customStyles prop:

const config = {
  customStyles: {
    container: {
      '& .ql-toolbar': {
        backgroundColor: '#fafafa',
        border: '1px solid #e0e0e0',
      },
      '& .ql-editor': {
        minHeight: '300px',
      },
    },
  },
};

Image Compression

The editor automatically compresses images that exceed the size limit or are larger than 500KB. Compression maintains aspect ratio and reduces quality until the image fits within the size limit.

Image Cropping

When enableImageCrop is enabled, users can:

  • Drag to move the crop box
  • Resize the crop box by dragging corners/edges
  • Adjust zoom level
  • Rotate the image
  • Set fixed aspect ratio (if cropAspectRatio is provided)

TypeScript

Full TypeScript support is included. Import types as needed:

import type {
  RichTextEditorProps,
  RichTextEditorConfig,
  CropDialogProps,
  LoadingButtonProps,
} from 'react-mui-richtext';

License

MIT

Keywords

react

FAQs

Package last updated on 30 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts