2017-12-24 08:16:45 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { changeSetting } from 'flavours/glitch/actions/settings';
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
|
|
|
import { useEmoji } from 'flavours/glitch/actions/emojis';
|
2017-05-03 03:04:16 +03:00
|
|
|
import React from 'react';
|
2017-04-21 21:05:35 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-02 01:57:55 +02:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-12-04 09:26:40 +02:00
|
|
|
import { EmojiPicker as EmojiPickerAsync } from 'flavours/glitch/util/async-components';
|
2017-10-06 04:24:33 +03:00
|
|
|
import Overlay from 'react-overlays/lib/Overlay';
|
2017-09-23 02:41:00 +03:00
|
|
|
import classNames from 'classnames';
|
2017-09-23 06:40:28 +03:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-09-24 01:40:10 +03:00
|
|
|
import detectPassiveEvents from 'detect-passive-events';
|
2019-06-28 16:54:10 +03:00
|
|
|
import { buildCustomEmojis, categoriesFromEmojis } from 'flavours/glitch/util/emoji';
|
2019-08-12 16:37:00 +03:00
|
|
|
import { useSystemEmojiFont } from 'flavours/glitch/util/initial_state';
|
2017-03-02 01:57:55 +02:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2017-04-22 04:36:33 +03:00
|
|
|
emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' },
|
2017-04-22 18:28:36 +03:00
|
|
|
emoji_search: { id: 'emoji_button.search', defaultMessage: 'Search...' },
|
2017-09-23 02:41:00 +03:00
|
|
|
emoji_not_found: { id: 'emoji_button.not_found', defaultMessage: 'No emojos!! (╯°□°)╯︵ ┻━┻' },
|
|
|
|
custom: { id: 'emoji_button.custom', defaultMessage: 'Custom' },
|
|
|
|
recent: { id: 'emoji_button.recent', defaultMessage: 'Frequently used' },
|
|
|
|
search_results: { id: 'emoji_button.search_results', defaultMessage: 'Search results' },
|
2017-04-22 18:28:36 +03:00
|
|
|
people: { id: 'emoji_button.people', defaultMessage: 'People' },
|
|
|
|
nature: { id: 'emoji_button.nature', defaultMessage: 'Nature' },
|
|
|
|
food: { id: 'emoji_button.food', defaultMessage: 'Food & Drink' },
|
|
|
|
activity: { id: 'emoji_button.activity', defaultMessage: 'Activity' },
|
|
|
|
travel: { id: 'emoji_button.travel', defaultMessage: 'Travel & Places' },
|
|
|
|
objects: { id: 'emoji_button.objects', defaultMessage: 'Objects' },
|
|
|
|
symbols: { id: 'emoji_button.symbols', defaultMessage: 'Symbols' },
|
2017-05-20 18:31:47 +03:00
|
|
|
flags: { id: 'emoji_button.flags', defaultMessage: 'Flags' },
|
2017-03-02 01:57:55 +02:00
|
|
|
});
|
|
|
|
|
2017-12-24 08:16:45 +02:00
|
|
|
const perLine = 8;
|
|
|
|
const lines = 2;
|
|
|
|
|
|
|
|
const DEFAULTS = [
|
|
|
|
'+1',
|
|
|
|
'grinning',
|
|
|
|
'kissing_heart',
|
|
|
|
'heart_eyes',
|
|
|
|
'laughing',
|
|
|
|
'stuck_out_tongue_winking_eye',
|
|
|
|
'sweat_smile',
|
|
|
|
'joy',
|
|
|
|
'yum',
|
|
|
|
'disappointed',
|
|
|
|
'thinking_face',
|
|
|
|
'weary',
|
|
|
|
'sob',
|
|
|
|
'sunglasses',
|
|
|
|
'heart',
|
|
|
|
'ok_hand',
|
|
|
|
];
|
|
|
|
|
|
|
|
const getFrequentlyUsedEmojis = createSelector([
|
|
|
|
state => state.getIn(['settings', 'frequentlyUsedEmojis'], ImmutableMap()),
|
|
|
|
], emojiCounters => {
|
|
|
|
let emojis = emojiCounters
|
|
|
|
.keySeq()
|
|
|
|
.sort((a, b) => emojiCounters.get(a) - emojiCounters.get(b))
|
|
|
|
.reverse()
|
|
|
|
.slice(0, perLine * lines)
|
|
|
|
.toArray();
|
|
|
|
|
|
|
|
if (emojis.length < DEFAULTS.length) {
|
|
|
|
emojis = emojis.concat(DEFAULTS.slice(0, DEFAULTS.length - emojis.length));
|
|
|
|
}
|
|
|
|
|
|
|
|
return emojis;
|
|
|
|
});
|
|
|
|
|
|
|
|
const getCustomEmojis = createSelector([
|
|
|
|
state => state.get('custom_emojis'),
|
|
|
|
], emojis => emojis.filter(e => e.get('visible_in_picker')).sort((a, b) => {
|
|
|
|
const aShort = a.get('shortcode').toLowerCase();
|
|
|
|
const bShort = b.get('shortcode').toLowerCase();
|
|
|
|
|
|
|
|
if (aShort < bShort) {
|
|
|
|
return -1;
|
|
|
|
} else if (aShort > bShort ) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
custom_emojis: getCustomEmojis(state),
|
|
|
|
skinTone: state.getIn(['settings', 'skinTone']),
|
|
|
|
frequentlyUsedEmojis: getFrequentlyUsedEmojis(state),
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, { onPickEmoji }) => ({
|
|
|
|
onSkinTone: skinTone => {
|
|
|
|
dispatch(changeSetting(['skinTone'], skinTone));
|
|
|
|
},
|
|
|
|
|
|
|
|
onPickEmoji: emoji => {
|
|
|
|
dispatch(useEmoji(emoji));
|
|
|
|
|
|
|
|
if (onPickEmoji) {
|
|
|
|
onPickEmoji(emoji);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
const assetHost = process.env.CDN_HOST || '';
|
2017-10-02 08:22:24 +03:00
|
|
|
let EmojiPicker, Emoji; // load asynchronously
|
|
|
|
|
2018-06-13 01:43:50 +03:00
|
|
|
const backgroundImageFn = () => `${assetHost}/emoji/sheet_10.png`;
|
2017-09-24 01:40:10 +03:00
|
|
|
const listenerOptions = detectPassiveEvents.hasSupport ? { passive: true } : false;
|
2017-09-23 02:41:00 +03:00
|
|
|
|
|
|
|
class ModifierPickerMenu extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
active: PropTypes.bool,
|
|
|
|
onSelect: PropTypes.func.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2017-10-03 02:56:50 +03:00
|
|
|
handleClick = e => {
|
|
|
|
this.props.onSelect(e.currentTarget.getAttribute('data-index') * 1);
|
2017-09-23 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (nextProps.active) {
|
|
|
|
this.attachListeners();
|
|
|
|
} else {
|
|
|
|
this.removeListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.removeListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDocumentClick = e => {
|
|
|
|
if (this.node && !this.node.contains(e.target)) {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attachListeners () {
|
|
|
|
document.addEventListener('click', this.handleDocumentClick, false);
|
2017-09-24 01:40:10 +03:00
|
|
|
document.addEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
2017-09-23 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
removeListeners () {
|
|
|
|
document.removeEventListener('click', this.handleDocumentClick, false);
|
2017-09-24 01:40:10 +03:00
|
|
|
document.removeEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
2017-09-23 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2019-03-27 15:04:52 +02:00
|
|
|
const { active } = this.props;
|
2017-09-23 02:41:00 +03:00
|
|
|
|
|
|
|
return (
|
2019-03-27 15:04:52 +02:00
|
|
|
<div className='emoji-picker-dropdown__modifiers__menu' style={{ display: active ? 'block' : 'none' }} ref={this.setRef}>
|
2019-08-12 16:37:00 +03:00
|
|
|
<button onClick={this.handleClick} data-index={1}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={1} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
|
|
|
<button onClick={this.handleClick} data-index={2}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={2} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
|
|
|
<button onClick={this.handleClick} data-index={3}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={3} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
|
|
|
<button onClick={this.handleClick} data-index={4}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={4} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
|
|
|
<button onClick={this.handleClick} data-index={5}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={5} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
|
|
|
<button onClick={this.handleClick} data-index={6}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={6} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
2019-03-27 15:04:52 +02:00
|
|
|
</div>
|
2017-09-23 02:41:00 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ModifierPicker extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
active: PropTypes.bool,
|
|
|
|
modifier: PropTypes.number,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
onClose: PropTypes.func,
|
|
|
|
onOpen: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
if (this.props.active) {
|
|
|
|
this.props.onClose();
|
|
|
|
} else {
|
|
|
|
this.props.onOpen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSelect = modifier => {
|
|
|
|
this.props.onChange(modifier);
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { active, modifier } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='emoji-picker-dropdown__modifiers'>
|
2019-08-12 16:37:00 +03:00
|
|
|
<Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={modifier} onClick={this.handleClick} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} />
|
2019-03-27 15:04:52 +02:00
|
|
|
<ModifierPickerMenu active={active} onSelect={this.handleSelect} onClose={this.props.onClose} />
|
2017-09-23 02:41:00 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@injectIntl
|
|
|
|
class EmojiPickerMenu extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-09-23 06:40:28 +03:00
|
|
|
custom_emojis: ImmutablePropTypes.list,
|
2017-10-08 22:47:15 +03:00
|
|
|
frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.string),
|
2017-10-02 08:22:24 +03:00
|
|
|
loading: PropTypes.bool,
|
2017-09-23 02:41:00 +03:00
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onPick: PropTypes.func.isRequired,
|
|
|
|
style: PropTypes.object,
|
|
|
|
placement: PropTypes.string,
|
|
|
|
arrowOffsetLeft: PropTypes.string,
|
|
|
|
arrowOffsetTop: PropTypes.string,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2017-10-07 20:02:30 +03:00
|
|
|
skinTone: PropTypes.number.isRequired,
|
|
|
|
onSkinTone: PropTypes.func.isRequired,
|
2017-09-23 02:41:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
style: {},
|
2017-10-02 08:22:24 +03:00
|
|
|
loading: true,
|
2017-10-08 22:47:15 +03:00
|
|
|
frequentlyUsedEmojis: [],
|
2017-09-23 02:41:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
modifierOpen: false,
|
2018-05-05 17:58:20 +03:00
|
|
|
placement: null,
|
2017-09-23 02:41:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
handleDocumentClick = e => {
|
|
|
|
if (this.node && !this.node.contains(e.target)) {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
document.addEventListener('click', this.handleDocumentClick, false);
|
2017-09-24 01:40:10 +03:00
|
|
|
document.addEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
2017-09-23 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
document.removeEventListener('click', this.handleDocumentClick, false);
|
2017-09-24 01:40:10 +03:00
|
|
|
document.removeEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
2017-09-23 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
getI18n = () => {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return {
|
|
|
|
search: intl.formatMessage(messages.emoji_search),
|
|
|
|
notfound: intl.formatMessage(messages.emoji_not_found),
|
|
|
|
categories: {
|
|
|
|
search: intl.formatMessage(messages.search_results),
|
|
|
|
recent: intl.formatMessage(messages.recent),
|
|
|
|
people: intl.formatMessage(messages.people),
|
|
|
|
nature: intl.formatMessage(messages.nature),
|
|
|
|
foods: intl.formatMessage(messages.food),
|
|
|
|
activity: intl.formatMessage(messages.activity),
|
|
|
|
places: intl.formatMessage(messages.travel),
|
|
|
|
objects: intl.formatMessage(messages.objects),
|
|
|
|
symbols: intl.formatMessage(messages.symbols),
|
|
|
|
flags: intl.formatMessage(messages.flags),
|
|
|
|
custom: intl.formatMessage(messages.custom),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick = emoji => {
|
2017-09-23 06:40:28 +03:00
|
|
|
if (!emoji.native) {
|
|
|
|
emoji.native = emoji.colons;
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
this.props.onClose();
|
|
|
|
this.props.onPick(emoji);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModifierOpen = () => {
|
|
|
|
this.setState({ modifierOpen: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModifierClose = () => {
|
|
|
|
this.setState({ modifierOpen: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModifierChange = modifier => {
|
2017-10-07 20:02:30 +03:00
|
|
|
this.props.onSkinTone(modifier);
|
2017-09-23 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-10-31 23:58:07 +02:00
|
|
|
const { loading, style, intl, custom_emojis, skinTone, frequentlyUsedEmojis } = this.props;
|
2017-10-02 08:22:24 +03:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <div style={{ width: 299 }} />;
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
const title = intl.formatMessage(messages.emoji);
|
2019-06-28 16:54:10 +03:00
|
|
|
|
2017-10-07 20:02:30 +03:00
|
|
|
const { modifierOpen } = this.state;
|
2017-09-23 02:41:00 +03:00
|
|
|
|
2019-06-28 16:54:10 +03:00
|
|
|
const categoriesSort = [
|
|
|
|
'recent',
|
|
|
|
'people',
|
|
|
|
'nature',
|
|
|
|
'foods',
|
|
|
|
'activity',
|
|
|
|
'places',
|
|
|
|
'objects',
|
|
|
|
'symbols',
|
|
|
|
'flags',
|
|
|
|
];
|
|
|
|
|
|
|
|
categoriesSort.splice(1, 0, ...Array.from(categoriesFromEmojis(custom_emojis)).sort());
|
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
return (
|
|
|
|
<div className={classNames('emoji-picker-dropdown__menu', { selecting: modifierOpen })} style={style} ref={this.setRef}>
|
2017-10-02 08:22:24 +03:00
|
|
|
<EmojiPicker
|
2017-09-23 02:41:00 +03:00
|
|
|
perLine={8}
|
|
|
|
emojiSize={22}
|
|
|
|
sheetSize={32}
|
2017-10-31 23:58:07 +02:00
|
|
|
custom={buildCustomEmojis(custom_emojis)}
|
2017-09-23 02:41:00 +03:00
|
|
|
color=''
|
|
|
|
emoji=''
|
|
|
|
set='twitter'
|
|
|
|
title={title}
|
|
|
|
i18n={this.getI18n()}
|
|
|
|
onClick={this.handleClick}
|
2017-10-07 20:02:30 +03:00
|
|
|
include={categoriesSort}
|
2017-10-08 22:47:15 +03:00
|
|
|
recent={frequentlyUsedEmojis}
|
2017-10-07 20:02:30 +03:00
|
|
|
skin={skinTone}
|
2017-10-03 02:56:50 +03:00
|
|
|
showPreview={false}
|
2017-09-23 02:41:00 +03:00
|
|
|
backgroundImageFn={backgroundImageFn}
|
2018-09-13 12:55:41 +03:00
|
|
|
autoFocus
|
2017-10-08 22:47:15 +03:00
|
|
|
emojiTooltip
|
2019-08-12 16:37:00 +03:00
|
|
|
native={useSystemEmojiFont}
|
2017-09-23 02:41:00 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
<ModifierPicker
|
|
|
|
active={modifierOpen}
|
2017-10-07 20:02:30 +03:00
|
|
|
modifier={skinTone}
|
2017-09-23 02:41:00 +03:00
|
|
|
onOpen={this.handleModifierOpen}
|
|
|
|
onClose={this.handleModifierClose}
|
|
|
|
onChange={this.handleModifierChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-05-07 03:42:38 +03:00
|
|
|
|
2017-12-24 08:16:45 +02:00
|
|
|
@connect(mapStateToProps, mapDispatchToProps)
|
2017-06-23 20:36:54 +03:00
|
|
|
@injectIntl
|
|
|
|
export default class EmojiPickerDropdown extends React.PureComponent {
|
2017-03-02 01:57:55 +02:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
static propTypes = {
|
2017-09-23 06:40:28 +03:00
|
|
|
custom_emojis: ImmutablePropTypes.list,
|
2017-10-08 22:47:15 +03:00
|
|
|
frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.string),
|
2017-05-12 15:44:10 +03:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-20 18:31:47 +03:00
|
|
|
onPickEmoji: PropTypes.func.isRequired,
|
2017-10-07 20:02:30 +03:00
|
|
|
onSkinTone: PropTypes.func.isRequired,
|
|
|
|
skinTone: PropTypes.number.isRequired,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
active: false,
|
2017-10-02 08:22:24 +03:00
|
|
|
loading: false,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
2017-03-02 01:57:55 +02:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
setRef = (c) => {
|
2017-03-02 01:57:55 +02:00
|
|
|
this.dropdown = c;
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|
2017-03-02 01:57:55 +02:00
|
|
|
|
2018-05-05 17:58:20 +03:00
|
|
|
onShowDropdown = ({ target }) => {
|
2017-06-01 18:25:10 +03:00
|
|
|
this.setState({ active: true });
|
2017-10-02 08:22:24 +03:00
|
|
|
|
|
|
|
if (!EmojiPicker) {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
|
|
EmojiPickerAsync().then(EmojiMart => {
|
|
|
|
EmojiPicker = EmojiMart.Picker;
|
2017-10-07 20:02:30 +03:00
|
|
|
Emoji = EmojiMart.Emoji;
|
|
|
|
|
2017-10-02 08:22:24 +03:00
|
|
|
this.setState({ loading: false });
|
|
|
|
}).catch(() => {
|
|
|
|
this.setState({ loading: false });
|
|
|
|
});
|
|
|
|
}
|
2018-05-05 17:58:20 +03:00
|
|
|
|
|
|
|
const { top } = target.getBoundingClientRect();
|
|
|
|
this.setState({ placement: top * 2 < innerHeight ? 'bottom' : 'top' });
|
2017-05-07 03:42:38 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
onHideDropdown = () => {
|
2017-06-01 18:25:10 +03:00
|
|
|
this.setState({ active: false });
|
2017-05-07 03:42:38 +03:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:37:30 +03:00
|
|
|
onToggle = (e) => {
|
2017-10-02 08:22:24 +03:00
|
|
|
if (!this.state.loading && (!e.key || e.key === 'Enter')) {
|
2017-07-28 05:37:30 +03:00
|
|
|
if (this.state.active) {
|
|
|
|
this.onHideDropdown();
|
|
|
|
} else {
|
2018-05-05 17:58:20 +03:00
|
|
|
this.onShowDropdown(e);
|
2017-07-28 05:37:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
handleKeyDown = e => {
|
2017-07-28 05:37:30 +03:00
|
|
|
if (e.key === 'Escape') {
|
|
|
|
this.onHideDropdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
setTargetRef = c => {
|
|
|
|
this.target = c;
|
|
|
|
}
|
2017-03-02 01:57:55 +02:00
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
findTarget = () => {
|
|
|
|
return this.target;
|
|
|
|
}
|
2017-04-22 18:28:36 +03:00
|
|
|
|
2017-09-23 02:41:00 +03:00
|
|
|
render () {
|
2017-10-31 23:58:07 +02:00
|
|
|
const { intl, onPickEmoji, onSkinTone, skinTone, frequentlyUsedEmojis } = this.props;
|
2017-07-28 05:37:30 +03:00
|
|
|
const title = intl.formatMessage(messages.emoji);
|
2018-05-05 17:58:20 +03:00
|
|
|
const { active, loading, placement } = this.state;
|
2017-05-07 03:42:38 +03:00
|
|
|
|
2017-03-02 01:57:55 +02:00
|
|
|
return (
|
2017-09-23 02:41:00 +03:00
|
|
|
<div className='emoji-picker-dropdown' onKeyDown={this.handleKeyDown}>
|
|
|
|
<div ref={this.setTargetRef} className='emoji-button' title={title} aria-label={title} aria-expanded={active} role='button' onClick={this.onToggle} onKeyDown={this.onToggle} tabIndex={0}>
|
2017-06-06 14:20:07 +03:00
|
|
|
<img
|
2017-10-02 08:22:24 +03:00
|
|
|
className={classNames('emojione', { 'pulse-loading': active && loading })}
|
2017-07-14 20:47:53 +03:00
|
|
|
alt='🙂'
|
2017-09-23 02:41:00 +03:00
|
|
|
src={`${assetHost}/emoji/1f602.svg`}
|
2017-06-06 14:20:07 +03:00
|
|
|
/>
|
2017-09-23 02:41:00 +03:00
|
|
|
</div>
|
|
|
|
|
2018-05-05 17:58:20 +03:00
|
|
|
<Overlay show={active} placement={placement} target={this.findTarget}>
|
2017-09-23 06:40:28 +03:00
|
|
|
<EmojiPickerMenu
|
|
|
|
custom_emojis={this.props.custom_emojis}
|
2017-10-02 08:22:24 +03:00
|
|
|
loading={loading}
|
2017-09-23 06:40:28 +03:00
|
|
|
onClose={this.onHideDropdown}
|
|
|
|
onPick={onPickEmoji}
|
2017-10-07 20:02:30 +03:00
|
|
|
onSkinTone={onSkinTone}
|
|
|
|
skinTone={skinTone}
|
2017-10-08 22:47:15 +03:00
|
|
|
frequentlyUsedEmojis={frequentlyUsedEmojis}
|
2017-09-23 06:40:28 +03:00
|
|
|
/>
|
2017-09-23 02:41:00 +03:00
|
|
|
</Overlay>
|
|
|
|
</div>
|
2017-03-02 01:57:55 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|