simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 1 | import { useState } from 'react'; |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 2 | import { InputBase, InputAdornment } from '@mui/material'; |
| 3 | import { SearchRounded } from '@mui/icons-material'; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 4 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 5 | export default function NewContactForm(props) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 6 | const [value, setValue] = useState(''); |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 7 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 8 | const handleChange = (event) => { |
| 9 | setValue(event.target.value); |
| 10 | if (props.onChange) props.onChange(event.target.value); |
| 11 | }; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 12 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 13 | const handleSubmit = (event) => { |
| 14 | event.preventDefault(); |
| 15 | if (value && props.onSubmit) props.onSubmit(value); |
| 16 | }; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 17 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 18 | return ( |
| 19 | <form className="main-search" onSubmit={handleSubmit} noValidate autoComplete="off"> |
| 20 | <InputBase |
| 21 | className="main-search-input" |
| 22 | type="search" |
| 23 | placeholder="Ajouter un contact" |
| 24 | value={value} |
| 25 | onChange={handleChange} |
| 26 | startAdornment={ |
| 27 | <InputAdornment position="start"> |
| 28 | <SearchRounded /> |
| 29 | </InputAdornment> |
| 30 | } |
| 31 | /> |
| 32 | </form> |
| 33 | ); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 34 | } |