diff options
author | Ernst Widerberg <ernstwi@kth.se> | 2021-10-06 16:11:06 +0200 |
---|---|---|
committer | Ernst Widerberg <ernstwi@kth.se> | 2021-10-06 16:11:06 +0200 |
commit | 46b9df3279f51479cfc607cbce8fb8b73bef69f7 (patch) | |
tree | ddca9489ce2779c5c7c23938cb5e666387ace775 /src/components/SearchForm.js |
Initial commit
Diffstat (limited to 'src/components/SearchForm.js')
-rw-r--r-- | src/components/SearchForm.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/components/SearchForm.js b/src/components/SearchForm.js new file mode 100644 index 0000000..0dc288c --- /dev/null +++ b/src/components/SearchForm.js @@ -0,0 +1,72 @@ +import React from "react"; +import PropTypes from "prop-types"; +import { Button, Select, Input, Icon } from "semantic-ui-react"; + +class SearchForm extends React.Component { + static propTypes = { + filter: PropTypes.func.isRequired + }; + + constructor(props) { + super(props); + this.state = { + field: "default-field", + value: "" + }; + + this.clearSearch = this.clearSearch.bind(this); + this.handleInput = this.handleInput.bind(this); + this.submitSearch = this.submitSearch.bind(this); + } + + handleInput(e) { + this.setState({ + [e.target.name]: e.target.value + }); + } + + clearSearch(_) { + this.setState({ value: "" }); + this.props.filter(null, null); + } + + submitSearch(e) { + e.preventDefault(); + this.props.filter(this.state.field, this.state.value); + } + + render() { + const searchOptions = [ + { + key: "default-field", + value: "default-field", + text: "Default field" + } + ]; + return ( + <form onSubmit={this.submitSearch}> + <Input + action + type="text" + name="value" + placeholder="Search..." + iconPosition="left" + onChange={this.handleInput} + value={this.state.value} + > + <input /> + <Icon name="delete" link onClick={this.clearSearch} /> + <Select + name="field" + options={searchOptions} + defaultValue="default-field" + onChange={this.handleInput} + /> + <Button type="submit">Search</Button> + </Input> + </form> + ); + } +} + +export default SearchForm; |