2016-05-31 14:36:52 +00:00
|
|
|
import React from 'react'
|
2017-05-05 01:38:03 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2016-07-19 16:27:24 +00:00
|
|
|
|
2018-04-30 00:55:13 +00:00
|
|
|
import { getData } from '../utils'
|
2018-11-13 10:21:07 +00:00
|
|
|
import NimbleEmoji from './emoji/nimble-emoji'
|
|
|
|
import SkinsEmoji from './skins-emoji'
|
|
|
|
import SkinsDot from './skins-dot'
|
2016-05-31 14:36:52 +00:00
|
|
|
|
2018-04-30 00:55:13 +00:00
|
|
|
export default class Preview extends React.PureComponent {
|
2016-05-31 14:36:52 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2018-03-28 21:30:47 +00:00
|
|
|
|
|
|
|
this.data = props.data
|
2016-05-31 14:36:52 +00:00
|
|
|
this.state = { emoji: null }
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
var { emoji } = this.state,
|
2018-03-02 20:10:04 +00:00
|
|
|
{
|
|
|
|
emojiProps,
|
|
|
|
skinsProps,
|
|
|
|
showSkinTones,
|
|
|
|
title,
|
|
|
|
emoji: idleEmoji,
|
2018-07-05 21:00:57 +00:00
|
|
|
i18n,
|
2018-03-02 20:10:04 +00:00
|
|
|
} = this.props
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
|
|
if (emoji) {
|
2018-03-28 21:30:47 +00:00
|
|
|
var emojiData = getData(emoji, null, null, this.data),
|
2017-10-07 04:02:02 +00:00
|
|
|
{ emoticons = [] } = emojiData,
|
|
|
|
knownEmoticons = [],
|
|
|
|
listedEmoticons = []
|
2016-07-07 21:05:37 +00:00
|
|
|
|
2018-03-27 18:51:26 +00:00
|
|
|
emoticons.forEach((emoticon) => {
|
2017-09-17 08:54:22 +00:00
|
|
|
if (knownEmoticons.indexOf(emoticon.toLowerCase()) >= 0) {
|
|
|
|
return
|
2016-07-07 21:05:37 +00:00
|
|
|
}
|
2017-09-17 08:54:22 +00:00
|
|
|
|
|
|
|
knownEmoticons.push(emoticon.toLowerCase())
|
|
|
|
listedEmoticons.push(emoticon)
|
|
|
|
})
|
2016-07-07 21:05:37 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
return (
|
|
|
|
<div className="emoji-mart-preview">
|
|
|
|
<div className="emoji-mart-preview-emoji">
|
2018-04-26 14:36:54 +00:00
|
|
|
{NimbleEmoji({
|
|
|
|
key: emoji.id,
|
|
|
|
emoji: emoji,
|
|
|
|
data: this.data,
|
|
|
|
...emojiProps,
|
|
|
|
})}
|
2016-07-12 20:52:18 +00:00
|
|
|
</div>
|
2017-10-07 04:02:02 +00:00
|
|
|
|
|
|
|
<div className="emoji-mart-preview-data">
|
|
|
|
<div className="emoji-mart-preview-name">{emoji.name}</div>
|
|
|
|
<div className="emoji-mart-preview-shortnames">
|
2018-03-27 18:51:26 +00:00
|
|
|
{emojiData.short_names.map((short_name) => (
|
2017-10-07 04:02:02 +00:00
|
|
|
<span key={short_name} className="emoji-mart-preview-shortname">
|
|
|
|
:{short_name}:
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div className="emoji-mart-preview-emoticons">
|
2018-03-27 18:51:26 +00:00
|
|
|
{listedEmoticons.map((emoticon) => (
|
2017-10-07 04:02:02 +00:00
|
|
|
<span key={emoticon} className="emoji-mart-preview-emoticon">
|
|
|
|
{emoticon}
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</div>
|
2016-07-12 20:52:18 +00:00
|
|
|
</div>
|
2016-05-31 14:36:52 +00:00
|
|
|
</div>
|
2017-10-07 04:02:02 +00:00
|
|
|
)
|
2016-05-31 14:36:52 +00:00
|
|
|
} else {
|
2017-10-07 04:02:02 +00:00
|
|
|
return (
|
|
|
|
<div className="emoji-mart-preview">
|
|
|
|
<div className="emoji-mart-preview-emoji">
|
|
|
|
{idleEmoji &&
|
|
|
|
idleEmoji.length &&
|
2018-03-28 21:30:47 +00:00
|
|
|
NimbleEmoji({ emoji: idleEmoji, data: this.data, ...emojiProps })}
|
2017-10-07 04:02:02 +00:00
|
|
|
</div>
|
2016-06-01 13:53:45 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
<div className="emoji-mart-preview-data">
|
|
|
|
<span className="emoji-mart-title-label">{title}</span>
|
|
|
|
</div>
|
2016-06-09 00:22:06 +00:00
|
|
|
|
2018-03-02 20:08:52 +00:00
|
|
|
{showSkinTones && (
|
2018-07-05 21:00:57 +00:00
|
|
|
<div
|
|
|
|
className={`emoji-mart-preview-skins${
|
2018-08-10 18:11:28 +00:00
|
|
|
skinsProps.skinEmoji ? ' custom' : ''
|
2018-07-05 21:00:57 +00:00
|
|
|
}`}
|
|
|
|
>
|
2018-08-10 18:11:28 +00:00
|
|
|
{skinsProps.skinEmoji ? (
|
2018-07-05 21:00:57 +00:00
|
|
|
<SkinsEmoji
|
|
|
|
skin={skinsProps.skin}
|
|
|
|
emojiProps={emojiProps}
|
|
|
|
data={this.data}
|
2018-08-10 18:11:28 +00:00
|
|
|
skinEmoji={skinsProps.skinEmoji}
|
2018-07-05 21:00:57 +00:00
|
|
|
i18n={i18n}
|
|
|
|
onChange={skinsProps.onChange}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<SkinsDot
|
|
|
|
skin={skinsProps.skin}
|
|
|
|
i18n={i18n}
|
|
|
|
onChange={skinsProps.onChange}
|
|
|
|
/>
|
|
|
|
)}
|
2018-03-02 20:08:52 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2016-06-09 00:22:06 +00:00
|
|
|
</div>
|
2017-10-07 04:02:02 +00:00
|
|
|
)
|
2016-05-31 14:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-30 00:55:13 +00:00
|
|
|
Preview.propTypes = {
|
|
|
|
showSkinTones: PropTypes.bool,
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
emoji: PropTypes.string.isRequired,
|
|
|
|
emojiProps: PropTypes.object.isRequired,
|
|
|
|
skinsProps: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
Preview.defaultProps = {
|
|
|
|
showSkinTones: true,
|
|
|
|
onChange: () => {},
|
2018-04-26 14:36:54 +00:00
|
|
|
}
|