p5.js-web-editor/client/modules/IDE/components/Searchbar/Searchbar.jsx
ov f918669116
Spanish Translation: Copyable/Editable/AddRemove/SearchBar/PreviewNav (#1569)
* AddRemoveButton Translation

* CopyableInput EditableInput translations.json

* Translation in PreviewNav.jsx

* Translation in Feedback.jsx

* Translation in AssetList.jsx

* Translation in SearchBarComponent

* Translations.json merged

* Translations.json AddRemoved, feedback and Preview Nav
2020-08-26 17:28:53 +02:00

74 lines
1.9 KiB
JavaScript

import PropTypes from 'prop-types';
import React from 'react';
import { throttle } from 'lodash';
import { withTranslation } from 'react-i18next';
import i18next from 'i18next';
import SearchIcon from '../../../../images/magnifyingglass.svg';
class Searchbar extends React.Component {
constructor(props) {
super(props);
this.state = {
searchValue: this.props.searchTerm
};
this.throttledSearchChange = throttle(this.searchChange, 500);
}
componentWillUnmount() {
this.props.resetSearchTerm();
}
handleResetSearch = () => {
this.setState({ searchValue: '' }, () => {
this.props.resetSearchTerm();
});
}
searchChange = () => {
this.props.setSearchTerm(this.state.searchValue.trim());
};
handleSearchChange = (e) => {
this.setState({ searchValue: e.target.value }, () => {
this.throttledSearchChange(this.state.searchValue.trim());
});
}
render() {
const { searchValue } = this.state;
return (
<div className={`searchbar ${searchValue === '' ? 'searchbar--is-empty' : ''}`}>
<div className="searchbar__button">
<SearchIcon className="searchbar__icon" focusable="false" aria-hidden="true" />
</div>
<input
className="searchbar__input"
type="text"
value={searchValue}
placeholder={this.props.searchLabel}
onChange={this.handleSearchChange}
/>
<button
className="searchbar__clear-button"
onClick={this.handleResetSearch}
>{this.props.t('Searchbar.ClearTerm')}
</button>
</div>
);
}
}
Searchbar.propTypes = {
searchTerm: PropTypes.string.isRequired,
setSearchTerm: PropTypes.func.isRequired,
resetSearchTerm: PropTypes.func.isRequired,
searchLabel: PropTypes.string,
t: PropTypes.func.isRequired
};
Searchbar.defaultProps = {
searchLabel: i18next.t('Searchbar.SearchSketch')
};
export default withTranslation()(Searchbar);