Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create search bar component #216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/searchBar/SearchBar.language.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"searchBarPlaceholder": "Search"
}
22 changes: 22 additions & 0 deletions components/searchBar/SearchBar.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.textBoxContainer {
Noamili marked this conversation as resolved.
Show resolved Hide resolved
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;
MichalPorag marked this conversation as resolved.
Show resolved Hide resolved
color: #bfc0c2;
font-size: 1.25rem;
font-weight: 400;
line-height: 26.16px;
}
54 changes: 54 additions & 0 deletions components/searchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -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 => {
Noamili marked this conversation as resolved.
Show resolved Hide resolved
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 (
<div className={styles.textBoxContainer}>
<input
onChange={handleOnChange}
type="text"
placeholder={placeholder ? placeholder : searchPlaceholder}
className={styles.textBox}
/>
<svg
width="20"
height="20"
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8.55295 17.105C10.5265 17.105 12.3408 16.4261 13.7884 15.3004L18.4883 20L20 18.4883L15.3002 13.7888C16.427 12.3402 17.1059 10.526 17.1059 8.55249C17.1059 3.83686 13.2688 0 8.55295 0C3.83707 0 0 3.83686 0 8.55249C0 13.2681 3.83707 17.105 8.55295 17.105ZM8.55295 2.13812C12.0907 2.13812 14.9677 5.01497 14.9677 8.55249C14.9677 12.09 12.0907 14.9669 8.55295 14.9669C5.01523 14.9669 2.13824 12.09 2.13824 8.55249C2.13824 5.01497 5.01523 2.13812 8.55295 2.13812Z"
fill="#BFC0C3"
/>
</svg>
</div>
);
};

export default SearchBar;