import {React, ReactDOM} from 'nylas-exports'; import emoji from 'node-emoji'; import EmojiStore from './emoji-store'; import EmojiActions from './emoji-actions'; class EmojiPicker extends React.Component { static displayName = "EmojiPicker"; static propTypes = { emojiOptions: React.PropTypes.array, selectedEmoji: React.PropTypes.string, }; constructor(props) { super(props); this.state = {}; } componentDidUpdate() { const selectedButton = ReactDOM.findDOMNode(this).querySelector(".emoji-option"); if (selectedButton) { selectedButton.scrollIntoViewIfNeeded(); } } onMouseDown(emojiName) { EmojiActions.selectEmoji({emojiName, replaceSelection: true}); } render() { const emojiButtons = []; let emojiIndex = this.props.emojiOptions.indexOf(this.props.selectedEmoji); if (emojiIndex === -1) emojiIndex = 0; if (this.props.emojiOptions) { this.props.emojiOptions.forEach((emojiOption, i) => { const emojiClass = emojiIndex === i ? "btn btn-icon emoji-option" : "btn btn-icon"; let emojiChar = emoji.get(emojiOption); emojiChar = ( {emojiOption} ); emojiButtons.push( ); emojiButtons.push(
); }); } return (
{emojiButtons}
); } } export default EmojiPicker;