4.9.2 • Published 1 month ago

emoji-picker-react v4.9.2

Weekly downloads
16,251
License
MIT
Repository
github
Last release
1 month ago

Emoji Picker React (v4) | Live Demo

Picker

Usage as a Reactions Picker

image

reactions

If you enjoy using emoji-picker-react You should also consider trying: Vest validation framework.


What to know before using

  • This package assumes it runs in the browser. I have taken many steps to prevent it from failing on the server, but still, it is recommended to only render the component on the client. See troubleshooting section for more information.

Installation

npm install emoji-picker-react

Usage

import EmojiPicker from 'emoji-picker-react';

function App() {
  return (
    <div>
      <EmojiPicker />
    </div>
  );
}

Shout Outs

Component Design 🎨
317751726_1277528579755086_5320360926126813336_n copy
Pavel Bolo

Features

  • Custom click handler
  • Custom Emojis Support
  • Dark mode
  • Customizable styles via css variables
  • Default skin tone selection
  • Skin tone change
  • Different emoji sets (Google, Apple, Facebook, Twitter)
  • Native Emoji support
  • Emoji Component To Render Emojis in your app
  • Reactions Picker

Props

The following props are accepted by them picker:

PropTypeDefaultDescription
openbooleantrueControls whether the picker is open or not.
onEmojiClickfunctionCallback function that is called when an emoji is clicked. The function receives the emoji object as a parameter.
autoFocusSearchbooleantrueControls the auto focus of the search input.
ThemestringlightControls the theme of the picker. Possible values are light, dark and auto.
emojiStylestringappleControls the emoji style. Possible values are google, apple, facebook, twitter and native.
defaultSkinTonestringneutralControls the default skin tone.
lazyLoadEmojisbooleanfalseControls whether the emojis are loaded lazily or not.
previewConfigobject{}Controls the preview of the emoji. See below for more information.
searchPlaceholderstringSearchControls the placeholder of the search input.
suggestedEmojisModestringfrequentControls the suggested emojis mode. Possible values are frequent and recent.
skinTonesDisabledbooleanfalseControls whether the skin tones are disabled or not.
searchDisabledbooleanfalseControls whether the search is disabled or not. When disabled, the skin tone picker will be shown in the preview component.
skinTonePickerLocationstringSEARCHControls the location of the skin tone picker. Possible values are SEARCH and PREVIEW.
emojiVersionstring-Allows displaying emojis up to a certain version for compatibility.
classNamestring-Adds a class name to the root element of the picker.
widthnumber/string350Controls the width of the picker. You can provide a number that will be treated as pixel size, or your any accepted css width as string.
heightnumber/string450Controls the height of the picker. You can provide a number that will be treated as pixel size, or your any accepted css height as string.
styleReact.CSSProperties{}Adds inline style to the root element of the picker.
getEmojiUrlFunction-Allows to customize the emoji url and provide your own image host.
categoriesArray-Allows full config over ordering, naming and display of categories.
customEmojisArray<{names: string[], imgUrl: string, id: string}>-Allows adding custom emojis to the picker.
reactionsDefaultOpenbooleanfalseControls whether the reactions picker is on the initial mount instead of the main picker component.
reactionsstring[]-Controls the reactions to display in the reactions picker. Takes unified emoji ids
onReactionClickFunction-Callback function that is called when a reaction is clicked. The function receives the emoji object as a parameter. If not passed, onEmojiClicked is used.
allowExpandReactionsbooleantrueControls whether the reactions picker can be expanded to the main picker.
onSkinToneChangeFunction-Callback function that is called when a skin tone is changed. The function receives new picked skin tone as a parameter.

Full details

  • onEmojiClick: (emojiData: EmojiClickData, event: MouseEvent) => void - Callback function when an emoji is clicked. The callback receives the event and the emoji data. The emoji data is comprised of the following properties:

    {
      activeSkinTone: SkinTones;
      unified: string;
      unifiedWithoutSkinTone: string;
      emoji: string; // the emoji character, for example: '😀'. Emoji ID in custom emojis
      isCustom: boolean; // whether the emoji is a custom emoji or not
      names: string[];
      imageUrl: string; // the url of the emoji image with the current emoji style applied
      getImageUrl: (emojiStyle: EmojiStyle) => string; // a function that receives an emoji style and returns the url of the emoji image with the provided style applied
    }
  • theme: Theme - The theme of the picker. Can be light, dark or auto. Default is light. The Theme enum can be imported from the package.

    import { Theme } from 'emoji-picker-react';
  • emojiStyle: EmojiStyle - The emoji style to use. Can be either apple, google, facebook, twitter or native. Default is apple. The EmojiStyle enum can be imported from the package.

    import { EmojiStyle } from 'emoji-picker-react';
  • autoFocusSearch: boolean - Whether to focus the search input on mount. Defaults to true.

  • lazyLoadEmojis: boolean - Whether to lazy load the emojis. Defaults to false.

  • defaultSkinTone: SkinTones - The default skin tone to use when an emoji is clicked. Defaults to SkinTones.Neutral. Possible skin tones are:

    • ✋ 'neutral'
    • ✋🏻 '1f3fb'
    • ✋🏼 '1f3fc'
    • ✋🏽 '1f3fd'
    • ✋🏾 '1f3fe'
    • ✋🏿 '1f3ff'

The skin tones typescript enum can be imported directly from the package:

import { SkinTones } from 'emoji-picker-react';
  • onSkinToneChange: (skinTone: SkinTones) => void - Callback function when a skin tone is changed.

  • searchDisabled: boolean - Whether to disable the search input. Defaults to false. When disabled, the skin tone picker will be shown in the preview component.

  • skinTonesDisabled: boolean - Whether to disable the skin tone selection. Defaults to false.

  • skinTonePickerLocation: SkinTonePickerLocation - The location of the skin tone picker. Can be either SEARCH or PREVIEW. Defaults to SEARCH. The SkinTonePickerLocation enum can be imported from the package.

    import { SkinTonePickerLocation } from 'emoji-picker-react';
  • previewConfig: PreviewConfig - Full control over the Preview component, either to show/hide it, change the default emoji or the default caption.

{
  defaultEmoji: string; // defaults to: "1f60a"
  defaultCaption: string; // defaults to: "What's your mood?"
  showPreview: boolean; // defaults to: true
}
  • searchPlaceholder: string - The placeholder text for the search input. Defaults to Search.

  • categories: Allows full config over ordering, naming and display of categories. To only sort/omit categories, you can simply pass an array of category names to display:

    • 'suggested',
    • 'custom', - Hidden by default
    • 'smileys_people',
    • 'animals_nature',
    • 'food_drink',
    • 'travel_places',
    • 'activities',
    • 'objects',
    • 'symbols',
    • 'flags'

    For a more in-depth configuration, you can pass an array with category config:

    [
      {
        category: 'suggested',
        name: 'Recently Used'
      },
      {
        category: 'smileys_people',
        name: 'Faces...'
      }
    ];
  • suggestedEmojisMode: SuggestedEmojisMode - The mode to use for the suggested emojis. Can be either recent or frequent. Defaults to recent. The SuggestionMode enum can be imported from the package.

    import { SuggestionMode } from 'emoji-picker-react';
  • emojiVersion: string - Allows displaying emojis up to a certain version for compatibility. The passed version will be parsed as a float and each emoji will be tested against it. Common values are:

    • "0.6"
    • "1.0"
    • "2.0"
    • "3.0"
    • "4.0"
    • "5.0"
  • getEmojiUrl: (unified: string, emojiStyle: EmojiStyle) => string - Allows to customize the emoji url and provide your own image host. The function receives the emoji unified and the emoji style as parameters. The function should return the url of the emoji image.

Custom Emojis

The customEmojis prop allows you to add custom emojis to the picker. The custom emojis prop takes an array of custom emojis, each custom emoji has three keys:

id: Unique identifier for each of the custom emojis names: an array of string identifiers, will be used both for display, search and indexing. imgUrl: URL for the emoji image

Usage Example

<Picker
  customEmojis={[
    {
      names: ['Alice', 'alice in wonderland'],
      imgUrl:
        'https://cdn.jsdelivr.net/gh/ealush/emoji-picker-react@custom_emojis_assets/alice.png',
      id: 'alice'
    },
    {
      names: ['Dog'],
      imgUrl:
        'https://cdn.jsdelivr.net/gh/ealush/emoji-picker-react@custom_emojis_assets/dog.png',
      id: 'dog'
    },
    {
      names: ['Hat'],
      imgUrl:
        'https://cdn.jsdelivr.net/gh/ealush/emoji-picker-react@custom_emojis_assets/hat.png',
      id: 'hat'
    },
    {
      names: ['Vest'],
      imgUrl:
        'https://cdn.jsdelivr.net/gh/ealush/emoji-picker-react@custom_emojis_assets/vest.png',
      id: 'vest'
    }
  ]}
/>

Here are some additional things to keep in mind about custom emojis:

  • The custom emojis will be added to the Custom category.
  • The location or name of the Custom category can be controlled via the categories prop.
  • The custom emojis will be indexed by their id property. This means that you can search for custom emojis by their id or names.

Reactions Picker

image

reactions

The picker can be used as a reactions picker. To use it as a reactions picker, you should set the reactionsDefaultOpen prop to true. This will cause the picker to the reactions picker on the initial mount instead of the main picker component.

To customize the reactions, you should pass an array of unified emoji ids to the reactions prop.

The reactions picker uses the same event handlers, and the same css variables for customizations.

<Picker reactionsDefaultOpen={true} onReactionClick={handleReaction} />

Customization

Custom Picker Width and Height

To customize the dimensions of the picker, use the height and width props. You can pass in a number that will be treated as pixel size, or your any accepted css width/height as string.

<EmojiPicker height={500} width={400} />
<EmojiPicker height="100%" width="15em" />

CSS Variables

The picker can be customized via css variables. The root selector for the picker is .EmojiPickerReact, when overriding, make sure to provide a more specific selector.

In dark mode, the specific selector is .EmojiPickerReact.epr-dark-theme.

The list of possible variables is quite extensive, but the main ones you may want to override are:

  • --epr-emoji-size: The size of the emojis.
  • --epr-emoji-gap: The space between emojis.

  • --epr-hover-bg-color Hovered emoji background color.

  • --epr-bg-color: The background color of the picker. When changing it, you should also change --epr-category-label-bg-color as they are usually the same color.
  • --epr-text-color: The text color in the picker.

Rendering Output Emojis in Your App

The picker exports an Emoji component. The emoji component is the same used within the picker, so it will render the same way as the emojis in the picker. You can choose to render emojis either as native, or as images.

Props

NameTypeDefaultDescription
unifiedstring""The unified code of the emoji.
sizenumber32The size of the emoji.
emojiStyleEmojiStyleEmojiStyle.APPLEThe emoji style to use. Can be either apple, google, facebook, twitter or native.
lazyLoadbooleanfalseWhether to lazy load the emoji. image
emojiUrlstring-The url of the emoji image to render. Useful for custom emojis.
getEmojiUrlFunction-Allows to customize the emoji url and provide your own image host for dynamic resolution.
import { Emoji, EmojiStyle } from 'emoji-picker-react';

export function MyApp() {
  return (
    <p>
      My Favorite emoji is:
      <Emoji unified="1f423" size="25" />
    </p>
  );
}

How to Contribute?

Check out the contributing documentation to get information about contributing, reporting bugs, suggesting enhancements, and writing code changes to the project!

Troubleshooting

Error Boundary

emoji-picker-react has a top-level error boundary, trying to catch rendering errors. It won't catch server side related errors, or event handlers errors. If an error is caught, the picker will not render, and a console error will be logged.

Next.js

To avoid errors such as "document is not defined" on the server side, you should make sure the library is only imported on the client side. Here is how to do that:

import dynamic from 'next/dynamic';

const Picker = dynamic(
  () => {
    return import('emoji-picker-react');
  },
  { ssr: false }
);

Vite

For reference, if you only need to shim global, you can add

<script>
  window.global = window;
</script>
@edifice.io/editor@edifice.io/mindplot@uponco/admin-uiwidget_tikket@infinitebrahmanuniverse/nolb-emoji-p@eten-lab/discussion-boxemdkb-kitemdkb-kit-1intraactive-sdk-ui@everything-registry/sub-chunk-1582hackhubb-components@itoa/fieldsghosty-widgetmedusa-admin-ui-fagubick-storybook-styleshillz_chatgrooming-centerjumbito-standalonejumbito-standalone2jumbito-standalone3hello-next-apphasanadehcourseisometrik-chatmario-chatmaroc4products-admin-uimaterial-ui-form-builderensightful-koala-uiecu-clientembeddedchatdumy-23farapod-course-productionfarapod-course-sandboxfirebase-login-templateemoji-picker-textfieldocrcc-chatboxom-master-complaika-ti-chatgpt-reactl-min-components@lrocher/medusa-admin-uimighty-emoji-pickermodupe-react-startermedusa-adminmedika-ui-componentsmedusajs-admin-uimentalgpt-chat-pluginrasa-chat-libraryprivate-safesupport-chatboxreact-discussionviewreact-comments-sectionreact-comments-section-pt-brreact-comments-sectionv2react-chat-optireact-chat-optimreact-chat-optimireact-chat-easyreact-customized-componentsreact-commentviewscab-chatsafesupport-chatboxreact-swift-nested-commentsreact-simple-typewriter-wemojired-quick-templatetedooo-web-design-systemtag-input-fieldtest-admin-uiuc-custom-medusajs-admin-uiuc-custon-medusajs-admin-uistorefront-icu_admin-uistrapi-plugin-reactionstg-designtechbrains-chat@pensil-inc/web-sdk@netlambda/admin-ui@polesapart/novel@nazmul_mpower/dashboardvisualization@nelomobile/medusa-admin-ui@perseides/admin-ui@pushprotocol/uiweb@foxpage/foxpage-rich-text-editorzj_chat_gpt@equinor/ioc-common-frontend@ryaneewx/react-chat-widget@novapo/medusajs-admin-uivacation-rentals-socket-client@minternaljs/admin-ui@lambdacurry/gatsby-theme-medusa-admin@optidist/admin-ui@payglo/admin-ui@ocopjs/fields@medikabazaar/ui-components@medusajs/admin-ui@mephistowa/cra-template-typescript-redux-red-quick@fluxusui/fluxusui-base@inderes/react-ui@gip-recia/wisemapping-editor@gip-recia/wisemapping-mindplot@guozg/react-comments-section@hadicph/admin-ui@isalinaderi/chat-component@selfcommunity/react-ui
4.9.0

1 month ago

4.9.2

1 month ago

4.9.1

1 month ago

4.8.0

2 months ago

4.7.18

2 months ago

4.7.17

3 months ago

4.7.16

3 months ago

4.7.15

3 months ago

4.7.13

3 months ago

4.7.14

3 months ago

4.7.12

3 months ago

4.7.11

3 months ago

4.7.10

3 months ago

4.7.9

3 months ago

4.7.8

3 months ago

4.7.6

3 months ago

4.7.5

3 months ago

4.7.7

3 months ago

4.7.7-rc.1

3 months ago

4.7.7-rc.0

3 months ago

4.7.2

3 months ago

4.7.1

3 months ago

4.7.4

3 months ago

4.7.3

3 months ago

4.7.16-rc.0

3 months ago

4.7.0

3 months ago

4.6.15

3 months ago

4.6.12

3 months ago

4.6.13

3 months ago

4.6.14

3 months ago

4.6.12-rc.1

3 months ago

4.6.12-rc.2

3 months ago

4.6.12-rc.3

3 months ago

4.6.12-rc.4

3 months ago

4.6.12-rc.5

3 months ago

4.6.12-rc.6

3 months ago

4.6.12-rc.7

3 months ago

4.6.14-rc.0

3 months ago

4.6.9-rc.1

4 months ago

4.6.9

4 months ago

4.6.11

4 months ago

4.6.10

4 months ago

4.6.11-rc.0

4 months ago

4.6.12-rc.0

4 months ago

4.6.8

4 months ago

4.6.8-rc.5

4 months ago

4.6.7

4 months ago

4.6.6

4 months ago

4.6.8-rc.2

4 months ago

4.6.8-rc.3

4 months ago

4.6.8-rc.1

4 months ago

4.6.6-rc.1

4 months ago

4.6.6-rc.3

4 months ago

4.6.6-rc.2

4 months ago

4.6.6-rc.4

4 months ago

4.6.6-rc.6

4 months ago

4.6.4-rc.2

4 months ago

4.6.5

4 months ago

4.6.4

4 months ago

4.6.1-rc.2

4 months ago

4.6.4-rc.1

4 months ago

4.6.1

4 months ago

4.6.3

4 months ago

4.6.2

4 months ago

4.6.1-rc.1

4 months ago

4.6.0

4 months ago

4.5.8

6 months ago

4.5.7

6 months ago

4.5.9

6 months ago

4.5.4

6 months ago

4.5.3

7 months ago

4.5.6

6 months ago

4.5.5

6 months ago

4.5.10

6 months ago

4.5.11

6 months ago

4.5.14

6 months ago

4.5.15

6 months ago

4.5.12

6 months ago

4.5.13

6 months ago

4.5.16

5 months ago

4.5.0-rc.1

8 months ago

4.5.0

8 months ago

4.5.2

8 months ago

4.5.1

8 months ago

4.5.2-rc.1

8 months ago

4.4.12

8 months ago

4.4.11

9 months ago

4.4.10-rc.1

10 months ago

4.4.10

10 months ago

4.4.9

1 year ago

4.4.8

1 year ago

4.4.1

2 years ago

4.4.0

2 years ago

4.4.3

2 years ago

4.4.2

2 years ago

4.4.5

1 year ago

4.4.4

2 years ago

4.4.7

1 year ago

4.4.6

1 year ago

4.3.0

2 years ago

4.4.0-rc.1

2 years ago

4.1.0-rc.1

2 years ago

4.4.0-rc.2

2 years ago

4.2.0

2 years ago

4.1.0

2 years ago

4.1.1

2 years ago

3.6.2

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.8

2 years ago

3.6.5

2 years ago

3.6.4

2 years ago

3.6.3

2 years ago

4.0.0-rc.10

2 years ago

4.0.0-rc.16

2 years ago

4.0.0-rc.15

2 years ago

4.0.0-rc.18

2 years ago

4.0.0-rc.17

2 years ago

4.0.0-rc.12

2 years ago

4.0.0-rc.11

2 years ago

4.0.0-rc.13

2 years ago

4.0.0-rc.19

2 years ago

4.0.0-rc.9

2 years ago

4.0.0-rc.8

2 years ago

4.0.0-rc.1

2 years ago

4.0.0-rc.3

2 years ago

4.0.0-rc.2

2 years ago

4.0.0-rc.5

2 years ago

4.0.0-rc.4

2 years ago

4.0.0-rc.7

2 years ago

4.0.0-rc.6

2 years ago

4.0.0-rc.30

2 years ago

4.0.0-rc.32

2 years ago

4.0.0-rc.31

2 years ago

4.0.0-rc.34

2 years ago

4.0.0-rc.33

2 years ago

4.0.0-rc.35

2 years ago

4.0.0-rc.21

2 years ago

4.0.0-rc.20

2 years ago

4.0.0-rc.27

2 years ago

4.0.0-rc.26

2 years ago

4.0.0-rc.29

2 years ago

4.0.0-rc.28

2 years ago

4.0.0-rc.23

2 years ago

4.0.0-rc.22

2 years ago

4.0.0-rc.25

2 years ago

4.0.0-rc.24

2 years ago

3.6.1-rc.1

2 years ago

3.6.1-rc

2 years ago

3.6.1

2 years ago

3.6.0

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

3.4.10

2 years ago

3.4.11

2 years ago

3.4.12

2 years ago

3.4.9

2 years ago

3.4.8

3 years ago

3.4.7

3 years ago

3.4.6

3 years ago

3.4.5

3 years ago

3.4.4

3 years ago

3.4.3

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.4.0-rc

3 years ago

3.3.0

3 years ago

3.2.4

4 years ago

3.2.4-rc.2

4 years ago

3.2.4-rc.1

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.2.0-rc.1

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.4-rc.1

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.1-rc.1

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

5 years ago

3.0.0-rc.10

5 years ago

3.0.0-rc.9

5 years ago

3.0.0-rc.8

5 years ago

3.0.0-rc.7

5 years ago

3.0.0-rc

5 years ago

3.0.0-rc.5

5 years ago

3.0.0-rc.3

5 years ago

3.0.0-rc.2

5 years ago

3.0.0-rc.1

6 years ago

2.1.2-rc.1

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.4-rc.0

6 years ago

2.0.3

6 years ago

2.0.3-rc.1

6 years ago

2.0.2

6 years ago

1.7.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-rc.5

6 years ago

2.0.0-rc.4

6 years ago

2.0.0-rc.3

6 years ago

2.0.0-rc.2

6 years ago

2.0.0-rc.1

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.6.6

6 years ago

1.6.5

6 years ago

1.6.4

6 years ago

1.6.3

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.4

6 years ago

1.5.3

6 years ago

1.5.3-rc.0

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.4

6 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.14

7 years ago

1.2.13

7 years ago

1.2.12

7 years ago

1.2.11

7 years ago

1.2.10

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9-RC

7 years ago

0.0.8-RC

7 years ago

0.0.7-RC1

7 years ago

0.0.7-RC

7 years ago

0.0.7-WIP

7 years ago

0.0.6-WIP

7 years ago

0.0.5-WIP

7 years ago

0.0.4-WIP

7 years ago

0.0.3-WIP

7 years ago

0.0.2-WIP

7 years ago

0.0.1-WIP

7 years ago

0.0.1-RC

7 years ago