blob: 0dc288c818cc69fcf4e2ca2429827f29159a17cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
|