3d7f68c273
* Revert "Fix some icon names changed by the Font Awesome 5. (#8796)" This reverts commit3f9ec3de82
. * Revert "Migrate to font-awesome 5.0. (#8799)" This reverts commit8bae14591b
. * Revert "Fix some icons names, unavailable in fontawesome5 (free license). (#8792)" This reverts commitb9c727a945
. * Revert "Update the icon name changed by the Font Awesome 5. (#8776)" This reverts commit17af4d27da
. * Revert "Add bot icon to bot avatars and migrate to newer version of Font Awesome (#8484)" This reverts commit4b794e134d
.
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { connect } from 'react-redux';
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
import { fetchListSuggestions, clearListSuggestions, changeListSuggestions } from '../../../actions/lists';
|
|
import classNames from 'classnames';
|
|
|
|
const messages = defineMessages({
|
|
search: { id: 'lists.search', defaultMessage: 'Search among people you follow' },
|
|
});
|
|
|
|
const mapStateToProps = state => ({
|
|
value: state.getIn(['listEditor', 'suggestions', 'value']),
|
|
});
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
onSubmit: value => dispatch(fetchListSuggestions(value)),
|
|
onClear: () => dispatch(clearListSuggestions()),
|
|
onChange: value => dispatch(changeListSuggestions(value)),
|
|
});
|
|
|
|
export default @connect(mapStateToProps, mapDispatchToProps)
|
|
@injectIntl
|
|
class Search extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
intl: PropTypes.object.isRequired,
|
|
value: PropTypes.string.isRequired,
|
|
onChange: PropTypes.func.isRequired,
|
|
onSubmit: PropTypes.func.isRequired,
|
|
onClear: PropTypes.func.isRequired,
|
|
};
|
|
|
|
handleChange = e => {
|
|
this.props.onChange(e.target.value);
|
|
}
|
|
|
|
handleKeyUp = e => {
|
|
if (e.keyCode === 13) {
|
|
this.props.onSubmit(this.props.value);
|
|
}
|
|
}
|
|
|
|
handleClear = () => {
|
|
this.props.onClear();
|
|
}
|
|
|
|
render () {
|
|
const { value, intl } = this.props;
|
|
const hasValue = value.length > 0;
|
|
|
|
return (
|
|
<div className='list-editor__search search'>
|
|
<label>
|
|
<span style={{ display: 'none' }}>{intl.formatMessage(messages.search)}</span>
|
|
|
|
<input
|
|
className='search__input'
|
|
type='text'
|
|
value={value}
|
|
onChange={this.handleChange}
|
|
onKeyUp={this.handleKeyUp}
|
|
placeholder={intl.formatMessage(messages.search)}
|
|
/>
|
|
</label>
|
|
|
|
<div role='button' tabIndex='0' className='search__icon' onClick={this.handleClear}>
|
|
<i className={classNames('fa fa-search', { active: !hasValue })} />
|
|
<i aria-label={intl.formatMessage(messages.search)} className={classNames('fa fa-times-circle', { active: hasValue })} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
}
|