blob: d55b80b506bcda066c9561f98296015e70196f8a [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
Adrien Béraudab519ff2022-05-03 15:34:48 -040018import { SearchRounded } from '@mui/icons-material';
simon07b4eb02022-09-29 17:50:26 -040019import { InputAdornment, InputBase } from '@mui/material';
simon6b9ddfb2022-10-03 00:04:50 -040020import { ChangeEvent, FormEvent, useState } from 'react';
Larbi Gharibe9af9732021-03-31 15:08:01 +010021
simon6b9ddfb2022-10-03 00:04:50 -040022type NewContactFormProps = {
23 onChange?: (v: string) => void;
24 onSubmit?: (v: string) => void;
25};
26
27export default function NewContactForm(props: NewContactFormProps) {
simond47ef9e2022-09-28 22:24:28 -040028 const [value, setValue] = useState('');
Adrien Béraud150b4782021-04-21 19:40:59 -040029
simon6b9ddfb2022-10-03 00:04:50 -040030 const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
simond47ef9e2022-09-28 22:24:28 -040031 setValue(event.target.value);
32 if (props.onChange) props.onChange(event.target.value);
33 };
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040034
simon6b9ddfb2022-10-03 00:04:50 -040035 const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
simond47ef9e2022-09-28 22:24:28 -040036 event.preventDefault();
37 if (value && props.onSubmit) props.onSubmit(value);
38 };
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040039
simond47ef9e2022-09-28 22:24:28 -040040 return (
41 <form className="main-search" onSubmit={handleSubmit} noValidate autoComplete="off">
42 <InputBase
43 className="main-search-input"
44 type="search"
45 placeholder="Ajouter un contact"
46 value={value}
47 onChange={handleChange}
48 startAdornment={
49 <InputAdornment position="start">
50 <SearchRounded />
51 </InputAdornment>
52 }
53 />
54 </form>
55 );
Larbi Gharibe9af9732021-03-31 15:08:01 +010056}