Skip to content

Commit 4a0f051

Browse files
committed
Issue #140: Made Header Responsive
1 parent 7e6178b commit 4a0f051

File tree

2 files changed

+68
-50
lines changed

2 files changed

+68
-50
lines changed

components/Header.tsx

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,51 @@ import { useRouter } from 'next/router';
55
import { IoLogoGithub } from 'react-icons/io';
66
import { BsPeopleFill } from 'react-icons/bs';
77

8-
import Search from './Search';
8+
import Search, { SearchProps } from './Search';
99

10-
function Header() {
10+
11+
const SearchBar = (props: SearchProps) => {
1112
const router = useRouter();
1213

14+
return (router.pathname === '/repos/[language]' && (
15+
<Search {...props} />
16+
)
17+
)
18+
}
19+
20+
function Header() {
1321
return (
14-
<div className="border-b-[0.5px] border-dashed border-b-2023-manga-3 flex justify-center mb-5">
15-
<div className="justify-between px-2 mb-2 ml-1.5 w-3/4 shadow-lg navbar rounded-box">
16-
<Link href="/">
17-
<img src="/hacktoberfest.svg" alt="Hacktoberfest" />
18-
</Link>
19-
{router.pathname === '/repos/[language]' && (
20-
<div className="justify-center flex-1">
21-
<Search />
22-
</div>
23-
)}
24-
<div className="flex-none">
25-
<Link
26-
href="/contributors"
27-
className="btn btn-square btn-ghost umami--click--contributors-button"
28-
>
29-
<BsPeopleFill size="1.5rem" title="Contributors" />
22+
<header className="border-b-[0.5px] border-dashed border-b-2023-manga-3 mb-5">
23+
<div className="container mx-auto px-4 py-2">
24+
<div className="justify-between shadow-lg navbar">
25+
<Link href="/">
26+
<img src="/hacktoberfest.svg" alt="Hacktoberfest" className="h-12 w-auto sm:h-auto" />
3027
</Link>
31-
<a
32-
href="https://github.com/max-programming/hacktoberfest-projects"
33-
target="_blank"
34-
rel="noreferrer"
35-
className="btn btn-square btn-ghost umami--click--github-button"
36-
>
37-
<IoLogoGithub size="1.5rem" title="GitHub" />
38-
</a>
39-
</div>
28+
29+
<SearchBar searchBarWrapperStyles="hidden sm:inline-flex flex-1 max-w-md px-6" />
30+
31+
<div className="flex-none">
32+
<Link
33+
href="/contributors"
34+
className="btn btn-square btn-ghost umami--click--contributors-button"
35+
>
36+
<BsPeopleFill size="1.5rem" title="Contributors" />
37+
</Link>
38+
39+
<a
40+
href="https://github.com/max-programming/hacktoberfest-projects"
41+
target="_blank"
42+
rel="noreferrer"
43+
className="btn btn-square btn-ghost umami--click--github-button"
44+
>
45+
<IoLogoGithub size="1.5rem" title="GitHub" />
46+
</a>
47+
</div>
48+
</div>
49+
50+
<SearchBar searchBarWrapperStyles="sm:hidden px-2 mb-3" />
4051
</div>
41-
</div>
52+
</header>
4253
);
4354
}
4455

components/Search.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,45 @@ import { GoX } from 'react-icons/go';
55
interface FormValues {
66
searchQuery: string;
77
}
8+
export interface SearchProps {
9+
searchBarWrapperStyles?: string
10+
}
811

9-
export default function Search() {
12+
export default function Search({ searchBarWrapperStyles }: SearchProps) {
1013
const router = useRouter();
14+
1115
const { register, handleSubmit, reset } = useForm<FormValues>({
1216
defaultValues: {
1317
searchQuery: router.query.q as string
1418
}
1519
});
20+
1621
const onSubmit: SubmitHandler<FormValues> = ({ searchQuery }) => {
17-
console.log(router.asPath);
1822
router.push({ query: { ...router.query, q: searchQuery } });
1923
};
24+
2025
return (
21-
<form
22-
className="w-full m-2 lg:w-2/4 form-control"
23-
onSubmit={handleSubmit(onSubmit)}
24-
>
25-
<div className="relative">
26-
<input
27-
placeholder="Search"
28-
className="w-full pr-16 input input-bordered border-2023-bavarian-gold-2 focus:outline-2023-bavarian-gold-2 bg-transparent"
29-
type="text"
30-
{...register('searchQuery', { required: true })}
31-
/>
32-
<button
33-
className="absolute top-0 right-0 rounded-l-none btn btn-ghost"
34-
type="button"
35-
onClick={() => reset()}
36-
>
37-
<GoX />
38-
</button>
39-
</div>
40-
</form>
26+
<div className={searchBarWrapperStyles}>
27+
<form
28+
className="w-full mx-auto m-2 form-control"
29+
onSubmit={handleSubmit(onSubmit)}
30+
>
31+
<div className="relative">
32+
<input
33+
placeholder="Search"
34+
className="w-full pr-16 input input-bordered border-2023-bavarian-gold-2 focus:outline-2023-bavarian-gold-2 bg-transparent"
35+
type="text"
36+
{...register('searchQuery', { required: true })}
37+
/>
38+
<button
39+
className="absolute top-0 right-0 rounded-l-none btn btn-ghost"
40+
type="button"
41+
onClick={() => reset()}
42+
>
43+
<GoX />
44+
</button>
45+
</div>
46+
</form>
47+
</div>
4148
);
4249
}

0 commit comments

Comments
 (0)