blob: c98c9b40b78f44f4ca179be2371f2725cc069729 [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001import React from 'react'
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04002import SearchIcon from '@material-ui/icons/Search';
3import InputBase from '@material-ui/core/InputBase';
4import InputAdornment from '@material-ui/core/InputAdornment';
Larbi Gharibe9af9732021-03-31 15:08:01 +01005
6class NewContactForm extends React.Component {
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04007 constructor(props) {
8 super(props)
9 this.state = {value: ''}
10 this.controller = new AbortController()
11 this.handleChange = this.handleChange.bind(this)
12 this.handleSubmit = this.handleSubmit.bind(this)
13 }
14
15 componentDidMount() {
16 this.controller = new AbortController()
17 }
18
19 componentWillUnmount() {
20 this.controller.abort()
21 this.req = undefined
22 }
23
24 handleChange(event) {
25 this.setState({value: event.target.value})
26 this.props.onChange(event.target.value)
27 }
28
29 handleSubmit(event) {
30 event.preventDefault()
31 if (this.props.onSubmit)
32 this.props.onSubmit(this.state.value)
33 }
34
Larbi Gharibe9af9732021-03-31 15:08:01 +010035 render() {
36 return (
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040037 <form className="main-search" onSubmit={this.handleSubmit} noValidate autoComplete="off">
38 <InputBase
39 className="main-search-input"
40 type="search"
41 placeholder="Ajouter un contact"
42 onChange={this.handleChange}
43 startAdornment={
44 <InputAdornment position="start">
45 <SearchIcon />
46 </InputAdornment>
47 } />
48 </form>
Larbi Gharibe9af9732021-03-31 15:08:01 +010049 )
50 }
51}
52
53export default NewContactForm