Revert Emoji back to a functional component

nolan/hinaloe-test
Etienne Lemay 2017-09-30 11:37:02 -04:00
parent fdb88daa31
commit 22d1a0375d
3 changed files with 79 additions and 88 deletions

View File

@ -146,20 +146,20 @@ export default class Category extends React.Component {
</div> </div>
{emojis && emojis.map((emoji) => {emojis && emojis.map((emoji) =>
<Emoji emoji={emoji} {...emojiProps} /> Emoji({ emoji: emoji, ...emojiProps })
)} )}
{emojis && !emojis.length && {emojis && !emojis.length &&
<div> <div>
<div> <div>
<Emoji {Emoji({
{...emojiProps} ...emojiProps,
size={38} size: 38,
emoji='sleuth_or_spy' emoji: 'sleuth_or_spy',
onOver={null} onOver: null,
onLeave={null} onLeave: null,
onClick={null} onClick: null,
/> })}
</div> </div>
<div className='emoji-mart-no-results-label'> <div className='emoji-mart-no-results-label'>

View File

@ -23,45 +23,36 @@ const _getSanitizedData = (props) => {
return getSanitizedData(emoji, skin, set) return getSanitizedData(emoji, skin, set)
} }
export default class Emoji extends React.PureComponent { const _handleClick = (e, props) => {
if (!props.onClick) { return }
constructor (props) { var { onClick } = props,
super(props) emoji = _getSanitizedData(props)
this.handleClick = this.handleClick.bind(this)
this.handleEnter = this.handleEnter.bind(this)
this.handleLeave = this.handleLeave.bind(this)
}
handleClick (e) {
if (!this.props.onClick) { return }
const { onClick } = this.props,
emoji = _getSanitizedData(this.props)
onClick(emoji, e) onClick(emoji, e)
} }
handleEnter (e) { const _handleOver = (e, props) => {
if (!this.props.onOver) { return } if (!props.onOver) { return }
var { onOver } = props,
const { onOver } = this.props, emoji = _getSanitizedData(props)
emoji = _getSanitizedData(this.props)
onOver(emoji, e) onOver(emoji, e)
} }
handleLeave (e) { const _handleLeave = (e, props) => {
if (!this.props.onLeave) { return } if (!props.onLeave) { return }
var { onLeave } = props,
const { onLeave } = this.props, emoji = _getSanitizedData(props)
emoji = _getSanitizedData(this.props)
onLeave(emoji, e) onLeave(emoji, e)
} }
render () { const Emoji = (props) => {
var props = this.props; for (let k in Emoji.defaultProps) {
if (props[k] == undefined && Emoji.defaultProps[k] != undefined) {
props[k] = Emoji.defaultProps[k]
}
}
var { unified, custom, imageUrl } = _getData(props), var { unified, custom, imageUrl } = _getData(props),
style = {}, style = {},
@ -107,14 +98,12 @@ export default class Emoji extends React.PureComponent {
return <span return <span
key={props.emoji.id || props.emoji} key={props.emoji.id || props.emoji}
onClick={this.handleClick} onClick={(e) => _handleClick(e, props)}
onMouseEnter={this.handleEnter} onMouseEnter={(e) => _handleOver(e, props)}
onMouseLeave={this.handleLeave} onMouseLeave={(e) => _handleLeave(e, props)}
className='emoji-mart-emoji'> className='emoji-mart-emoji'>
<span style={style}>{children}</span> <span style={style}>{children}</span>
</span> </span>
}
} }
Emoji.propTypes = { Emoji.propTypes = {
@ -145,3 +134,5 @@ Emoji.defaultProps = {
onLeave: (() => {}), onLeave: (() => {}),
onClick: (() => {}), onClick: (() => {}),
} }
export default Emoji

View File

@ -31,7 +31,7 @@ export default class Preview extends React.PureComponent {
return <div className='emoji-mart-preview'> return <div className='emoji-mart-preview'>
<div className='emoji-mart-preview-emoji'> <div className='emoji-mart-preview-emoji'>
<Emoji key={emoji.id} emoji={emoji} {...emojiProps} /> {Emoji({ key: emoji.id, emoji: emoji, ...emojiProps })}
</div> </div>
<div className='emoji-mart-preview-data'> <div className='emoji-mart-preview-data'>
@ -51,7 +51,7 @@ export default class Preview extends React.PureComponent {
} else { } else {
return <div className='emoji-mart-preview'> return <div className='emoji-mart-preview'>
<div className='emoji-mart-preview-emoji'> <div className='emoji-mart-preview-emoji'>
{idleEmoji && idleEmoji.length && <Emoji emoji={idleEmoji} {...emojiProps} />} {idleEmoji && idleEmoji.length && Emoji({ emoji: idleEmoji, ...emojiProps })}
</div> </div>
<div className='emoji-mart-preview-data'> <div className='emoji-mart-preview-data'>