Format emoji data on click

exclude-unsupported-native-emojis
Etienne Lemay 2016-05-31 20:29:37 -04:00
parent 035653cbca
commit 030251f2dc
1 changed files with 37 additions and 2 deletions

View File

@ -42,6 +42,8 @@ export default class Emoji extends React.Component {
kit = kitMatches[0] kit = kitMatches[0]
if (variationData[`has_img_${kit}`]) { if (variationData[`has_img_${kit}`]) {
emojiData.skin_tone = skin
for (let k in variationData) { for (let k in variationData) {
let v = variationData[k] let v = variationData[k]
emojiData[k] = v emojiData[k] = v
@ -68,12 +70,45 @@ export default class Emoji extends React.Component {
return `-${x}px -${y}px` return `-${x}px -${y}px`
} }
getNative(emojiData) {
var { unified } = emojiData,
unicodes = unified.split('-'),
codePoints = unicodes.map((u) => `0x${u}`)
return String.fromCodePoint(...codePoints)
}
handleClick(emojiData) {
var { onClick } = this.props,
{ name, short_names, skin_tone, text, texts, unified } = emojiData,
id = short_names[0],
colons = `:${id}:`
texts || (texts = [])
if (text && !texts.length) {
texts = [text]
}
if (skin_tone) {
colons += `:skin-tone-${skin_tone}:`
}
onClick({
id,
name,
colons,
skin: skin_tone || 1,
emoticons: texts,
native: this.getNative(emojiData),
})
}
render() { render() {
var { sheetURL, size, onOver, onLeave, onClick } = this.props, var { sheetURL, size, onOver, onLeave } = this.props,
emojiData = this.getEmojiData() emojiData = this.getEmojiData()
return <span return <span
onClick={() => onClick(emojiData)} onClick={() => this.handleClick(emojiData)}
onMouseEnter={() => onOver(emojiData)} onMouseEnter={() => onOver(emojiData)}
onMouseLeave={() => onLeave(emojiData)} onMouseLeave={() => onLeave(emojiData)}
className='emoji-picker-emoji'> className='emoji-picker-emoji'>