Giter Club home page Giter Club logo

openmoji-for-react's Introduction

Openmoji for React

unofficial; bodged by drinking-code

  1. What is Openmoji for React?
  2. Installation
  3. Usage
    1. Automatically
      1. reactReplaceEmojis(jsx[, options])
      2. replaceEmojis(string[, options])
    2. Manually
      1. Via icon name
      2. Via unicode
      3. Attributes

What is Openmoji for React?

Openmoji is a collection of open source emojis. This repository lets you use these emojis in a React app easily.

Please comply with the Openmoji Attribution Requirements

Installation

npm i react-openmoji

Usage

Automatically

reactReplaceEmojis(jsx[, options])

For easy and dynamic use you can replace emojis completely automatically:

import React from 'react';
import reactReplaceEmojis from 'react-openmoji';

const App = () => {
    return reactReplaceEmojis(<p>Hello πŸ™‹β€β™‚οΈ World! 🌍</p>)
};

export default App;

You can also set options:

Field Type Description Default
size CSS length (string) size of the emojis 1.5em
outline boolean set to true if you want the colourless emojis false
import React from 'react';
import reactReplaceEmojis from 'react-openmoji';

const App = () => {
    return reactReplaceEmojis(
        <p>Hello πŸ™‹β€β™‚οΈ World! 🌍</p>,
        {size: '1.2em', outline: true}
    )
};

export default App;

replaceEmojis(string[, options])

Is the string equivalent to reactReplaceEmojis. Use this if you just want to replace emojis within a string.

import React from 'react';
import {replaceEmojis} from 'react-openmoji';

const App = () => {
    return <p>{replaceEmojis('Hello πŸ™‹β€β™‚οΈ World! 🌍')}</p>
};

export default App;

Manually

Via icon name

import React from 'react';
import {ManRaisingHand} from 'react-openmoji';

const App = () => {
    return <p>Hello World! <ManRaisingHand/></p>
};

export default App;

Icon names from the Openmoji Library are converted into PascalCase, so man raising hand translates to ManRaisingHand.

Additions

: is replaced with _.

waving hand: light skin tone  ->  WavingHand_LightSkinTone

,, ., ’, !, ”, and & are removed.

person: light skin tone, blond hair -> Person_LightSkinToneBlondHair
Mrs. Claus                          -> MrsClaus
twelve o’clock                      -> TwelveOclock
ON! arrow                           -> ONArrow
Japanese β€œhere” button              -> JapaneseHereButton
flag: Bosnia & Herzegovina          -> Flag_BosniaHerzegovina

# is replaced with NumberSign, * is replaced with Asterisk.

keycap: #  ->  Keycap_NumberSign
keycap: *  ->  Keycap_Asterisk

Everything in brackets is removed.

A button (blood type) -> AButton

If a name starts with a number, a _ is added in front of the name.

1st place medal -> _1stPlaceMedal

Note: Some names may appear more than once in the Library (i.e. some emoji variations). Those duplicates are renamed to DuplicatedName2, DuplicatedName3 etc.

Via unicode

You can use the unicode of the emoji to import it. Unicodes are also listed in the Openmoji Library. All unicode names have the U_ prefix in react-openmoji.

import React from 'react';
import {U_1F64B_200D_2642_FE0F} from 'react-openmoji';

const App = () => {
    return <p>Hello World! <U_1F64B_200D_2642_FE0F/></p>
};

export default App;

Fun fact: Importing all 3678 emojis at once is actually just as fast as the other methods because all emojis are dynamically loaded:

import React from 'react';
import * as Emoji from 'react-openmoji';

const App = () => {
    return <p>Hello <Emoji.ManRaisingHand/> World! <Emoji._1F30D/></p>
};

export default App;

Attributes

With all manual methods you can use two attributes:

Field Type Description Default
size CSS length (string) size of the emojis 1.5em
outline boolean attribute add if you want the colourless emojis false
import React from 'react';
import {ManRaisingHand} from 'react-openmoji';

const App = () => {
    return <p>Hello World! <ManRaisingHand size={'1.2em'} outline/></p>
};

export default App;

openmoji-for-react's People

Contributors

dependabot[bot] avatar drinking-code avatar

Stargazers

 avatar  avatar

Watchers

 avatar

openmoji-for-react's Issues

replaceEmojis() doesn't work with consecutive emojis

Consecutive emojis are not replaced with SVGs whatsoever.
Separating them with any character/s (e.g. spaces, zero width spaces) makes it work fine, but emojis without any character/s in between them are not replaced.

Yarn add error

Hi, I get this error when trying to install this lib.

Probably comes from this namespace "sodipodi:docname="flag-quebec.svg"". I've seen then being produced by inkscape. @svgo removes them.

Could probably be resolved by using @svgr here : https://github.com/drinking-code/openmoji-for-react/blob/master/build/correct-dom-properties.js

[5/6] Building fresh packages...
error XXX/node_modules/react-openmoji: Command failed.
Exit code: 1
Command: node build/build.js && npx babel --presets @babel/preset-react src --out-dir lib --copy-files && node build/correct-dom-properties.js && rm -rf src
Arguments: 
Directory: node_modules/react-openmoji
Output:
SyntaxError:XXX/node_modules/react-openmoji/src/icons/1F3F4-E0063-E0061-E0071-E0063-E007F.js: Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can set `throwIfNamespace: false` to bypass this warning.
   5 |     if (!outline) {
   6 |         return (
>  7 |             <svg width={size} height={size} className="openmoji" viewBox="0 0 72 72" version="1.1" sodipodi:docname="flag-quebec.svg" xmlns="http://www.w3.org/2000/svg" ><g id="line-supplement"><path stroke-width="1.849" d="m5 40.5v14.5h26v-14.5h-26zm13.521 2.4785a0.68564 0.68564 0 0 1 0.68555 0.68555v4.8242h0.20312c0.064592-0.48327 0.2712-0.91288 0.58398-1.2344 0.36396-0.3741 0.83888-0.61685 1.3594-0.77148a0.51863 0.51863 0 0 1 0.14648-0.021484 0.51863 0.51863 0 0 1 0.49805 0.37109 0.51863 0.51863 0 0 1-0.34961 0.64453c-0.39915 0.11858-0.71132 0.29362-0.91211 0.5-0.14013 0.14403-0.21782 0.314

Some ZWJ sequences are not getting replaced properly

Some concatenated emojis, like ❀️‍πŸ”₯, get replaced only partly (the fire part, and the heart stays as a preinstalled emoji), and some, like πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘©, not at all.
❀️‍πŸ”₯ in particular is not supported by Openmoji, so an option for handling those situations would be appropriate.

Probably should go through the list of all recommended ZWJ sequences and make all of them work (or purposely not, if Openmoji does not have a replacement).

SVGs cause content shifting after loading

The replaced emojis take up no space when not yet loaded. So, when they are loaded and rendered, the content jumps.

The improvement here would be to

  • reserve the needed screen estate in advance
    and/or
  • use the preinstalled emojis of the OS as a fallback-placeholder (similar to font-display: swap)

to reduce/eliminate cumulative layout shift coming from react-openmoji

Text-selecting replaced emojis

It would be useful if replaced emojis could be text-selected (like normal emojis), for example to be then copied and pasted somewhere else (as the actual emoji character)

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.