9.2.0 • Published 11 months ago

@ctrl/ngx-emoji-mart v9.2.0

Weekly downloads
20,305
License
MIT
Repository
github
Last release
11 months ago

ngx-emoji-mart

npm codecov

DEMO: https://ngx-emoji-mart.vercel.app

This project is a port of emoji-mart by missive.

Installation

npm install @ctrl/ngx-emoji-mart
# Or if you're using yarn
yarn add @ctrl/ngx-emoji-mart
# Or if you're using pnpm
pnpm install @ctrl/ngx-emoji-mart

Dependencies

Latest version available for each version of Angular

@ctrl/ngx-emoji-martAngular
1.0.68.x
3.1.09.x
5.1.210.x 11.x
6.2.012.x 13.x
7.1.014.x
8.2.015.x
current>=16.x

Components

Picker

Add PickerComponent to your module imports:

import { PickerComponent } from '@ctrl/ngx-emoji-mart';

@NgModule({
  imports: [PickerComponent],
})
export class AppModule {}

// Or if using standalone components

@Component({
  standalone: true,
  imports: [PickerComponent],
})
export class AppComponent {}

Import styles in styles.scss:

@import '@ctrl/ngx-emoji-mart/picker';

Or bundle those styles through angular.json configuration:

"build": {
  "options": {
    "styles": [
      "src/styles.scss",
      "node_modules/@ctrl/ngx-emoji-mart/picker.css"
    ]
  }
}

Now we can use the emoji-mart component:

<emoji-mart title="Pick your emoji…" emoji="point_up"></emoji-mart>
<emoji-mart set="emojione"></emoji-mart>
<emoji-mart (emojiClick)="addEmoji($event)"></emoji-mart>
<emoji-mart [style]="{ position: 'absolute', bottom: '20px', right: '20px' }"></emoji-mart>
<emoji-mart
  [i18n]="{ search: 'Recherche', categories: { search: 'Résultats de recherche', recent: 'Récents' } }"
></emoji-mart>
PropDefaultDescription
autoFocusfalseAuto focus the search input when mounted
color#ae65c5The top bar anchors select and hover color
emojidepartment_storeemoji shown when no emojis are hovered, set to an empty string to show nothing
darkModevariesDark mode (boolean). true by default if the browser reports prefers-color-scheme: dark.
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
emojiSize24The emoji width and height
(emojiClick)not triggered on return key in search bar. Params: { emoji, $event }
(emojiSelect)whenever an emoji is selected. returns { emoji, $event }
perLine9Number of emojis per line. While there’s no minimum or maximum, this will affect the picker’s width. This will set Frequently Used length as well (perLine * totalFrequentLines (4))
totalFrequentLines4number of lines of frequently used emojis
i18n{…}An object containing localized strings
isNativefalseRenders the native unicode emoji
setappleThe emoji set: 'apple', 'google', 'twitter', 'facebook'
sheetSize64The emoji sheet size: 16, 20, 32, 64
backgroundImageFn((set, sheetSize) => …)A Fn that returns that image sheet to use for emojis. Useful for avoiding a request if you have the sheet locally.
imageUrlFn((emoji) => string)A Fn that returns the url used for the given emoji. Useful for fetching your own assets.
emojisToShowFilter((emoji) => true)A Fn to choose whether an emoji should be displayed or not
showPreviewtrueDisplay preview section
enableSearchtrueDisplay search bar
emojiTooltipfalseShow emojis short name when hovering (title)
skin1Default skin color: 1, 2, 3, 4, 5, 6
styleInline styles applied to the root element. Useful for positioning
titleEmoji Mart™The title shown when no emojis are hovered
hideObsoletetrueHides ex: "cop" emoji in favor of female and male emoji
notFoundEmojisleuth_or_spyThe emoji shown when there are no search results
categoriesIconssee svgs/index.tsthe anchor icons
searchIconssee svgs/index.tsthe search/close icon in the search bar
showSingleCategoryshow only one category at a time to increase rendering performance
useButtonfalseUses button elements for emoji instead of spans
enableFrequentEmojiSortfalseEnables re-sorting of emoji on click
virtualizefalseEnables experimental virtualized rendering to render only emoji categories in view
virtualizeOffset0use with virtualize option to add or subtract the amount of pixels used to determine whether or not render the category

I18n

search: 'Search',
emojilist: 'List of emoji',
notfound: 'No Emoji Found',
clear: 'Clear',
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',
},
skintones: {
  1: 'Default Skin Tone',
  2: 'Light Skin Tone',
  3: 'Medium-Light Skin Tone',
  4: 'Medium Skin Tone',
  5: 'Medium-Dark Skin Tone',
  6: 'Dark Skin Tone',
},

Sheet sizes

Sheets are served from unpkg, a global CDN that serves files published to npm.

SetsheetSizeSize
apple16334 KB
apple20459 KB
apple321.08 MB
apple642.94 MB
facebook16322 KB
facebook20439 KB
facebook321020 KB
facebook642.5 MB
google16301 KB
google20409 KB
google32907 KB
google642.17 MB
twitter16288 KB
twitter20389 KB
twitter32839 KB
twitter641.82 MB

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://github.githubassets.com/images/icons/emoji/octocat.png'
}

Emoji

Add EmojiComponent to your module or standalone component imports:

import { EmojiComponent } from '@ctrl/ngx-emoji-mart/ngx-emoji';
<ngx-emoji [emoji]="{ id: 'santa', skin: 3 }" size="16"></ngx-emoji>
<ngx-emoji emoji=":santa::skin-tone-3:" size="16"></ngx-emoji>
<ngx-emoji emoji="santa" set="emojione" size="16"></ngx-emoji>
PropRequiredDefaultDescription
emojiEither a string or an emoji object
sizeThe emoji width and height.
isNativefalseRenders the native unicode emoji
(emojiClick)Params: { emoji, $event }
(emojiLeave)Params: { emoji, $event }
(emojiOver)Params: { emoji, $event }
fallbackParams: (emoji, props) => {}
setappleThe emoji set: 'apple', 'google', 'twitter', 'emojione'
sheetSize64The emoji sheet size: 16, 20, 32, 64
backgroundImageFn((set, sheetSize) => …)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)
hideObsoletefalseHides ex: "cop" emoji in favor of female and male emoji
useButtonfalseUses button element instead of span

Unsupported emojis fallback

Certain sets don’t support all emojis (i.e. Facebook doesn'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:

emojiFallback = (emoji: any, props: any) => (emoji ? `:${emoji.shortNames[0]}:` : props.emoji);
<ngx-emoji set="twitter" emoji="shrug" size="24" [fallback]="emojiFallback"></ngx-emoji>

Custom emojis

You can provide custom emojis which will show up in their own category. You can either use a single image as imageUrl or use a spritesheet as shown in the second object.

const customEmojis = [
  {
    name: 'Octocat',
    shortNames: ['octocat'],
    text: '',
    emoticons: [],
    keywords: ['github'],
    imageUrl: 'https://github.githubassets.com/images/icons/emoji/octocat.png',
  },
  {
    name: 'Test Flag',
    shortNames: ['test'],
    text: '',
    emoticons: [],
    keywords: ['test', 'flag'],
    spriteUrl: 'https://cdn.jsdelivr.net/npm/emoji-datasource-twitter@14.0.0/img/twitter/sheets-256/64.png',
    sheet_x: 1,
    sheet_y: 1,
    size: 64,
    sheetColumns: 61,
    sheetRows: 60,
  },
];
<emoji-mart [custom]="customEmojis"></emoji-mart>

Headless search

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

import { EmojiSearch } from '@ctrl/ngx-emoji-mart';

class ex {
  constructor(private emojiSearch: EmojiSearch) {
    this.emojiSearch.search('christmas').map(o => o.native);
    // => [🎄, 🎅🏼, 🔔, 🎁, ⛄️, ❄️]
  }
}

Display emoji as custom element

// $event is from (emojiClick)
const styles = this.emoji.emojiSpriteStyles($event.emoji.sheet, 'twitter'); // pass emoji sheet
const el = document.createElement('div');
Object.assign(el.style, styles); // apply styles to new element
document.body.appendChild(el);

Storage

By default EmojiMart will store user chosen skin and frequently used emojis in localStorage.

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.

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 / Facebook


GitHub @scttcper  ·  Twitter @scttcper

8.1.0

12 months ago

9.1.1

12 months ago

9.1.0

12 months ago

9.1.2

11 months ago

8.0.0

12 months ago

8.2.0

12 months ago

9.2.0

11 months ago

9.0.0

12 months ago

7.1.0

1 year ago

7.0.0

2 years ago

6.2.0

2 years ago

6.1.0

2 years ago

6.1.1

2 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago

4.0.2

4 years ago

4.0.0

4 years ago

3.1.0

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.17.0

5 years ago

0.16.3

5 years ago

0.16.2

5 years ago

0.16.1

5 years ago

0.16.0

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.1

5 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago