2016-03-25 01:42:44 +08:00
|
|
|
import {React} from 'nylas-exports';
|
|
|
|
import EmojiActions from './emoji-actions';
|
|
|
|
import emoji from 'node-emoji';
|
|
|
|
import missingEmojiList from './missing-emoji';
|
|
|
|
|
2016-02-04 07:05:14 +08:00
|
|
|
|
|
|
|
class EmojiPicker extends React.Component {
|
2016-02-18 06:54:43 +08:00
|
|
|
static displayName = "EmojiPicker";
|
2016-02-04 07:05:14 +08:00
|
|
|
static propTypes = {
|
|
|
|
emojiOptions: React.PropTypes.array,
|
2016-02-04 09:40:28 +08:00
|
|
|
selectedEmoji: React.PropTypes.string,
|
2016-02-04 07:05:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
2016-02-04 09:40:28 +08:00
|
|
|
const selectedButton = React.findDOMNode(this).querySelector(".emoji-option");
|
2016-02-04 07:05:14 +08:00
|
|
|
if (selectedButton) {
|
|
|
|
selectedButton.scrollIntoViewIfNeeded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:42:44 +08:00
|
|
|
onMouseDown(emojiName) {
|
|
|
|
EmojiActions.selectEmoji({emojiName, replaceSelection: true});
|
2016-02-04 09:40:28 +08:00
|
|
|
}
|
|
|
|
|
2016-02-04 07:05:14 +08:00
|
|
|
render() {
|
2016-03-16 04:37:31 +08:00
|
|
|
const emojiButtons = [];
|
2016-02-04 09:40:28 +08:00
|
|
|
let emojiIndex = this.props.emojiOptions.indexOf(this.props.selectedEmoji);
|
|
|
|
if (emojiIndex === -1) emojiIndex = 0;
|
2016-02-04 07:05:14 +08:00
|
|
|
if (this.props.emojiOptions) {
|
2016-02-04 09:40:28 +08:00
|
|
|
this.props.emojiOptions.forEach((emojiOption, i) => {
|
|
|
|
const emojiClass = emojiIndex === i ? "btn btn-icon emoji-option" : "btn btn-icon";
|
2016-03-25 01:42:44 +08:00
|
|
|
let emojiChar = emoji.get(emojiOption);
|
|
|
|
if (missingEmojiList.indexOf(emojiOption) !== -1) {
|
|
|
|
emojiChar = (<img
|
|
|
|
src={`images/composer-emoji/missing-emoji/${emojiOption}.png`}
|
|
|
|
width="16"
|
|
|
|
height="16"
|
|
|
|
style={{marginTop: "-4px", marginRight: "3px"}} />);
|
|
|
|
}
|
|
|
|
emojiButtons.push(
|
|
|
|
<button
|
|
|
|
key={emojiOption}
|
|
|
|
onMouseDown={() => this.onMouseDown(emojiOption)}
|
|
|
|
className={emojiClass}>
|
|
|
|
{emojiChar} :{emojiOption}:
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
emojiButtons.push(<br key={emojiOption + " br"} />);
|
|
|
|
});
|
2016-02-04 07:05:14 +08:00
|
|
|
}
|
2016-02-04 09:40:28 +08:00
|
|
|
return (
|
2016-02-04 07:05:14 +08:00
|
|
|
<div className="emoji-picker">
|
2016-03-16 04:37:31 +08:00
|
|
|
{emojiButtons}
|
2016-02-04 07:05:14 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default EmojiPicker;
|