npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@solemomentsclub/emoji-picker-react

v4.0.8

Published

Emoji Picker component for React Applications on the web

Downloads

2

Readme

Emoji Picker React (v4) | Live Demo

Picker

An emoji picker component for React applications.

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>
  );
}

Features

  • Custom click handler
  • 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

Props

The following props are accepted by them picker:

| Prop | Type | Default | Description | | ------------------- | -------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------- | | onEmojiClick | function | | Callback function that is called when an emoji is clicked. The function receives the emoji object as a parameter. | | autoFocusSearch | boolean | true | Controls the auto focus of the search input. | | Theme | string | light | Controls the theme of the picker. Possible values are light, dark and auto. | | emojiStyle | string | apple | Controls the emoji style. Possible values are google, apple, facebook, twitter and native. | | defaultSkinTone | string | neutral | Controls the default skin tone. | | lazyLoadEmojis | boolean | false | Controls whether the emojis are loaded lazily or not. | | previewConfig | object | {} | Controls the preview of the emoji. See below for more information. | | searchPlaceholder | string | Search | Controls the placeholder of the search input. | | suggestedEmojisMode | string | frequent | Controls the suggested emojis mode. Possible values are frequent and recent. | | skinTonesDisabled | boolean | false | Controls whether the skin tones are disabled or not. | | width | number | 350 | Controls the width of the picker. | | height | number | 450 | Controls the height of the picker. | | cdnHost | string | https://cdn.jsdelivr.net | Override the cdn host to host your own cdn emoji files. | | emojiFormat | string | png | Override the emoji file format. |

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;
      names: string[];
      getImageUrl: (emojiStyle: EmojiStyle) => string;
    }
  • 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';
  • skinTonesDisabled: boolean - Whether to disable the skin tone selection. Defaults to false.

  • 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',
    • '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';

Customization

Custom Picker Width and Height

To customize the dimensions of the picker, use the height and width props:

<EmojiPicker height={500} width={400} />

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

| Name | Type | Default | Description | | ------------ | ------------ | ------------------ | ------------------------------------------------------------------------------------------- | | unified | string | "" | The unified code of the emoji. | | size | number | 32 | The size of the emoji. | | emojiStyle | EmojiStyle | EmojiStyle.APPLE | The emoji style to use. Can be either apple, google, facebook, twitter or native. | | lazyLoad | boolean | false | Whether to lazy load the emoji. image |

import { Emoji, EmojiStyle } from 'emoji-picker-react';

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

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>