Emoji Mart

One component to pick them all

README


Emoji Mart is a Slack-like customizable
emoji picker component for React
DemoChangelog

Build Status

picker

Missive | Team email, team chat, team tasks, one app
Brought to you by the Missive team

Installation


npm install --save emoji-mart

Components

Picker

  1. ``` js
  2. import 'emoji-mart/css/emoji-mart.css'
  3. import { Picker } from 'emoji-mart'

  4. <Picker set='apple' />
  5. <Picker onSelect={this.addEmoji} />
  6. <Picker title='Pick your emoji…' emoji='point_up' />
  7. <Picker style={{ position: 'absolute', bottom: '20px', right: '20px' }} />
  8. <Picker i18n={{ search: 'Recherche', categories: { search: 'Résultats de recherche', recent: 'Récents' } }} />
  9. ```

PropRequiredDefaultDescription
----:------:------------------
**autoFocus**|Auto
**color**|The
**emoji**|The
**include**|Only
**exclude**|Don't
**custom**|[Custom
**recent**|Pass
**enableFrequentEmojiSort**|Instantly
**emojiSize**|The
**onClick**|Params:
**onSelect**|Params:
**onSkinChange**|Params:
**perLine**|Number
**i18n**|[An
**native**|Renders
**set**|The
**theme**|The
**sheetSize**|The
**backgroundImageFn**|A
**emojisToShowFilter**|A
**showPreview**|Display
**showSkinTones**|Display
**emojiTooltip**|Show
**useButton**|When
**skin**|Forces
**defaultSkin**|Default
**skinEmoji**|The
**style**|Inline
**title**|The
**notFoundEmoji**|The
**notFound**|[Not
**icons**|[Custom

I18n

  1. ``` js
  2. search: 'Search',
  3. clear: 'Clear', // Accessible label on "clear" button
  4. notfound: 'No Emoji Found',
  5. skintext: 'Choose your default skin tone',
  6. categories: {
  7.   search: 'Search Results',
  8.   recent: 'Frequently Used',
  9.   smileys: 'Smileys & Emotion',
  10.   people: 'People & Body',
  11.   nature: 'Animals & Nature',
  12.   foods: 'Food & Drink',
  13.   activity: 'Activity',
  14.   places: 'Travel & Places',
  15.   objects: 'Objects',
  16.   symbols: 'Symbols',
  17.   flags: 'Flags',
  18.   custom: 'Custom',
  19. },
  20. categorieslabel: 'Emoji categories', // Accessible title for the list of categories
  21. skintones: {
  22.   1: 'Default Skin Tone',
  23.   2: 'Light Skin Tone',
  24.   3: 'Medium-Light Skin Tone',
  25.   4: 'Medium Skin Tone',
  26.   5: 'Medium-Dark Skin Tone',
  27.   6: 'Dark Skin Tone',
  28. },
  29. ```

Tip: You usually do not need to translate the categories and skin tones by youself, because this data and their translations should be included in the Unicode CLDR (the "Common Locale Data Repository"). You can look them up and just take them from there.

Sheet sizes

Sheets are served from unpkg, a global CDN that serves files published to npm.

SetSizeSizeSizeSize
-------------------------------------------------------------------------------------------------
apple4075611.343.60
facebook4165791.383.68
google3624891.122.78
twitter3614851.052.39

Datasets

While all sets are available by default, you may want to include only a single set data to reduce the size of your bundle.

SetSize
-----------------------
all611
apple548
facebook468
google518
twitter517

To use these data files (or any other custom data), use the NimblePicker component:

  1. ``` js
  2. import data from 'emoji-mart/data/google.json'
  3. import { NimblePicker } from 'emoji-mart'

  4. <NimblePicker set='google' data={data} />
  5. ```

Examples of emoji object:

  1. ``` js
  2. {
  3.   id: 'smiley',
  4.   name: 'Smiling Face with Open Mouth',
  5.   colons: ':smiley:',
  6.   text: ':)',
  7.   emoticons: [
  8.     '=)',
  9.     '=-)'
  10.   ],
  11.   skin: null,
  12.   native: '😃'
  13. }

  14. {
  15.   id: 'santa',
  16.   name: 'Father Christmas',
  17.   colons: ':santa::skin-tone-3:',
  18.   text: '',
  19.   emoticons: [],
  20.   skin: 3,
  21.   native: '🎅🏼'
  22. }

  23. {
  24.   id: 'octocat',
  25.   name: 'Octocat',
  26.   colons: ':octocat:',
  27.   text: '',
  28.   emoticons: [],
  29.   custom: true,
  30.   imageUrl: 'https://github.githubassets.com/images/icons/emoji/octocat.png'
  31. }

  32. ```

Emoji

  1. ``` js
  2. import { Emoji } from 'emoji-mart'

  3. <Emoji emoji={{ id: 'santa', skin: 3 }} size={16} />
  4. <Emoji emoji=':santa::skin-tone-3:' size={16} />
  5. <Emoji emoji='santa' set='apple' size={16} />
  6. ```

PropRequiredDefaultDescription
----:------:------------------
**emoji**|
**size**|
**native**|Renders
**onClick**|Params:
**onLeave**|Params:
**onOver**|Params:
[**fallback**](#unsupported-emojis-fallback)|Params:
**set**|The
**sheetSize**|The
**backgroundImageFn**|A
**skin**|Skin
**tooltip**|Show
[**html**](#using-with-dangerouslysetinnerhtml)|Returns

Unsupported emojis fallback

Certain sets don’t support all emojis. By default the Emoji component will not render anything so that the emojis’ don’t take space in the picker when not available. When using the standalone Emoji component, you can however render anything you want by providing the fallback props.

To have the component render :shrug: you would need to:

  1. ``` js
  2. <Emoji
  3.   set={'apple'}
  4.   emoji={'shrug'}
  5.   size={24}
  6.   fallback={(emoji, props) => {
  7.     return emoji ? `:${emoji.short_names[0]}:` : props.emoji
  8.   }}
  9. />
  10. ```

Using with dangerouslySetInnerHTML

The Emoji component being a functional component, you can call it as you would call any function instead of using JSX. Make sure you passhtml: true for it to return an HTML string.

  1. ``` js
  2. <span dangerouslySetInnerHTML={{
  3.   __html: Emoji({
  4.     html: true
  5.     set: 'apple'
  6.     emoji: '+1'
  7.     size: 24
  8.   })
  9. }}></span>
  10. ```

Using with contentEditable

Following the dangerouslySetInnerHTML example above, make sure the wrapping span sets contenteditable="false".

  1. ``` js
  2. <div contentEditable={true}>
  3.   Looks good to me

  4.   <span contentEditable={false} dangerouslySetInnerHTML={{
  5.     __html: Emoji({
  6.       html: true
  7.       set: 'apple'
  8.       emoji: '+1'
  9.       size: 24
  10.     })
  11.   }}></span>
  12. </div>
  13. ```

Custom emojis

You can provide custom emojis which will show up in their own category. You can either use a single image as imageUrl or use a spritesheet as shown in the second object.

  1. ``` js
  2. import { Picker } from 'emoji-mart'

  3. const customEmojis = [
  4.   {
  5.     name: 'Octocat',
  6.     short_names: ['octocat'],
  7.     text: '',
  8.     emoticons: [],
  9.     keywords: ['github'],
  10.     imageUrl: 'https://github.githubassets.com/images/icons/emoji/octocat.png',
  11.     customCategory: 'GitHub'
  12.   },
  13.   {
  14.     name: 'Test Flag',
  15.     short_names: ['test'],
  16.     text: '',
  17.     emoticons: [],
  18.     keywords: ['test', 'flag'],
  19.     spriteUrl: 'https://unpkg.com/emoji-datasource-twitter@4.0.4/img/twitter/sheets-256/64.png',
  20.     sheet_x: 1,
  21.     sheet_y: 1,
  22.     size: 64,
  23.     sheetColumns: 52,
  24.     sheetRows: 52,
  25.   },
  26. ]

  27. <Picker custom={customEmojis} />
  28. ```

The customCategory string is optional. If you include it, then the custom emoji will be shown in whatever
categories you define. If you don't include it, then there will just be one category called "Custom."

Not Found

You can provide a custom Not Found object which will allow the appearance of the not found search results to change. In this case, we change the default 'sleuth_or_spy' emoji to Octocat when our search finds no results.

  1. ``` js
  2. import { Picker } from 'emoji-mart'

  3. const notFound = () => <img src='https://github.githubassets.com/images/icons/emoji/octocat.png' />
  4. <Picker notFound={notFound} />
  5. ```

Custom icons

You can provide custom icons which will override the default icons.

  1. ``` js
  2. import { Picker } from 'emoji-mart'

  3. const customIcons = {
  4.   categories: {
  5.     recent: () => <img src='https://github.githubassets.com/images/icons/emoji/octocat.png' />,
  6.     foods: () => <svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M0 0l6.084 24H8L1.916 0zM21 5h-4l-1-4H4l3 12h3l1 4h13L21 5zM6.563 3h7.875l2 8H8.563l-2-8zm8.832 10l-2.856 1.904L12.063 13h3.332zM19 13l-1.5-6h1.938l2 8H16l3-2z"/>svg>,
  7.     people: () => <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M3 2l10 6-10 6z"></path>svg>
  8.   }
  9. }

  10. <Picker icons={customIcons} />
  11. ```

Headless search

The Picker doesn’t have to be mounted for you to take advantage of the advanced search results.

  1. ``` js
  2. import { emojiIndex } from 'emoji-mart'

  3. emojiIndex.search('christmas').map((o) => o.native)
  4. // => [🎄, 🎅🏼, 🔔, 🎁, ⛄️, ❄️]
  5. ```

With custom data

  1. ``` js
  2. import data from 'emoji-mart/datasets/apple'
  3. import { NimbleEmojiIndex } from 'emoji-mart'

  4. let emojiIndex = new NimbleEmojiIndex(data)
  5. emojiIndex.search('christmas')
  6. ```

Get emoji data from Native

You can get emoji data from native emoji unicode using the getEmojiDataFromNative util function.

  1. ``` js
  2. import { getEmojiDataFromNative, Emoji } from 'emoji-mart'
  3. import data from 'emoji-mart/data/all.json'

  4. const emojiData = getEmojiDataFromNative('🏊🏽‍♀️', 'apple', data)

  5. <Emoji
  6.   emoji={emojiData}
  7.   set={'apple'}
  8.   skin={emojiData.skin || 1}
  9.   size={48}
  10. />
  11. ```

Example of emojiData object:

  1. ``` js
  2. emojiData: {
  3.   "id": "woman-swimming",
  4.   "name": "Woman Swimming",
  5.   "colons": ":woman-swimming::skin-tone-4:",
  6.   "emoticons": [],
  7.   "unified": "1f3ca-1f3fd-200d-2640-fe0f",
  8.   "skin": 4,
  9.   "native": "🏊🏽‍♀️"
  10. }
  11. ```

Storage

By default EmojiMart will store user chosen skin and frequently used emojis in localStorage. That can however be overwritten should you want to store these in your own storage.

  1. ``` js
  2. import { store } from 'emoji-mart'

  3. store.setHandlers({
  4.   getter: (key) => {
  5.     // Get from your own storage (sync)
  6.   },

  7.   setter: (key, value) => {
  8.     // Persist in your own storage (can be async)
  9.   }
  10. })
  11. ```

Possible keys are:

KeyValueDescription
-------------------
skin`1,|
frequently`{An
last'astonished'(Optional)

Features

Powerful search

Short name, name and keywords

Not only does Emoji Mart return more results than most emoji picker, they’re more accurate and sorted by relevance.

summer

Emoticons

The only emoji picker that returns emojis when searching for emoticons.

emoticons

Results intersection

For better results, Emoji Mart split search into words and only returns results matching both terms.

high-five

Fully customizable

Anchors color, title and default emoji

customizable-color
pick-your-emoji

Emojis sizes and length

size-and-length

Default skin color

As the developer, you have control over which skin color is used by default.

skins

It can however be overwritten as per user preference.

customizable-skin

Multiple sets supported

Apple / Google / Twitter / Facebook

sets

Not opinionated

Emoji Mart doesn’t automatically insert anything into a text input, nor does it show or hide itself. It simply returns an emoji object. It’s up to the developer to mount/unmount (it’s fast!) and position the picker. You can use the returned object as props for the EmojiMart.Emoji component. You could also use emoji.colons to insert text into a textarea or emoji.native to use the emoji.

Usage outside React


Emoji Mart can be used with React alternatives such as Preact, Inferno, and react-lite.

Furthermore, you can use it as a custom element using remount, meaning that you can use it within any JavaScript framework (or vanilla JS).

For an end-to-end example of how to do this, see emoji-mart-outside-react.

Optimizing for production


Modern/ES builds


Emoji Mart comes in three flavors:

  1. ```
  2. dist
  3. dist-es
  4. dist-modern
  5. ```

- dist is the standard build with the highest level of compatibility.
- dist-es is the same, but uses ES modules for better tree-shaking.
- dist-modern removes features not needed in modern evergreen browsers (i.e. latest Chrome, Edge, Firefox, and Safari).

The default builds are dist and dist-es. (In Webpack, one or the other will be chosen based on your resolve main fields.)
If you want to use dist-modern, you must explicitly import it:

  1. ``` js
  2. import { Picker } from 'emoji-mart/dist-modern/index.js'
  3. ```

Using something like Babel, you can transpile the modern build to suit your own needs.

Removing prop-types



  1. ``` sh
  2. npm install --save-dev babel-plugin-transform-react-remove-prop-types
  3. ```

Then add to your .babelrc:

  1. ``` json
  2. "plugins": [
  3.   [
  4.     "transform-react-remove-prop-types",
  5.     {
  6.       "removeImport": true,
  7.       "additionalLibraries": [
  8.         "../../utils/shared-props"
  9.       ]
  10.     }
  11.   ]
  12. ]
  13. ```

You'll also need to ensure that Babel is transpiling emoji-mart, e.g. [by not excluding node_modules in babel-loader](https://github.com/babel/babel-loader#usage).

Development


  1. ``` sh
  2. yarn build
  3. ```

In two separate tabs:

  1. ``` sh
  2. yarn start
  3. yarn storybook
  4. ```

The storybook is hosted at localhost:6006, and the code will be built on-the-fly.

🎩 Hat tips!

Powered by [iamcal/emoji-data](https://github.com/iamcal/emoji-data) and inspired by [iamcal/js-emoji](https://github.com/iamcal/js-emoji).
🙌🏼  Cal Henderson.



Missive | Team email, team chat, team tasks, one app
Missive mixes team email and threaded group chat for productive teams.
A single app for all your internal and external communication and a full work management solution.