Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 1 | import React from 'react' |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 2 | import SearchIcon from '@material-ui/icons/Search'; |
| 3 | import InputBase from '@material-ui/core/InputBase'; |
| 4 | import InputAdornment from '@material-ui/core/InputAdornment'; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 5 | |
| 6 | class NewContactForm extends React.Component { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 7 | 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 Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 35 | render() { |
| 36 | return ( |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 37 | <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 Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 49 | ) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | export default NewContactForm |