• Stars
    star
    562
  • Rank 79,281 (Top 2 %)
  • Language
    JavaScript
  • Created about 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React component for Froala WYSIWYG HTML Rich Text Editor.

React JS Froala WYSIWYG Editor

npm npm npm

react-froala-wyswiyg provides React bindings to the Froala WYSIWYG editor VERSION 3.

Installation

npm install react-froala-wysiwyg --save

Update editor version

npm update froala-editor

Usage

1. Require and use Froala Editor component inside your application.

import React from 'react';
import ReactDOM from 'react-dom';


// Require Editor CSS files.
import 'froala-editor/css/froala_style.min.css';
import 'froala-editor/css/froala_editor.pkgd.min.css';

import FroalaEditorComponent from 'react-froala-wysiwyg';

// Import all Froala Editor plugins;
// import 'froala-editor/js/plugins.pkgd.min.js';

// Import a single Froala Editor plugin.
// import 'froala-editor/js/plugins/align.min.js';

// Import a language file.
// import 'froala-editor/js/languages/de.js';

// Import a third-party plugin.
// import 'froala-editor/js/third_party/image_tui.min.js';
// import 'froala-editor/js/third_party/embedly.min.js';
// import 'froala-editor/js/third_party/spell_checker.min.js';

// Include font-awesome css if required.
// install using "npm install font-awesome --save"
// import 'font-awesome/css/font-awesome.css';
// import 'froala-editor/js/third_party/font_awesome.min.js';

// Include special components if required.
// import FroalaEditorView from 'react-froala-wysiwyg/FroalaEditorView';
// import FroalaEditorA from 'react-froala-wysiwyg/FroalaEditorA';
// import FroalaEditorButton from 'react-froala-wysiwyg/FroalaEditorButton';
// import FroalaEditorImg from 'react-froala-wysiwyg/FroalaEditorImg';
// import FroalaEditorInput from 'react-froala-wysiwyg/FroalaEditorInput';

// Render Froala Editor component.
ReactDOM.render(<FroalaEditorComponent tag='textarea'/>, document.getElementById('editor'));

Add editor to UI by passing id to html element

<div  id="editor">
</div>

2. Make sure you have the right Webpack settings for loading the CSS files.

Webpack <= 3

var webpack = require("webpack");

module.exports = {
  module: {
    loaders: [
      {
        test: /\.jsx$/,
        loader: 'babel',
        query: {
          cacheDirectory: true,
          presets: ['react','es2015', 'stage-2']
        }
      }, {
        test: /\.css$/,
        loader: "style-loader!css-loader?root=."
      },
      {
        test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=application/font-woff"
      }, {
        test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=application/font-woff"
      }, {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=application/octet-stream"
      }, {
        test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
        loader: "file"
      }, {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=image/svg+xml"
      }
    ]
  },
  resolve: {
    modulesDirectories: ['node_modules']
  }
};

Webpack 4

var webpack = require("webpack");

module.exports = {
  module: {
    rules: [
      {
        test: /\.jsx$/,
        use: {
          loader: 'babel-loader',
          options: {
            cacheDirectory: true,
            presets: ['react','es2015', 'stage-2']
          }
        }
      }, {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
        use: "url-loader?limit=10000&mimetype=application/font-woff"
      }, {
        test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
        use: "url-loader?limit=10000&mimetype=application/font-woff"
      }, {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
        use: "url-loader?limit=10000&mimetype=application/octet-stream"
      }, {
        test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
        use: "file-loader"
      }, {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
        use: "url-loader?limit=10000&mimetype=image/svg+xml"
      }
    ]
  },
  resolve: {
    modules: ['node_modules']
  }
};

Pass properties to the wrapping DOM element

<FroalaEditor
  tag='textarea'
  config={this.config}
  model={this.state.model}
  onModelChange={this.handleModelChange}
/>

tag attr is used to tell on which tag the editor is initialized.

There are special tags: a, button, img, input. Do not use them in FroalaEditor component. To initialize the editor on a special tag, use FroalaEditorA, FroalaEditorButton, FroalaEditorImg and FroalaEditorInput components.

Config

You can pass editor options as component attribute (optional).

config={this.config}

You can pass any existing Froala option. Consult the Froala documentation to view the list of all the available options:

config={{
  placeholderText: 'Edit Your Content Here!',
  charCounterCount: false
}}

Aditional option is used:

  • immediateReactModelUpdate: (default: false) This option updates the React model as soon as a key is released in the editor. Note that it may affect performances.

Events and Methods

Events can be passed in with the options, with a key events and object where the key is the event name and the value is the callback function.

config={{
  placeholder: "Edit Me",
  events : {
    'focus' : function(e, editor) {
      console.log(editor.selection.get());
    }
  }
}}

Using the editor instance from the arguments of the callback you can call editor methods as described in the method docs.

Froala events are described in the events docs.

Custom Buttons

You can pass the custom buttons to the editor by following way:

<script>
import Froalaeditor from 'froala-editor';
Froalaeditor.DefineIcon('alert', {NAME: 'info', SVG_KEY: 'help'});
  Froalaeditor.RegisterCommand('alert', {
    title: 'Hello',
    focus: false,
    undo: false,
    refreshAfterCallback: false,
    callback: function () {
      alert('Hello!');
    }
  });

  Froalaeditor.DefineIcon('clear', {NAME: 'remove', SVG_KEY: 'remove'});
  Froalaeditor.RegisterCommand('clear', {
    title: 'Clear HTML',
    focus: false,
    undo: true,
    refreshAfterCallback: true,
    callback: function () {
      this.html.set('');
      this.events.focus();
    }
  });

  Froalaeditor.DefineIcon('insert', {NAME: 'plus', SVG_KEY: 'add'});
  Froalaeditor.RegisterCommand('insert', {
    title: 'Insert HTML',
    focus: true,
    undo: true,
    refreshAfterCallback: true,
    callback: function () {
      this.html.insert('My New HTML');
    }
  });
  </script>
  

Now you can use these buttons in options:

toolbarButtons: [['undo', 'redo' , 'bold'], ['alert', 'clear', 'insert']],

Model

The WYSIWYG HTML editor content model.

model = {this.state.model}

Two way binding:

import React from 'react';

class EditorComponent extends React.Component {
  constructor () {
    super();

    this.handleModelChange = this.handleModelChange.bind(this);

    this.state = {
      model: 'Example text'
    };
  }

  handleModelChange: function(model) {
    this.setState({
      model: model
    });
  }

  render () {
    return <FroalaEditor
			  model={this.state.model}
			  onModelChange={this.handleModelChange}
           />
  }
}

To achieve one way binding and pass only the initial editor content, simply do not pass onModelChange attribute.

Use the content in other places:

<input value={this.state.model}/>

Special tags

You can also use the editor on img, button, input and a tags:

<FroalaEditorImg
  config={this.config}
/>
<FroalaEditorButton
  config={this.config}
/>
<FroalaEditorInput
  config={this.config}
/>
<FroalaEditorA
  config={this.config}
/>

The model must be an object containing the attributes for your special tags. Example:

constructor () {
  super();

  this.handleModelChange = this.handleModelChange.bind(this);

  this.state = {
    model: {src: 'path/to/image.jpg'}
  };
}
  • The model can contain a special attribute named innerHTML which inserts innerHTML in the element: If you are using 'button' tag, you can specify the button text like this:
this.state = {
  model: {innerHTML: 'Click Me'}
};

As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.

Specific option for special tags

  • reactIgnoreAttrs: (default: null) This option is an array of attributes that you want to ignore when the editor updates the froalaModel:
config: {
 reactIgnoreAttrs: ['class', 'id']
},

Manual Instantiation

Gets the functionality to operate on the editor: create, destroy and get editor instance. Use it if you want to manually initialize the editor.

onManualControllerReady={this.handleManualController}

handleManualController: function(initControls) {
  //...
}

The object received by the function will contain the following methods:

  • initialize: Call this method to initialize the Froala Editor
  • destroy: Call this method to destroy the Froala Editor
  • getEditor: Call this method to retrieve the editor that was created. This method will return null if the editor was not yet created

Using type definition file

index.d.ts file is the type definition file for this repository. It is placed inside lib folder.In order to use it in your code , use the following line:

///<reference path= "index.d.ts" />

where path is the location of index.d.ts file.

Displaying HTML

To display content created with the froala editor use the FroalaEditorView component.

<FroalaEditor
  model={this.state.content}
  onModelChange={this.handleModelChange}
/>
<FroalaEditorView
  model={this.state.content}
/>

License

The react-froala-wyswiyg project is under MIT license. However, in order to use Froala WYSIWYG HTML Editor plugin you should purchase a license for it.

Froala Editor has 3 different licenses for commercial use. For details please see License Agreement.

Development environment setup

If you want to contribute to react-froala-wyswiyg, you will first need to install the required tools to get the project going.

Prerequisites

Install dependencies

$ npm install

Build

$ npm run build

Run Demo

$ npm run demo

More Repositories

1

design-blocks

A set of 170+ Bootstrap based design blocks ready to be used to create clean modern websites.
HTML
13,506
star
2

wysiwyg-editor

The next generation Javascript WYSIWYG HTML Editor.
CSS
5,259
star
3

angular-froala-wysiwyg

Angular 4, 5, 6, 7, 8 and 9 plugin for Froala WYSIWYG HTML Rich Text Editor.
TypeScript
732
star
4

vue-froala-wysiwyg

Vue component for Froala WYSIWYG HTML Rich Text Editor.
JavaScript
632
star
5

wysiwyg-rails

Ruby gem for Froala jQuery WYSIWYG HTML Rich Text Editor.
CSS
465
star
6

angular-froala

Angular.js bindings for Froala WYSIWYG HTML Rich Text Editor.
JavaScript
306
star
7

django-froala-editor

Package to integrate Froala WYSIWYG HTML rich text editor with Django.
CSS
283
star
8

nova-froala-field

A Laravel Nova Froala WYSIWYG Editor Field.
PHP
113
star
9

react-froala-design-blocks

React implementation for Froala Design Blocks.
JavaScript
108
star
10

KMSFroalaEditorBundle

Symfony bundle for Froala WYSIWYG HTML Rich Text Editor.
PHP
105
star
11

yii2-froala-editor

Yii 2 widget for the Froala WYSIWYG HTML Editor.
PHP
103
star
12

meteor-froala

Meteor bindings for the Froala WYSIWYG HTML Editor.
CSS
68
star
13

ember-froala-editor

Ember component for Froala WYSIWYG HTML Rich Text Editor.
JavaScript
68
star
14

vue-froala-design-blocks

Vue JS implementation for Froala Design Blocks.
Vue
60
star
15

design-framework-demo

CSS
59
star
16

wordpress-froala-wysiwyg

Wordpress plugin for Froala WYSIWYG HTML Editor.
CSS
42
star
17

wysiwyg-editor-php-sdk

PHP SDK to ease the integration of Froala WYSIWYG Editor on server side.
PHP
40
star
18

wysiwyg-editor-release

Froala wysiwyg editor release
HTML
30
star
19

wysiwyg-editor-dotnet-sdk

.NET SDK to ease the integration of Froala WYSIWYG Editor on server side.
JavaScript
29
star
20

aurelia-froala-editor

Aurelia plugin for Froala WYSIWYG HTML Rich Text Editor.
JavaScript
28
star
21

ember-froala

[DEPRECATED] Please use https://github.com/froala/ember-froala-editor instead.
JavaScript
28
star
22

angular-froala-design-blocks

Angular implementation for Froala Design Blocks.
HTML
27
star
23

froala-reactive

A Meteor reactive template wrapper around Froala WYSIWYG HTML Editor.
JavaScript
25
star
24

wysiwyg-editor-node-sdk

Node.JS SDK to ease the integration of Froala WYSIWYG Editor on server side.
JavaScript
25
star
25

froala-pages

HTML
21
star
26

wysiwyg-editor-v1

A flat designed jQuery WYSIWYG Rich Text Editor based on HTML5.
JavaScript
21
star
27

wysiwyg-editor-python-sdk

Python SDK to ease the integration of Froala WYSIWYG Editor on server side.
Python
21
star
28

Craft-3-Froala-WYSIWYG

Craft 3 CMS plugin for Froala WYSIWYG HTML Rich Text Editor.
PHP
16
star
29

Craft-Froala-WYSIWYG

Craft CMS plugin for Froala WYSIWYG HTML Rich Text Editor.
JavaScript
16
star
30

wysiwyg-editor-java-sdk

Java SDK to ease the integration of Froala WYSIWYG Editor on server side.
HTML
15
star
31

editor-php-sdk-example

Example for using the Froala Editor PHP SDK
PHP
11
star
32

wysiwyg-cake2

CakePHP Plugin for Froala Javascript WYSIWYG Rich Text Editor.
CSS
11
star
33

knockout-froala

Knockout.js binding for Froala WYSIWYG HTML Rich Text Editor
Shell
10
star
34

wysiwyg-editor-ruby-sdk

Ruby
9
star
35

wysiwyg-cake

CakePHP Plugin for Froala Javascript WYSIWYG Rich Text Editor.
CSS
8
star
36

editor-ruby-sdk-example

Ruby
7
star
37

vue-froalacharts

Simple and lightweight official Vue component for FroalaCharts.
JavaScript
5
star
38

froala-gatsby

JavaScript
3
star
39

froala-editor-nuget

Nuget package for Froala WYSIWYG Editor
3
star
40

angular-froala-systemjs-demo

A quick starter to use angular-froala with system js
TypeScript
2
star
41

froala-image-uploader-example

Sample PHP application demo for Froala Image Uploader
PHP
2
star
42

froalacharts

JavaScript
2
star
43

.github

1
star
44

react-froalacharts-component

Simple and lightweight official React component for FroalaCharts.
JavaScript
1
star
45

ember-froalacharts

Simple and lightweight official Ember component for FroalaCharts.
JavaScript
1
star
46

xt-themes

JavaScript
1
star