5.4.14 • Published 5 years ago

@bitsler/emoji-mart-vue v5.4.14

Weekly downloads
15
License
BSD-3-Clause
Repository
github
Last release
5 years ago

This project is a fork of https://github.com/jm-david/emoji-mart-vue with many performance fixes.

The original component was very slow to show/destroy, around 2 seconds to show and even a bit longer to destroy, so it was unusable in a popup.

This was the reason to fork and change it, the demo is here, use the "Show / hide the picker" button to see create/destroy performance

Major changes are:

  • Reworked emoji index class: use same index (so same data) for all components.
  • Added vue-virtual-scroller for emoji categories
  • Render emojis in categories without NimbleEmoji component, there are a lot of emojis to render and there is a noticeable slow down even with virtual scrolling when we render a component per emoji.
  • Frozen objects with emoji data to disable Vue change tracking
  • Do not create NimbleEmojiIndex globally, as it was loaded (along with the emoji data) even when not used
  • Extract CSS into external file, use less inline styles to reduce the amount of generated HTML
  • Fixes in CSS for native unicode emojis ported from the original react project
  • Excluded ./data/all.json from the js bundle (it was always loaded within the bundle even if it is not needed)
  • Updated to babel 7
  • Added tests

Build Status

codecov

It is not published to npm, to install from github, use npm install --save serebrov/emoji-mart-vue#4.0.0. (check the list of releases for available versions).

The original project has been forked from emoji-mart which was written for React

Installation

It is not published to npm, to install from github, use

npm install --save serebrov/emoji-mart-vue#4.0.0.

Check the list of releases for available versions).

Components

Picker

import { Picker } from 'emoji-mart-vue'

Import CSS with default styles:

import 'emoji-mart-vue/css/emoji-mart.css'

Note: to have a custom look for the picker, either use own css file without including the standard one or add custom styles on top of standard.

Note: CSS also includes background images for image-based emoji sets (apple, google, twitter, emojione, messenger, facebook). The images are loaded from the unpkg.com. To use self-hosted emojis sheet, override CSS like this:

/* load emojione sheet from own server */
.emoji-mart-body .emoji-type-image.emoji-set-emojione {
	background-image: url(/img/emojione-4.0.4-sheets-256-64.png);
}
<picker set="emojione" />
<picker @select="addEmoji" />
<picker title="Pick your emoji…" emoji="point_up" />
<picker :style="{ position: 'absolute', bottom: '20px', right: '20px' }" />
<picker
	:i18n="{ search: 'Recherche', categories: { search: 'Résultats de recherche', recent: 'Récents' } }"
/>
PropRequiredDefaultDescription
autoFocusfalseAuto focus the search input when mounted
color#ae65c5The top bar anchors select and hover color
emojidepartment_storeThe emoji shown when no emojis are hovered, set to an empty string to show nothing
emojiSize24The emoji width and height to calculate picker size; set the size for emoji itself via CSS
perLine9Number of emojis per line. While there’s no minimum or maximum, this will affect the picker’s width.
i18n{…}An object containing localized strings
nativefalseRenders the native unicode emoji
setappleThe emoji set: 'apple', 'google', 'twitter', 'emojione', 'messenger', 'facebook'
showPreviewtrueDisplay preview section
showSearchtrueDisplay search section
showCategoriestrueDisplay categories
showSkinTonestrueDisplay skin tones picker
emojiTooltipfalseShow emojis short name when hovering (title)
skinForces skin color: 1, 2, 3, 4, 5, 6
defaultSkin1Default skin color: 1, 2, 3, 4, 5, 6
pickerStylesInline styles applied to the root element. Useful for positioning
titleEmoji Mart™The title shown when no emojis are hovered
infiniteScrolltrueScroll continuously through the categories
EventDescription
selectParams: (emoji) => {}
skin-changeParams: (skin) => {}

I18n

search: 'Search',
notfound: 'No Emoji Found',
categories: {
  search: 'Search Results',
  recent: 'Frequently Used',
  people: 'Smileys & People',
  nature: 'Animals & Nature',
  foods: 'Food & Drink',
  activity: 'Activity',
  places: 'Travel & Places',
  objects: 'Objects',
  symbols: 'Symbols',
  flags: 'Flags',
  custom: 'Custom',
}

Sheet sizes

Sheets are served from unpkg, a global CDN that serves files published to npm. Note: URLs for background images are specified in the css/emoji-mart.css.

SetSize (sheetSize: 16)Size (sheetSize: 20)Size (sheetSize: 32)Size (sheetSize: 64)
apple334 KB459 KB1.08 MB2.94 MB
emojione315 KB435 KB1020 KB2.33 MB
facebook322 KB439 KB1020 KB2.50 MB
google301 KB409 KB907 KB2.17 MB
messenger325 KB449 MB1.05 MB2.69 MB
twitter288 KB389 KB839 KB1.82 MB

Datasets and Custom Emojis

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 (on disk)
all570 KB
apple484 KB
emojione485 KB
facebook421 KB
google483 KB
messenger197 KB
twitter484 KB

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

import data from 'emoji-mart-vue/data/messenger.json'
import { NimblePicker, EmojiIndex } from 'emoji-mart-vue'
let index = new EmojiIndex(data)
<nimble-picker set="messenger" :data="data" />

Using EmojiIndex, it is also possible to control which emojis data is included or excluded via constructor parameters:

ParamDefaultDescription
include[]Only load included categories. Accepts I18n categories keys. Order will be respected, except for the recent category which will always be the first.
exclude[]Don't load excluded categories. Accepts I18n categories keys.
custom[]Custom emojis
recentPass your own frequently used emojis as array of string IDs
recentLengthSet the number of emojis for the recent category.
emojisToShowFilter((emoji) => true)A Fn to choose whether an emoji should be displayed or not

Categories for exclude and include parameters are specified as category id, that are present in data arrays.

Avaiable categories are: people, nature, foods, activity, places, objects, symbols, flags.

For example:

import data from 'emoji-mart-vue/data/messenger.json'
import { NimblePicker, EmojiIndex } from 'emoji-mart-vue'

let emojisToShowFilter = function(emoji) {
	// check the emoji properties, see the examples of emoji object below
	return true // return true to include or false to exclude
}
let include = ['people', 'nature']
// or exclude:
// let exclude = ['flags']

const custom = [
	{
		name: 'Octocat',
		short_names: ['octocat'],
		text: '',
		emoticons: [],
		keywords: ['github'],
		imageUrl: 'https://assets-cdn.github.com/images/icons/emoji/octocat.png?v7',
	},
]

let index = new EmojiIndex(data, {
	emojisToShowFilter,
	include,
	exclude,
	custom,
})

Examples of emoji object:

{
  id: 'smiley',
  name: 'Smiling Face with Open Mouth',
  colons: ':smiley:',
  text: ':)',
  emoticons: [
    '=)',
    '=-)'
  ],
  skin: null,
  native: '😃'
}

{
  id: 'santa',
  name: 'Father Christmas',
  colons: ':santa::skin-tone-3:',
  text: '',
  emoticons: [],
  skin: 3,
  native: '🎅🏼'
}

{
  id: 'octocat',
  name: 'Octocat',
  colons: ':octocat',
  text: '',
  emoticons: [],
  custom: true,
  imageUrl: 'https://assets-cdn.github.com/images/icons/emoji/octocat.png?v7'
}

Emoji

import { Emoji } from 'emoji-mart-vue'
<emoji :emoji="{ id: 'santa', skin: 3 }" :size="16" />
<emoji emoji=":santa::skin-tone-3:" :size="16" />
<emoji emoji="santa" set="emojione" :size="16" />
PropRequiredDefaultDescription
emojiEither a string or an emoji object
sizeThe emoji width and height.
nativefalseRenders the native unicode emoji
fallbackParams: (emoji) => {}
setappleThe emoji set: 'apple', 'google', 'twitter', 'emojione'
sheetSize64The emoji sheet size: 16, 20, 32, 64
backgroundImageFn((set, sheetSize) => `https://unpkg.com/emoji-datasource@3.0.0/sheet_${set}_${sheetSize}.png`)A Fn that returns that image sheet to use for emojis. Useful for avoiding a request if you have the sheet locally.
skin1Skin color: 1, 2, 3, 4, 5, 6
tooltipfalseShow emoji short name when hovering (title)
EventDescription
selectParams: (emoji) => {}
mouseenterParams: (emoji) => {}
mouseleaveParams: (emoji) => {}

Unsupported emojis fallback

Certain sets don’t support all emojis (i.e. Messenger & Facebook don’t support :shrug:). 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:

function emojiFallback(emoji) {
	return `:${emoji.short_names[0]}:`
}
<emoji set="messenger" emoji="shrug" :size="24" :fallback="emojiFallback" />

Headless search

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

import { EmojiIndex } from 'emoji-mart-vue'
import data from 'emoji-mart-vue/data/all.json'

const emojiIndex = new EmojiIndex(data)
emojiIndex.search('christmas').map((o) => o.native)
// => [🎄, 🎅🏼, 🔔, 🎁, ⛄️, ❄️]

With custom data

import data from 'emoji-mart-vue/data/messenger'
import { EmojiIndex } from 'emoji-mart-vue'

let emojiIndex = new EmojiIndex(data)
emojiIndex.search('christmas')

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.

import { store } from 'emoji-mart-vue'

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

	setter: (key, value) => {
		// Persist in your own storage (can be async)
	},
})

Possible keys are:

KeyValueDescription
skin1, 2, 3, 4, 5, 6
frequently{ 'astonished': 11, '+1': 22 }An object where the key is the emoji name and the value is the usage count
last'astonished'(Optional) Used by frequently to be sure the latest clicked emoji will always appear in the “Recent” category

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.

Emoticons

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

Results intersection

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

Fully customizable

Anchors color, title and default emoji

Emojis sizes and length

Default skin color

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

It can however be overwritten as per user preference.

Multiple sets supported

Apple / Google / Twitter / EmojiOne / Messenger / Facebook

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.

Development

Build the component and the demo app.

$ npm build
$ npm start

Open docs/index.html in browser to see the demo.

Or serve the dir (with npx and http-server:

hpx http-server ./docs

And open http://127.0.0.1:8080/.

Tests

Run tests with npm run jest.

To debug tests, run npm run jest-debug and then open chrome://inspect in Chrome and open the node inspector client from there.

Building

# Checkout build branch
git checkout build

# Merge latest master into it
git merge master

# Build
npm run build
npm run dev:docs

# Add build files
git add buiid/
git add docs/
git commit -m "Rebuild"

# Push changes
git push origin HEAD

# Tag the new release, add the description for tag
# Hint: refer PRs with #17 (PR id) to later have links to PRs in github releases
git tag 3.1.1 -a

# Push the tags
git push origin --tags

## 🎩 Hat tips!

Original react emoji picker: [missive/emoji-mart](https://github.com/missive/emoji-mart).
Vue port: [jm-david/emoji-mart-vue](https://github.com/jm-david/emoji-mart-vue)

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

5 years ago

5.4.13

5 years ago

5.4.12

5 years ago

5.4.11

5 years ago

5.3.12

5 years ago

5.3.11

5 years ago

5.3.10

5 years ago

5.3.9

5 years ago

2.6.9

5 years ago

2.6.8

5 years ago

2.6.7

5 years ago