Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/missive/emoji-mart
๐ช One component to pick them all
https://github.com/missive/emoji-mart
component emoji emoji-picker emoticons missive picker react twemoji
Last synced: 3 days ago
JSON representation
๐ช One component to pick them all
- Host: GitHub
- URL: https://github.com/missive/emoji-mart
- Owner: missive
- License: mit
- Created: 2016-07-11T18:23:47.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T10:10:37.000Z (4 months ago)
- Last Synced: 2024-11-28T03:04:41.900Z (14 days ago)
- Topics: component, emoji, emoji-picker, emoticons, missive, picker, react, twemoji
- Language: TypeScript
- Homepage: https://missiveapp.com/open/emoji-mart
- Size: 54.2 MB
- Stars: 8,688
- Watchers: 39
- Forks: 835
- Open Issues: 170
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-frontend - emoji-mart - Emoji Mart is a customizable emoji picker HTML component for the web. ![](https://img.shields.io/github/stars/missive/emoji-mart.svg?style=social) (Repository / Animation)
- awesome - missive/emoji-mart - ๐ช One component to pick them all (TypeScript)
- awesome - missive/emoji-mart - ๐ช One component to pick them all (TypeScript)
- awesome-react - emoji-mart - Emoji Mart is a customizable emoji picker HTML component for the web. ![](https://img.shields.io/github/stars/missive/emoji-mart.svg?style=social) (UI Components / Form Components)
- awesome - missive/emoji-mart - ๐ช One component to pick them all (TypeScript)
- awesome-web-cn - emoji-mart - ไธไธชๅฏ่ชๅฎไน็่กจๆ ็ฌฆๅท้ๆฉๅจ react ็ปไปถ (Uncategorized / Uncategorized)
- awesome-repos - emoji-mart
- awesome-list - emoji-mart
- awesome - missive/emoji-mart - ๐ช One component to pick them all (TypeScript)
- awesome - missive/emoji-mart - ๐ช One component to pick them all (TypeScript)
README
Emoji Mart is a customizable
emoji picker HTML component for the web
Demo
Brought to you by the Missive team## ๐ Table of Contents
- [๐พ Data](#-data)
- [๐ช Picker](#-picker)
- [๐ Emoji component](#-emoji-component)
- [๐ต๏ธโโ๏ธ Headless search](#%EF%B8%8F%EF%B8%8F-headless-search)
- [๐ฌ Get emoji data from native](#-get-emoji-data-from-native)
- [๐บ Internationalization](#-internationalization)
- [๐ Examples](#-examples)
- [๐ค Built for modern browsers](#-built-for-modern-browsers)
- [๐ Development](#-development)## ๐พ Data
Data required for the picker to work has been completely decoupled from the library. That gives developers the flexibility to better control their app bundle size and let them choose how and when this data is loaded. Data can be:
### Bundled directly into your codebase
- **Pros:** Picker renders instantly, data is available offline
- **Cons:** Slower initial page load (bigger file to load)```sh
yarn add @emoji-mart/data
``````js
import data from '@emoji-mart/data'
import { Picker } from 'emoji-mart'new Picker({ data })
```### Fetched remotely
- **Pros:** Data fetched only when needed, does not affect your app bundle size
- **Cons:** Network latency, doesnโt work offline (unless you configure a ServiceWorker)```js
import { Picker } from 'emoji-mart'
new Picker({
data: async () => {
const response = await fetch(
'https://cdn.jsdelivr.net/npm/@emoji-mart/data',
)return response.json()
}
})
```In this example data is fetched from a content delivery network, but it could also be fetched from your own domain if you want to host the data.
## ๐ช Picker
### React
```sh
npm install --save emoji-mart @emoji-mart/data @emoji-mart/react
``````js
import data from '@emoji-mart/data'
import Picker from '@emoji-mart/react'function App() {
return (
)
}
```### Browser
```htmlconst pickerOptions = { onEmojiSelect: console.log }
const picker = new EmojiMart.Picker(pickerOptions)document.body.appendChild(picker)
```
### Options / Props
| Option | Default | Choices | Description |
| ------ | ------- | ------- | ----------- |
| **data** | `{}` | | Data to use for the picker |
| **i18n** | `{}` | | Localization data to use for the picker |
| **categories** | `[]` | `frequent`, `people`, `nature`, `foods`, `activity`, `places`, `objects`, `symbols`, `flags` | Categories to show in the picker. Order is respected. |
| **custom** | `[]` | | [Custom emojis](#custom-emojis) |
| **onEmojiSelect** | `null` | | Callback when an emoji is selected |
| **onClickOutside** | `null` | | Callback when a click outside of the picker happens |
| **onAddCustomEmoji** | `null` | | Callback when the *Add custom emoji* button is clicked. The button will only be displayed if this callback is provided. It is displayed when search returns no results. |
| **autoFocus** | `false` | | Whether the picker should automatically focus on the search input |
| **categoryIcons** | `{}` | | [Custom category icons](#custom-category-icons) |
| **dynamicWidth** | `false` | | Whether the picker should calculate `perLine` dynamically based on the width of ``. When enabled, `perLine` is ignored |
| **emojiButtonColors** | `[]` | i.e. `#f00`, `pink`, `rgba(155,223,88,.7)` | An array of color that affects the hover background color |
| **emojiButtonRadius** | `100%` | i.e. `6px`, `1em`, `100%` | The radius of the emoji buttons |
| **emojiButtonSize** | `36` | | The size of the emoji buttons |
| **emojiSize** | `24` | | The size of the emojis (inside the buttons) |
| **emojiVersion** | `14` | `1`, `2`, `3`, `4`, `5`, `11`, `12`, `12.1`, `13`, `13.1`, `14` | The version of the emoji data to use. Latest version supported in `@emoji-mart/data` is currently [14](https://emojipedia.org/emoji-14.0) |
| **exceptEmojis** | `[]` | | List of emoji IDs that will be excluded from the picker |
| **icons** | `auto` | `auto`, `outline`, `solid` | The type of icons to use for the picker. `outline` with light theme and `solid` with dark theme. |
| **locale** | `en` | `en`, `ar`, `be`, `cs`, `de`, `es`, `fa`, `fi`, `fr`, `hi`, `it`, `ja`, `ko`, `nl`, `pl`, `pt`, `ru`, `sa`, `tr`, `uk`, `vi`, `zh` | The locale to use for the picker |
| **maxFrequentRows** | `4` | | The maximum number of frequent rows to show. `0` will disable frequent category |
| **navPosition** | `top` | `top`, `bottom`, `none` | The position of the navigation bar |
| **noCountryFlags** | `false` | | Whether to show country flags or not. If not provided, tbhis is handled automatically (Windows doesnโt support country flags) |
| **noResultsEmoji** | `cry` | | The id of the emoji to use for the no results emoji |
| **perLine** | `9` | | The number of emojis to show per line |
| **previewEmoji** | `point_up` | | The id of the emoji to use for the preview when not hovering any emoji. `point_up` when preview position is bottom and `point_down` when preview position is top. |
| **previewPosition** | `bottom` | `top`, `bottom`, `none` | The position of the preview |
| **searchPosition** | `sticky` | `sticky`, `static`, `none` | The position of the search input |
| **set** | `native` | `native`, `apple`, `facebook`, `google`, `twitter` | The set of emojis to use for the picker. `native` being the most performant, others rely on spritesheets. |
| **skin** | `1` | `1`, `2`, `3`, `4`, `5`, `6` | The emojis skin tone |
| **skinTonePosition** | `preview` | `preview`, `search`, `none` | The position of the skin tone selector |
| **theme** | `auto` | `auto`, `light`, `dark` | The color theme of the picker |
| **getSpritesheetURL** | `null` | | A function that returns the URL of the spritesheet to use for the picker. It should be compatible with the data provided. |### Custom emojis
You can use custom emojis by providing an array of categories and their emojis. Emojis also support multiple skin tones and can be GIFs or SVGs.```js
import data from '@emoji-mart/data'
import Picker from '@emoji-mart/react'const custom = [
{
id: 'github',
name: 'GitHub',
emojis: [
{
id: 'octocat',
name: 'Octocat',
keywords: ['github'],
skins: [{ src: './octocat.png' }],
},
{
id: 'shipit',
name: 'Squirrel',
keywords: ['github'],
skins: [
{ src: './shipit-1.png' }, { src: './shipit-2.png' }, { src: './shipit-3.png' },
{ src: './shipit-4.png' }, { src: './shipit-5.png' }, { src: './shipit-6.png' },
],
},
],
},
{
id: 'gifs',
name: 'GIFs',
emojis: [
{
id: 'party_parrot',
name: 'Party Parrot',
keywords: ['dance', 'dancing'],
skins: [{ src: './party_parrot.gif' }],
},
],
},
]function App() {
return (
)
}
```### Custom category icons
You can use custom category icons by providing an object with the category name as key and the icon as value. Currently supported formats are `svg` string and `src`. See [example](https://missiveapp.com/open/emoji-mart/example-categories.html).```js
const customCategoryIcons = {
categoryIcons: {
activity: {
svg: '',
},
people: {
src: './people.png',
},
},
}
```## ๐ Emoji component
The emoji web component usage is the same no matter what library you use.First, you need to make sure data has been initialized. You need to call this only once per page load. Note that if you call `init` like this, you donโt necessarily need to include data in your Picker props. It doesnโt hurt either, it will noop.
```js
import data from '@emoji-mart/data'
import { init } from 'emoji-mart'init({ data })
```Then you can use the emoji component in your HTML / JSX.
```html
```
### Attributes / Props
| Attribute | Example | Description |
| --------- | ------- | ----------- |
| **id** | `+1` | An emoji ID |
| **shortcodes** | `:+1::skin-tone-2:` | An emoji shortcode |
| **native** | `๐` | A native emoji |
| **size** | `2em` | The inline element size |
| **fallback** | `:shrug:` | A string to be rendered in case the emoji canโt be found |
| **set** | `native` | The emoji set: `native`, `apple`, `facebook`, `google`, `twitter` |
| **skin** | `1` | The emoji skin tone: `1`, `2`, `3`, `4`, `5`, `6` |## ๐ต๏ธโโ๏ธ Headless search
You can search without the Picker. Just like the emoji component, `data` needs to be initialized first in order to use the search index.```js
import data from '@emoji-mart/data'
import { init, SearchIndex } from 'emoji-mart'init({ data })
async function search(value) {
const emojis = await SearchIndex.search(value)
const results = emojis.map((emoji) => {
return emoji.skins[0].native
})console.log(results)
}search('christmas') // => ['๐', '๐จ๐ฝ', '๐งโ๐', '๐', '๐คถ', '๐', 'โ๏ธ', 'โ๏ธ', '๐ ', 'โ']
```## ๐ฌ Get emoji data from native
You can get emoji data from a native emoji. This is useful if you want to get the emoji ID from a native emoji. Just like the emoji component, `data` needs to be initialized first in order to retrieve the emoji data.```js
import data from '@emoji-mart/data'
import { init, getEmojiDataFromNative } from 'emoji-mart'init({ data })
getEmojiDataFromNative('๐ค๐ฟ').then(console.log)
/* {
aliases: ['hand_with_index_and_middle_fingers_crossed'],
id: 'crossed_fingers',
keywords: ['hand', 'with', 'index', 'and', 'middle', 'good', 'lucky'],
name: 'Crossed Fingers',
native: '๐ค๐ฟ',
shortcodes: ':crossed_fingers::skin-tone-6:',
skin: 6,
unified: '1f91e-1f3ff',
} */
```## ๐บ Internationalization
EmojiMart UI supports [multiple languages](https://github.com/missive/emoji-mart/tree/main/packages/emoji-mart-data/i18n), feel free to open a PR if yours is missing.```js
import i18n from '@emoji-mart/data/i18n/fr.json'
i18n.search_no_results_1 = 'Aucun emoji'new Picker({ i18n })
```Given the small file size, English is built-in and doesnโt need to be provided.
## ๐ Examples
- [Categories](https://missiveapp.com/open/emoji-mart/example-categories.html)
- [Custom emoji font](https://missiveapp.com/open/emoji-mart/example-custom-font.html)
- [Custom styles](https://missiveapp.com/open/emoji-mart/example-custom-styles.html)
- [Emoji component](https://missiveapp.com/open/emoji-mart/example-emoji-component.html)
- [Headless search](https://missiveapp.com/open/emoji-mart/example-headless-search.html)
- [Slack colors](https://missiveapp.com/open/emoji-mart/example-slack-colors.html)## ๐ค Built for modern browsers
EmojiMart relies on these APIs, you may need to include polyfills if you need to support older browsers:
- [Shadow DOM](https://caniuse.com/shadowdomv1) ([MDN](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM))
- [Custom elements](https://caniuse.com/custom-elementsv1) ([MDN](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements))
- [IntersectionObserver](https://caniuse.com/intersectionobserver) ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API))
- [Async/Await](https://caniuse.com/async-functions) ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function))## ๐ Development
```sh
yarn install
yarn dev
```