2016-05-31 18:39:30 +00:00
|
|
|
import React from 'react'
|
2017-05-05 01:38:03 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2016-07-20 18:45:28 +00:00
|
|
|
import emojiIndex from '../utils/emoji-index'
|
2016-05-31 18:39:30 +00:00
|
|
|
|
2017-09-29 14:46:29 +00:00
|
|
|
export default class Search extends React.PureComponent {
|
2017-10-07 04:02:02 +00:00
|
|
|
constructor(props) {
|
2017-09-29 14:46:29 +00:00
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.setRef = this.setRef.bind(this)
|
|
|
|
this.handleChange = this.handleChange.bind(this)
|
|
|
|
}
|
|
|
|
|
2016-05-31 18:39:30 +00:00
|
|
|
handleChange() {
|
2017-09-27 19:26:50 +00:00
|
|
|
var value = this.input.value
|
2016-05-31 18:39:30 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
this.props.onSearch(
|
|
|
|
emojiIndex.search(value, {
|
|
|
|
emojisToShowFilter: this.props.emojisToShowFilter,
|
|
|
|
maxResults: this.props.maxResults,
|
|
|
|
include: this.props.include,
|
|
|
|
exclude: this.props.exclude,
|
|
|
|
custom: this.props.custom,
|
2018-03-27 18:51:26 +00:00
|
|
|
}),
|
2017-10-07 04:02:02 +00:00
|
|
|
)
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 19:26:50 +00:00
|
|
|
setRef(c) {
|
|
|
|
this.input = c
|
|
|
|
}
|
|
|
|
|
2016-07-08 20:28:43 +00:00
|
|
|
clear() {
|
2017-09-27 19:26:50 +00:00
|
|
|
this.input.value = ''
|
2016-07-08 20:28:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 18:39:30 +00:00
|
|
|
render() {
|
2017-04-04 15:07:48 +00:00
|
|
|
var { i18n, autoFocus } = this.props
|
2016-10-27 03:22:59 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
return (
|
|
|
|
<div className="emoji-mart-search">
|
|
|
|
<input
|
|
|
|
ref={this.setRef}
|
|
|
|
type="text"
|
|
|
|
onChange={this.handleChange}
|
|
|
|
placeholder={i18n.search}
|
|
|
|
autoFocus={autoFocus}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Search.propTypes = {
|
2017-05-05 01:38:03 +00:00
|
|
|
onSearch: PropTypes.func,
|
|
|
|
maxResults: PropTypes.number,
|
|
|
|
emojisToShowFilter: PropTypes.func,
|
|
|
|
autoFocus: PropTypes.bool,
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Search.defaultProps = {
|
2017-10-07 04:02:02 +00:00
|
|
|
onSearch: () => {},
|
2016-07-08 21:05:26 +00:00
|
|
|
maxResults: 75,
|
2017-04-18 14:22:32 +00:00
|
|
|
emojisToShowFilter: null,
|
2017-04-04 15:07:48 +00:00
|
|
|
autoFocus: false,
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|