emoji are replaced in the text area
This commit is contained in:
parent
533eb99f80
commit
5ad5a714bc
2 changed files with 37 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
import React, { PropTypes, Component } from 'react'
|
import React, { PropTypes, Component } from 'react'
|
||||||
import { Picker } from 'emoji-mart'
|
import { Picker, emojiIndex } from 'emoji-mart'
|
||||||
|
import { escapeRegExp } from 'lodash'
|
||||||
|
|
||||||
class NewMessage extends Component {
|
class NewMessage extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -15,24 +16,53 @@ class NewMessage extends Component {
|
||||||
this.setState({ showEmojiPicker: !this.state.showEmojiPicker })
|
this.setState({ showEmojiPicker: !this.state.showEmojiPicker })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textAreaValue = () => {
|
||||||
|
let { messageText } = this.props
|
||||||
|
Object.keys(emojiIndex.emoticons).forEach(key => {
|
||||||
|
const value = emojiIndex.emoticons[key]
|
||||||
|
messageText = messageText.replace(new RegExp(escapeRegExp(key), 'g'), `:${value}:`)
|
||||||
|
})
|
||||||
|
Object.keys(emojiIndex.emojis).forEach(key => {
|
||||||
|
const emoji = emojiIndex.emojis[key]
|
||||||
|
messageText = messageText.replace(new RegExp(escapeRegExp(emoji.colons), 'g'), emoji.native)
|
||||||
|
})
|
||||||
|
return messageText
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClick = (emoji, event) => {
|
||||||
|
const { messageText } = this.props
|
||||||
|
this.props.handleChange({ target: {
|
||||||
|
value: messageText + emoji.colons
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
return (
|
return (
|
||||||
<div className="new-message-area">
|
<div className="new-message-area">
|
||||||
<span onClick={this.toggleEmojiPicker}>Emoji</span>
|
<span onClick={this.toggleEmojiPicker}>Emoji</span>
|
||||||
<Picker set='emojione' style={{ display: this.state.showEmojiPicker ? 'block' : 'none' }} />
|
<Picker set='emojione'
|
||||||
<textarea {...this.props.textAreaProps} />
|
onClick={this.handleClick}
|
||||||
|
style={{
|
||||||
|
display: this.state.showEmojiPicker ? 'block' : 'none',
|
||||||
|
width: '100%'
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<textarea value={this.textAreaValue()}
|
||||||
|
onChange={this.props.handleChange}
|
||||||
|
{...this.props.textAreaProps}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NewMessage.propTypes = {
|
NewMessage.propTypes = {
|
||||||
|
messageText: PropTypes.string,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
textAreaProps: PropTypes.shape({
|
textAreaProps: PropTypes.shape({
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
ref: PropTypes.func,
|
ref: PropTypes.func,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
value: PropTypes.string,
|
|
||||||
onChange: PropTypes.func,
|
|
||||||
onKeyUp: PropTypes.func,
|
onKeyUp: PropTypes.func,
|
||||||
onFocus: PropTypes.func,
|
onFocus: PropTypes.func,
|
||||||
onBlur: PropTypes.func
|
onBlur: PropTypes.func
|
||||||
|
|
|
@ -148,12 +148,12 @@ class MapChat extends Component {
|
||||||
className: 'chat-input',
|
className: 'chat-input',
|
||||||
ref: textarea => this.messageInput = textarea,
|
ref: textarea => this.messageInput = textarea,
|
||||||
placeholder: 'Send a message...',
|
placeholder: 'Send a message...',
|
||||||
value: this.state.messageText,
|
|
||||||
onChange: this.handleChange('messageText'),
|
|
||||||
onKeyUp: this.handleTextareaKeyUp,
|
onKeyUp: this.handleTextareaKeyUp,
|
||||||
onFocus: this.props.inputFocus,
|
onFocus: this.props.inputFocus,
|
||||||
onBlur: this.props.inputBlur
|
onBlur: this.props.inputBlur
|
||||||
}}
|
}}
|
||||||
|
handleChange={this.handleChange('messageText')}
|
||||||
|
messageText={this.state.messageText}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue