Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/yosuke-furukawa/react-twemojify

React Component using twemoji parser, support webcomponents ( amp-img etc).
https://github.com/yosuke-furukawa/react-twemojify

Last synced: 17 days ago
JSON representation

React Component using twemoji parser, support webcomponents ( amp-img etc).

Awesome Lists containing this project

README

        

# react-twemojify

![CI](https://github.com/yosuke-furukawa/react-twemojify/workflows/CI/badge.svg)

A React Component converts emoji (like 🙆) to img tag `` .

- Support web component img tag, like `amp-img`.

# install

```
$ npm i react-twemojify
```

# usage

## using basic img tag

```js
const { twemojify } = require('react-twemojify');
const { createImgElement } = require('react-twemojify/lib/img');
const result = twemojify('Hello World 🙆', createImgElement);

// Hello World 🙆
console.log(result);
```

## using amp-img tag

```js
const { twemojify } = require('react-twemojify');
const { createImgElement } = require('react-twemojify/lib/amp-img');
const result = twemojify('Hello World 🙆', createImgElement);

// Hello World
console.log(result);
```

## custom webcomponent tag

```js
const { twemojify } = require('react-twemojify');
const createImgElement = ({
url,
size,
className,
alt,
key,
}) => {
return React.createElement("x-some-special-webcomponent-img", {
key,
width: size,
height: size,
class: className,
src: url,
alt,
});
};
const result = twemojify('Hello World 🙆', createImgElement);

// Hello World
console.log(result);
```

# options

- size: number, default 32, width and height are changed if `size` is specified.
- class: classname, default emoji, class name is changed if `class` is specified.
- style: react style properties, default is null.