diff --git a/components/searchBar/SearchBar.language.json b/components/searchBar/SearchBar.language.json new file mode 100644 index 0000000..c5d3be0 --- /dev/null +++ b/components/searchBar/SearchBar.language.json @@ -0,0 +1,3 @@ +{ + "searchBarPlaceholder": "Search" +} diff --git a/components/searchBar/SearchBar.module.scss b/components/searchBar/SearchBar.module.scss new file mode 100644 index 0000000..86ab810 --- /dev/null +++ b/components/searchBar/SearchBar.module.scss @@ -0,0 +1,22 @@ +.textBoxContainer { + display: flex; + align-items: center; + padding: 0 16px; + gap: 8px; + border: solid 1px #bfc0c3; + max-width: 313px; + height: 40px; + border-radius: 8px; + background-color: white; + margin: 100px; +} + +.textBox { + border: none; + width: 100%; + direction: ltr; + color: #bfc0c2; + font-size: 1.25rem; + font-weight: 400; + line-height: 26.16px; +} diff --git a/components/searchBar/SearchBar.tsx b/components/searchBar/SearchBar.tsx new file mode 100644 index 0000000..f42de20 --- /dev/null +++ b/components/searchBar/SearchBar.tsx @@ -0,0 +1,54 @@ +import React, { useCallback, ReactElement } from 'react'; +import { useTranslator } from '../language/useTranslator'; +import languageFile from './SearchBar.language.json'; +import styles from './SearchBar.module.scss'; + +interface Props { + handelSearch: (searchTerm: string) => void; + placeholder?: string; +} + +const debounce = (callback, delay) => { + let timer; + return (...args) => { + clearTimeout(timer); + timer = setTimeout(() => callback(...args), delay); + }; +}; + +const SearchBar = (props: Props): ReactElement => { + const { handelSearch, placeholder } = props; + const searchPlaceholder = useTranslator('searchBarPlaceholder', languageFile); + + const debounceHandler = useCallback(debounce(handelSearch, 1000), []); + + const handleOnChange = async (event) => { + const { value } = event.currentTarget; + debounceHandler(value); + }; + + return ( +
+ + + + +
+ ); +}; + +export default SearchBar;