This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathemoji.jsx
64 lines (58 loc) · 1.43 KB
/
emoji.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { Component } from "react";
import PropTypes from "prop-types";
import pick from "lodash/pick";
import emojione from "emojione";
export default class Emoji extends Component {
static propTypes = {
ariaLabel: PropTypes.string,
name: PropTypes.string,
onSelect: PropTypes.func.isRequired,
shortname: PropTypes.string,
title: PropTypes.string,
role: PropTypes.string
};
shouldComponentUpdate(nextProps) {
// avoid rerendering the Emoji component if the shortname hasn't changed
return nextProps.shortname !== this.props.shortname;
}
createMarkup() {
return { __html: emojione.shortnameToImage(this.props.shortname) };
}
_handleKeyUp = ev => {
ev.preventDefault();
if (ev.key === "Enter" || ev.key === " ") {
this._handleClick(ev);
}
};
_handleClick = ev => {
this.props.onSelect(
ev,
pick(
this.props,
"shortname",
"aliases",
"aliases_ascii",
"category",
"name",
"shortcode",
"unicode",
"unicode_alternates",
"keywords"
)
);
};
render() {
return (
<div
onKeyUp={this._handleKeyUp}
onClick={this._handleClick}
tabIndex="0"
className="emoji"
aria-label={this.props.ariaLabel}
title={this.props.name}
role={this.props.role}
dangerouslySetInnerHTML={this.createMarkup()}
/>
);
}
}