Nabarun Gogoi
c6c3ab03c3
* Implement layout for the projects page * Organize pages according to routes * Handle data from search bar * Get search data on submit --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
43 lines
905 B
TypeScript
43 lines
905 B
TypeScript
import React from 'react';
|
|
import { useForm, SubmitHandler } from 'react-hook-form';
|
|
|
|
interface SearchBarProps {
|
|
handler: (searchText: SearchInputs) => void;
|
|
placeholder?: string;
|
|
}
|
|
|
|
interface SearchInputs {
|
|
search: string;
|
|
}
|
|
|
|
const SearchBar: React.FC<SearchBarProps> = ({
|
|
handler,
|
|
placeholder = 'Search',
|
|
}) => {
|
|
const { register, handleSubmit } = useForm({
|
|
defaultValues: {
|
|
search: '',
|
|
},
|
|
});
|
|
|
|
const onSubmit: SubmitHandler<SearchInputs> = (data) => {
|
|
handler(data);
|
|
};
|
|
|
|
return (
|
|
<div className="w-full flex">
|
|
<div className="text-gray-300">^</div>
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
<input
|
|
{...register('search')}
|
|
type="text"
|
|
placeholder={placeholder}
|
|
className="grow text-gray-700 border-none focus:outline-none text-xs"
|
|
/>
|
|
</form>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default SearchBar;
|