Giter Club home page Giter Club logo

draft-js-emoji-mart-plugin's Introduction

Emoji-mart integration with DraftJS

This plugin for draft-js-editor

Install

npm install -S draft-js-emoji-mart-plugin

Install peer dependencies

npm install -S emoji-mart draft-js

Usage

import Editor from 'draft-js-plugins-editor';
import createEmojiMartPlugin from 'draft-js-emoji-mart-plugin';
import data from 'emoji-mart/data/apple.json';

import 'emoji-mart/css/emoji-mart.css'

const emojiPlugin = createEmojiMartPlugin({
  data,
  set: 'apple'
});

// NimblePicker from emoji-mart binded with draftjs
const { Picker } = emojiPlugin;

const MyEditor = ({ editorState, onChange }) => (
  <div>
    <Editor
      editorState={editorState}
      onChange={onChange}
      plugins={[emojiPlugin]}
    />
    {/*
      Any props supported by emoji-mart NimblePicker.
      Feel free to style it and trigger for view.
    */}
    <Picker
      perLine={7}
      showPreview={false}
    />
  </div>
)

export default MyEditor;

Configuration Parameters

Name Required Default Description
data true undefined Dataset from emoji-mart. Used for bind picker and replace emoji in editor.
set true undefined Addtional param to Dataset, used by emoji-mart.
emojiSize false 16 Size wich pass to Emoji component from emoji-mart.
sheetSize false emojiSize * 2 Sheet size wich pass to Emoji component from emoji-mart. By default emojiSize * 2.
onChange false undefined Call then DraftJS recieve new state.

Additional plugin feature

Emoji component

Plugin provide Emoji component, wich could replace native utf-8 emoji by NimbleEmoji component from emoji-mart.

// MyEditor.jsx
export const emojiPlugin = createEmojiMartPlugin({
  data,
  set: 'apple'
});

// Text.jsx
import { emojiPlugin } from './MyEditor.jsx';

const { Emoji } = emojiPlugin;

const TextViewer = ({ props }) => (
  <div>
    Useful text with emoji <Emoji decoratedText={'๐Ÿ˜ˆ'} />
  </div>
);

export default TextViewer;

Emoji RegExp

Useful to find native emoji in string. Could be used with Emoji component provided by plugin for replace emoji in plane text.

import { unicodeEmojiRegexp } from 'draft-js-emoji-mart-plugin/lib/constants';
import { emojiPlugin } from './MyEditor.jsx';

const { Emoji } = emojiPlugin;

// Not for production usage.
const parsedText = 'some string with ๐Ÿ˜ˆ '.split(unicodeEmojiRegexp).map(term => {
  if (term.match(unicodeEmojiRegexp)) {
    return <Emoji decoratedText={term} />
  }

  return term;
});

console.log(parsedText); // ['some string with', <Emoji decoratedText={'๐Ÿ˜ˆ'}>]

// Render it by React
const MyEmojifiedText = () => (
  <div>{parsedText}</div>
);

draft-js-emoji-mart-plugin's People

Contributors

zamarawka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.