Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-draft-wysiwyg

Package Overview
Dependencies
Maintainers
1
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-draft-wysiwyg

A wysiwyg on top of DraftJS.

  • 1.14.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
218K
decreased by-17.87%
Maintainers
1
Weekly downloads
 
Created

What is react-draft-wysiwyg?

The react-draft-wysiwyg package is a rich text editor component based on Draft.js. It provides a highly customizable and extensible WYSIWYG editor for React applications, allowing developers to integrate text editing capabilities with ease.

What are react-draft-wysiwyg's main functionalities?

Basic Editor

This code demonstrates how to set up a basic editor using react-draft-wysiwyg. The editor includes default toolbar options and basic styling.

import React from 'react';
import { Editor } from 'react-draft-wysiwyg';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';

const MyEditor = () => (
  <Editor
    toolbarClassName="toolbarClassName"
    wrapperClassName="wrapperClassName"
    editorClassName="editorClassName"
  />
);

export default MyEditor;

Custom Toolbar

This code shows how to customize the toolbar of the editor. You can specify which options to include and whether they should be displayed in dropdowns.

import React from 'react';
import { Editor } from 'react-draft-wysiwyg';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';

const MyEditor = () => (
  <Editor
    toolbar={{
      options: ['inline', 'blockType', 'fontSize', 'list', 'textAlign', 'colorPicker', 'link', 'embedded', 'emoji', 'image', 'remove', 'history'],
      inline: { inDropdown: true },
      list: { inDropdown: true },
      textAlign: { inDropdown: true },
      link: { inDropdown: true },
      history: { inDropdown: true },
    }}
  />
);

export default MyEditor;

Controlled Editor

This example demonstrates how to create a controlled editor component. The editor's state is managed using React's useState hook, allowing for more control over the editor's content.

import React, { useState } from 'react';
import { EditorState } from 'draft-js';
import { Editor } from 'react-draft-wysiwyg';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';

const MyEditor = () => {
  const [editorState, setEditorState] = useState(EditorState.createEmpty());

  return (
    <Editor
      editorState={editorState}
      onEditorStateChange={setEditorState}
    />
  );
};

export default MyEditor;

Image Upload

This code sample shows how to handle image uploads in the editor. The uploadImageCallBack function processes the image file and returns a promise with the image URL.

import React, { useState } from 'react';
import { EditorState } from 'draft-js';
import { Editor } from 'react-draft-wysiwyg';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';

const MyEditor = () => {
  const [editorState, setEditorState] = useState(EditorState.createEmpty());

  const uploadImageCallBack = (file) => {
    return new Promise(
      (resolve, reject) => {
        const reader = new FileReader();
        reader.onloadend = () => resolve({ data: { link: reader.result } });
        reader.readAsDataURL(file);
      }
    );
  };

  return (
    <Editor
      editorState={editorState}
      onEditorStateChange={setEditorState}
      toolbar={{
        image: {
          uploadCallback: uploadImageCallBack,
          previewImage: true,
        },
      }}
    />
  );
};

export default MyEditor;

Other packages similar to react-draft-wysiwyg

FAQs

Package last updated on 12 Dec 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc