From 43cdb7607d9423109758334155acfe844eab6ea5 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 20 Dec 2021 19:06:49 +0100
Subject: chore: define search form visibility

---
 src/components/SearchForm/SearchForm.tsx | 37 ++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 src/components/SearchForm/SearchForm.tsx

(limited to 'src/components/SearchForm/SearchForm.tsx')

diff --git a/src/components/SearchForm/SearchForm.tsx b/src/components/SearchForm/SearchForm.tsx
new file mode 100644
index 0000000..c02c224
--- /dev/null
+++ b/src/components/SearchForm/SearchForm.tsx
@@ -0,0 +1,37 @@
+import { ButtonSubmit } from '@components/Buttons';
+import { Form, Input } from '@components/Form';
+import { t } from '@lingui/macro';
+import { FormEvent, useEffect, useRef, useState } from 'react';
+
+const SearchForm = ({ isOpened }: { isOpened: boolean }) => {
+  const [query, setQuery] = useState('');
+  const inputRef = useRef<HTMLInputElement>(null);
+
+  useEffect(() => {
+    setTimeout(() => {
+      if (inputRef.current) {
+        inputRef.current.focus();
+      }
+    }, 800);
+  }, [isOpened]);
+
+  const launchSearch = (e: FormEvent) => {
+    e.preventDefault();
+  };
+
+  return (
+    <Form submitHandler={launchSearch} modifier="search">
+      <Input
+        ref={inputRef}
+        id="search-query"
+        name="search-query"
+        type="search"
+        value={query}
+        setValue={setQuery}
+      />
+      <ButtonSubmit>{t`Search`}</ButtonSubmit>
+    </Form>
+  );
+};
+
+export default SearchForm;
-- 
cgit v1.2.3

