简单效果示例: 具体实现:
emoji网站:https://www.emojiall.com/zh-hans/all-emojis
import React from 'react'
class Emoji extends React.Component {
state = {
txt:'',
isShow:true,
emojiList: [
{ id: 1, emoji: '😀' },
{ id: 2, emoji: '😂' },
{ id: 3, emoji: '🥂' },
{ id: 4, emoji: '🤩' },
{ id: 5, emoji: '👿' },
{ id: 6, emoji: '😛' },
{ id: 7, emoji: '🤫' },
{ id: 8, emoji: '😑' },
{ id: 9, emoji: '🙄' },
{ id: 10, emoji: '🤐' },
{ id: 11, emoji: '🤑' },
{ id: 12, emoji: '🤗' },
{ id: 13, emoji: '😏' },
{ id: 14, emoji: '🥃' },
{ id: 15, emoji: '😒' },
{ id: 16, emoji: '😪' },
{ id: 17, emoji: '😴' },
{ id: 18, emoji: '🤤' },
{ id: 19, emoji: '🤧' },
{ id: 20, emoji: '🥶' }
]
}
changeLayer = () => {
if (this.state.isShow) {
this.setState({
isShow: false
})
} else {
this.setState({
isShow: true
})
}
}
handleOk = emoji => {
this.setState({
txt: this.state.txt.concat(emoji)
})
}
render(){
return (
<div className="comment-emoji" onClick={this.changeLayer}>
<i className="face"></i>
<span className="text">表情</span>
<div className={classNames('layer', { hide: this.state.isShow })}>
{this.state.emojiList.map(item => (
<span key={item.id} onClick={() => this.handleOk(item.emoji)}{item.emoji</span>
))}
</div>
</div>
)
}
}
|