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

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-05-31 18:39:30 +00:00
import React from 'react'
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
export default class Search extends React.PureComponent {
2017-10-07 04:02:02 +00:00
constructor(props) {
super(props)
this.setRef = this.setRef.bind(this)
this.handleChange = this.handleChange.bind(this)
}
2016-05-31 18:39:30 +00:00
handleChange() {
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
}
setRef(c) {
this.input = c
}
clear() {
this.input.value = ''
}
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 = {
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,
emojisToShowFilter: null,
2017-04-04 15:07:48 +00:00
autoFocus: false,
2016-05-31 18:39:30 +00:00
}