chuckya/app/javascript/mastodon/features/compose/components/autosuggest_shortcode.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-21 03:21:09 +09:00
import React from 'react';
import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types';
import emojione from 'emojione';
// This is bad, but I don't know how to make it work without importing the entirety of emojione.
// taken from some old version of mastodon before they gutted emojione to "emojione_light"
const shortnameToImage = str => str.replace(emojione.regShortNames, shortname => {
if (typeof shortname === 'undefined' || shortname === '' || !(shortname in emojione.emojioneList)) {
return shortname;
}
const unicode = emojione.emojioneList[shortname].unicode[emojione.emojioneList[shortname].unicode.length - 1];
const alt = emojione.convert(unicode.toUpperCase());
return `<img draggable="false" class="emojione" alt="${alt}" src="/emoji/${unicode}.svg" />`;
});
export default class AutosuggestShortcode extends ImmutablePureComponent {
static propTypes = {
shortcode: PropTypes.string.isRequired,
};
render () {
const { shortcode } = this.props;
let emoji = shortnameToImage(shortcode);
return (
<div className='autosuggest-account'>
<div className='autosuggest-account-icon' dangerouslySetInnerHTML={{ __html: emoji }} />
{shortcode}
</div>
);
}
}