Git Product home page Git Product logo

g-emoji-element's Introduction

<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

import '@github/g-emoji-element'
<g-emoji fallback-src="t-rex.png" alias="T-Rex">๐Ÿฆ–</g-emoji>

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

<g-emoji fallback-src="t-rex.png" alias="T-Rex">
  <img class="emoji" alt="T-Rex" height="20" width="20" src="t-rex.png">
</g-emoji>

Skin tones

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

<g-emoji tone="0">๐Ÿ‘‹</g-emoji>
<g-emoji tone="1">๐Ÿ‘‹๐Ÿป</g-emoji>
<g-emoji tone="2">๐Ÿ‘‹๐Ÿผ</g-emoji>
<g-emoji tone="3">๐Ÿ‘‹๐Ÿฝ</g-emoji>
<g-emoji tone="4">๐Ÿ‘‹๐Ÿพ</g-emoji>
<g-emoji tone="5">๐Ÿ‘‹๐Ÿฟ</g-emoji>
> 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.

<g-emoji tone="4 5">๐Ÿง‘๐Ÿพ<200d>๐Ÿค<200d>๐Ÿง‘๐Ÿฟ</g-emoji>

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

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.