• Stars
    star
    337
  • Rank 124,898 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 11 months ago

Reviews

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

Repository Details

Normalize and render emoji's the way your users expect.

npm version Tests

react-emoji-render

Normalize and render emoji's the way your users expect.

  • Supports unicode emoji characters
  • Supports emoticons such as :) :x :/
  • Supports slack-style emoji names such as :smile:
  • Choose between native, twemoji, emojione or custom image sets.
  • Add custom styles when text contains only emoji (to make it bigger, of course)

Live Demo on CodeSandbox

Installation

Install with your favorite package manager:

npm install react-emoji-render --save
yarn add react-emoji-render

Basic Usage

By default the component will normalize all of the different emoji notations to native unicode characters.

import Emoji from "react-emoji-render";

<Emoji text="This ❤️ sentence includes :+1: a variety of emoji types :)" />;

// or as a child
<Emoji>
  This ❤️ sentence includes :+1: a variety of emoji types :)
<Emoji/>;

Twemoji

Twemoji is an emoji set designed by Twitter, you can use the included Twemoji component to render emoji images in this style.

import { Twemoji } from 'react-emoji-render';

<Twemoji text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

// or, for svg images:
<Twemoji svg text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

Emojione

Emojione is a great looking open source emoji set, you can use the included Emojione component to render emoji images in this style.

import { Emojione } from 'react-emoji-render';

<Emojione text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

// or, for svg images:
<Emojione svg text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

// or, for Emojione v4
<EmojioneV4 text="This ❤️ sentence includes :+1: a variety of emoji types :)" />
// note: only png supported -->
// https://github.com/emojione/emojione-assets/issues/2

// in v4 size prop can be set at 32, 64 (default) or 128
<EmojioneV4 size={32} text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

Advanced Usage

Only Emoji

The className passed as the onlyEmojiClassName prop is added when the provided text contains only three or less emoji characters. This allows you to add custom styles in this scenario. For example:

<Emoji text=":+1:" onlyEmojiClassName="make-emojis-large" />

Array Output

If you want to do further processing on the output, for example parsing HTML then it may be useful to not have the normalized emojis be wrapped in a component.

import { toArray } from "react-emoji-render";

// content is an array of text and emoji components, you can now loop through this
// array and perform further processing. Avoid using `dangerouslySetInnerHTML`!
const content = toArray(
  "This ❤️ sentence includes :+1: a variety of emoji types :)"
);

Then, for example, you can parse all the text and emojis in a single string like the following:

const parseEmojis = value => {
  const emojisArray = toArray(value);

  // toArray outputs React elements for emojis and strings for other
  const newValue = emojisArray.reduce((previous, current) => {
    if (typeof current === "string") {
      return previous + current;
    }
    return previous + current.props.children;
  }, "");

  return newValue;
};

parseEmojis(":)hello"); // => "😃hello"

Custom Images

If you wish to use a custom emoji set / location then you can pass options into the props. One way to achive this is to create a wrapping component which provides your options and exposes a new component, something like:

import Emoji from "react-emoji-render";

function MyEmojiRenderer({ children, ...rest }) {
  const options = {
    baseUrl: "https://mycustom.cdn.com/emojis/",
    ext: "svg",
  };

  return <Emoji options={options} {...rest} />;
}

You can then use the new component:

<MyEmojiRenderer text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

Contributing

Emojis and aliases

If our dataset is missing some emoji, please open an issue specifying which one is missing. The library has a package script (yarn update-aliases) that makes it easy to update with the latest emojis at any time. You can directly do it yourself and open a PR as well.

If you would like to add a new alias to an existing emoji, please find the emoji in our custom aliases file and add the alias to its array of aliases. If you have found a source of aliases that is being actively maintained and you would like to add it, please open an issue to discuss it.

More Repositories

1

tinycon

A small library for manipulating the favicon, in particular adding alert bubbles and changing images.
JavaScript
5,110
star
2

crumble

Crumble makes it easy to create feature tours in your website or app.
JavaScript
659
star
3

emojione-picker

A react emoji picker for use with emojione
JavaScript
261
star
4

electron-lets-move

Automatically move Electron apps to the Applications directory
JavaScript
178
star
5

fastimage

FastImage finds the dimensions or filetype of an image at a url by fetching the least data possible
PHP
163
star
6

HackerNew

The best Chrome extension to make Hacker News quicker and more useful.
JavaScript
125
star
7

fontselect-jquery-plugin

A font selector for the Google Web Fonts api
JavaScript
102
star
8

navigate-jquery-plugin

Allows any group of dom elements to be navigated with the keyboard arrows
JavaScript
16
star
9

tinyrange-jquery-plugin

TinyRange is a small jquery slider plugin that augments the html5 range element
JavaScript
15
star
10

promise-pool

A flexible pool of promises that can be awaited and executed at a chosen level of concurrency
JavaScript
10
star
11

Zap

Zap! is an audio manager for html 5 applications with a focus on real time and interactive applications such as games.
JavaScript
7
star
12

distribute-jquery-plugin

Ensures child elements are horizontally spaced evenly in fluid layouts
JavaScript
6
star
13

mime-names

Media Type Names Database
JavaScript
4
star
14

Testing-Repo

Testing Repository.
JavaScript
4
star
15

annotatey

Draw annotations on any website and save to Dropbox. Hack project for TechCrunch Disrupt 2013
JavaScript
3
star
16

dotfiles

My dotfiles. It's public because it's free, not because you should care.
Ruby
3
star
17

sheffield-js-photobooth

Sample application built for talk on node-webkit at Sheffield.js
JavaScript
2
star
18

felony

WIP. HTML5 top-down game using box2d
JavaScript
1
star
19

electronguides.github.io

A collection of guides for those building Electron apps
1
star
20

macflix

Mac desktop wrapper for Netflix with all the goodies you'd expect
JavaScript
1
star
21

pulse-jquery-plugin

Animate the DOM using a mediaStream
JavaScript
1
star
22

personal-api

WIP, framework for anyone to easily build a personal API.
JavaScript
1
star
23

vagrant-heroku

Ruby
1
star
24

easy-peer-connection

A wrapper library to make PeerConnections in the web browser easy
1
star
25

tommoor.github.io

Personal website
HTML
1
star
26

doorman

This script answers my front door
JavaScript
1
star
27

quantified-chrome

Track your browsing habits
CSS
1
star
28

filecop

Checks filenames against a library of filename rules to find sensitive files
Ruby
1
star
29

forest

Fast, detailed event logging for lithium PHP
1
star