2016-03-29 16:41:24 +08:00
|
|
|
import {React, ReactDOM} from 'nylas-exports';
|
2016-04-13 01:27:24 +08:00
|
|
|
|
|
|
|
import EmojiStore from './emoji-store';
|
2016-03-25 01:42:44 +08:00
|
|
|
import EmojiActions from './emoji-actions';
|
|
|
|
import emoji from 'node-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-03-29 16:41:24 +08:00
|
|
|
const selectedButton = ReactDOM.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);
|
2016-04-13 01:27:24 +08:00
|
|
|
emojiChar = (<img
|
|
|
|
src={EmojiStore.getImagePath(emojiOption)}
|
|
|
|
width="16"
|
|
|
|
height="16"
|
|
|
|
style={{marginTop: "-4px", marginRight: "3px"}} />);
|
2016-03-25 01:42:44 +08:00
|
|
|
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;
|