emoji-mart-lazyload/src/components/preview.js

128 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-05-31 14:36:52 +00:00
import React from 'react'
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)
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,
i18n,
2018-03-02 20:10:04 +00:00
} = this.props
2016-05-31 14:36:52 +00:00
if (emoji) {
var emojiData = getData(emoji, null, null, this.data),
2017-10-07 04:02:02 +00:00
{ emoticons = [] } = emojiData,
knownEmoticons = [],
listedEmoticons = []
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
}
2017-09-17 08:54:22 +00:00
knownEmoticons.push(emoticon.toLowerCase())
listedEmoticons.push(emoticon)
})
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 &&
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
{showSkinTones && (
<div
className={`emoji-mart-preview-skins${
skinsProps.skinEmoji ? ' custom' : ''
}`}
>
{skinsProps.skinEmoji ? (
<SkinsEmoji
skin={skinsProps.skin}
emojiProps={emojiProps}
data={this.data}
skinEmoji={skinsProps.skinEmoji}
i18n={i18n}
onChange={skinsProps.onChange}
/>
) : (
<SkinsDot
skin={skinsProps.skin}
i18n={i18n}
onChange={skinsProps.onChange}
/>
)}
</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
}