Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/github/g-emoji-element

Backports native emoji characters to browsers that don't support them by replacing the characters with fallback images.
https://github.com/github/g-emoji-element

custom-elements emoji web-components

Last synced: about 1 month ago
JSON representation

Backports native emoji characters to browsers that don't support them by replacing the characters with fallback images.

Awesome Lists containing this project

README

        

# <g-emoji> element

Backports native emoji characters to browsers that don't support them by replacing the characters with fallback images.

## Installation

```
$ npm install @github/g-emoji-element
```

## Usage

```js
import '@github/g-emoji-element'
```

```html
🦖
```

If a browser supports emoji, nothing happens. If a browser does not support emoji, a fallback image tag is created:

```html

T-Rex

```

### Skin tones

The `tone` attribute renders the emoji with a [skin tone modifier][scale] between 1-5. Use
0 to display the default tone.

[scale]: https://en.wikipedia.org/wiki/Fitzpatrick_scale

```html
👋
👋🏻
👋🏼
👋🏽
👋🏾
👋🏿
```

```js
> const emoji = document.createElement('g-emoji')
> emoji.textContent = '👋'
> emoji.tone = '5'
> document.body.append(emoji)
> emoji.textContent
"👋🏿"
```

The `tone` attribute accepts a space separated list of skin tone modifiers to apply
to each base emoji in a sequence. Some platforms will display these sequences
as a single glyph while others will render each emoji in the sequence.

```html
🧑🏾<200d>🤝<200d>🧑🏿
```

## Browser support

Browsers without native [custom element support][support] require a [polyfill][].

- Chrome
- Firefox
- Safari
- Microsoft Edge

[support]: https://caniuse.com/#feat=custom-elementsv1
[polyfill]: https://github.com/webcomponents/custom-elements

## Development

```
npm install
npm test
```

## License

Distributed under the MIT license. See LICENSE for details.