Coder Social home page Coder Social logo

sumonrayy / emoji-picker-react Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ealush/emoji-picker-react

0.0 1.0 0.0 27.82 MB

React Emoji Picker

Home Page: https://stackblitz.com/edit/emoji-picker-react?file=index.js

License: The Unlicense

CSS 13.58% JavaScript 86.42%

emoji-picker-react's Introduction

emoji-picker-react

V3

Live Demo

Preview

What you need to know before installing?

  • Version 3 uses React hooks, which means you need to use React 16.8 or higher.
  • Unlike previous versions, this version uses Apple emojis.
  • V3 does not support SSR. The assumption is that you mount it only after user interaction in the browser. SSR support may be added in the future.

Installation

npm i emoji-picker-react

Or

yarn add emoji-picker-react

New v3 features

  • Larger emoji library.
  • Apple emojis instead of emojione.
  • Recently used emojis support.
  • Faster load time, improved performance.
  • Ability to set default skin tone.

Usage

Emoji-picker-react comes ready to use out of the box, zero conf needed. The only thing you need to do is add your own emoji click callback.

import React, { useState } from 'react';
import Picker from 'emoji-picker-react';

const App = () => {
  const [chosenEmoji, setChosenEmoji] = useState(null);

  const onEmojiClick = (event, emojiObject) => {
    setChosenEmoji(emojiObject);
  };

  return (
    <div>
      {chosenEmoji ? (
        <span>You chose: {chosenEmoji.emoji}</span>
      ) : (
        <span>No emoji Chosen</span>
      )}
      <Picker onEmojiClick={onEmojiClick} />
    </div>
  );
};

Accepted props

Name Type Default Value Required? Description
onEmojiClick Function undefined Yes Callback to run when clicking an emoji.
preload Boolean false No Indicates whether all emojis images, should be preloaded, or only when showing each category.
skinTone string neutral No Decides the default skit tone for supported emojis.
disableAutoFocus boolean false No Disables autofocus of the search bar. Useful for safari-iphone devices which zoom in to focused inputs.
disableSearchBar boolean false No Disables the search bar and the skin tone picker altogether.
disableSkinTonePicker boolean false No Disables the skin tone picker.
pickerStyle string undefined No Overrides style of the component.
groupNames Object undefined No Specifies alternative category names to use. See Internationalization section.
groupVisibility Object undefined No Specifies group names to be disabled.
native Boolean false No Loads system emojis instead of Apple Emoji pngs

onEmojiClick Arguments

onEmojiClick is a regular click handler for any of the emojis in the app. It takes two arguments:

  1. The click event.
  2. An emoji object, which contains the following:
    • emoji: The emoji symbol. May vary across OSs, in some it may not be visible to you.
    • unified: The actual emoji unicode.
    • activeSkinTone: The currently selected skin tone, regardless if the current emoji has one or not.
    • originalUnified: If the currently selected emoji has a skin tone modifier, originalUnified will hold the "neutral" code.
    • names: An array of one or more descriptive names for the emoji.

Setting a default skin tone modifier

You may choose an alternative skin tone as the default skin tone to show for supported emojis (such as the ๐Ÿค˜ rocker hand emoji). Emoji-picker-react exports descriptive names for all skin variations so you may use them when setting your variations.

The following are exported:

  • โœ‹ SKIN_TONE_NEUTRAL
  • โœ‹๐Ÿป SKIN_TONE_LIGHT
  • โœ‹๐Ÿผ SKIN_TONE_MEDIUM_LIGHT
  • โœ‹๐Ÿฝ SKIN_TONE_MEDIUM
  • โœ‹๐Ÿพ SKIN_TONE_MEDIUM_DARK
  • โœ‹๐Ÿฟ SKIN_TONE_DARK

Use them like this:

import React, { useState } from 'react';
import Picker, { SKIN_TONE_MEDIUM_DARK } from 'emoji-picker-react';

const App = () => {
  const [chosenEmoji, setChosenEmoji] = useState(null);

  const onEmojiClick = (event, emojiObject) => {
    setChosenEmoji(emojiObject);
  };

  return (
    <div>
      <Picker onEmojiClick={onEmojiClick} skinTone={SKIN_TONE_MEDIUM_DARK} />
    </div>
  );
};

Customize Styling

You can override the style of emoji-picker-react with pickerStyle props.

import React, { useState } from 'react';
import Picker from 'emoji-picker-react';

const App = () => {
  const [chosenEmoji, setChosenEmoji] = useState(null);

  const onEmojiClick = (event, emojiObject) => {
    setChosenEmoji(emojiObject);
  };

  return (
    <div>
      <Picker onEmojiClick={onEmojiClick} pickerStyle={{ width: '100%' }} />
    </div>
  );
};

Internationalization

The emoji names cannot be translated as they come from an external library, but it is possible to rename the categories. To rename the categories, pass a prop called groupNames which contains an object of group keys and their names as strings. For example:

<Picker
  groupNames={{
    smileys_people: 'yellow faces',
    animals_nature: 'cute dogs and also trees',
    food_drink: 'milkshakes and more',
    travel_places: 'I love trains',
    activities: 'lets play a game',
    objects: 'stuff',
    symbols: 'more stuff',
    flags: 'fun with flags',
    recently_used: 'did I really use those?!',
  }}
/>

The complete list of keys is:

  • smileys_people
  • animals_nature
  • food_drink
  • travel_places
  • activities
  • objects
  • symbols
  • flags
  • recently_used

Disabling categories

It is possible to disable certain categories by setting the groupVisibility prop. The groupVisibility prop takes an object of group names, and a boolean indicating whether they should be shown or not. For example, if you'd like to disable the flags category, set it to false like this:

<Picker
  groupVisibility={{
    flags: false,
  }}
/>

The complete list of keys is:

  • smileys_people
  • animals_nature
  • food_drink
  • travel_places
  • activities
  • objects
  • symbols
  • flags
  • recently_used

UI Customizations

In general, UI customizations can be done directly via CSS. Descriptive classnames were added in order for you to be able to easily target whatever it is you want to change, and the markup is guaranteed to stay unchanged until the next major version (4).

emoji-picker-react's People

Contributors

centrual avatar dependabot[bot] avatar ealush avatar erdemgonul avatar greenkeeper[bot] avatar iamthe-wraith avatar lamperoyge avatar lior-a avatar lleyton avatar nafaska avatar thenumberone avatar

Watchers

 avatar

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.