Skip to content

Commit 97fea96

Browse files
authored
Adding Mobile NavBar (#8)
* add header mobile * fix test
1 parent 08c0fe5 commit 97fea96

File tree

22 files changed

+278
-75
lines changed

22 files changed

+278
-75
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.13.2

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"dependencies": {
6161
"axios": "^0.27.2",
6262
"classnames": "^2.3.1",
63+
"hamburger-react": "^2.5.0",
6364
"i18next": "^21.8.9",
6465
"i18next-browser-languagedetector": "^6.1.4",
6566
"i18next-http-backend": "^1.4.1",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { FC } from 'react';
2+
import { NavContainer, Brand, NavList, NavItem } from './styles';
3+
import { useTranslation } from 'react-i18next';
4+
import { Link, NavLink } from 'react-router-dom';
5+
import { Routes } from 'routes/Routes';
6+
import Button from 'components/Button';
7+
import Sparkles from 'components/Sparkles';
8+
import NanBrand from 'components/NanBrand';
9+
import type { NavLinkProp } from 'components/Header/domain/links';
10+
11+
type DesktopNavProps = {
12+
links: NavLinkProp[];
13+
};
14+
15+
const DesktopNav: FC<DesktopNavProps> = ({ links }) => {
16+
const { t } = useTranslation(['config', 'translations']);
17+
return (
18+
<NavContainer className="desktop-nav">
19+
<Link to={Routes.ROOT}>
20+
<Brand>
21+
<NanBrand />
22+
</Brand>
23+
</Link>
24+
25+
<NavList>
26+
{links.map((link) => (
27+
<NavItem key={link.to}>
28+
<NavLink to={link.to}>{link.title(t)}</NavLink>
29+
</NavItem>
30+
))}
31+
</NavList>
32+
33+
<Sparkles colors={['#FFC700', '#22d0b6', '#22d0b6', '#80a6e9', '#f280b9', '#e35da0', '#0cea86']}>
34+
<NavLink to={Routes.POWERED}>
35+
<Button>Powered</Button>
36+
</NavLink>
37+
</Sparkles>
38+
</NavContainer>
39+
);
40+
};
41+
42+
export default DesktopNav;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Desktop';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import styled from 'styled-components';
2+
3+
export const NavContainer = styled.div`
4+
display: flex;
5+
flex: 1;
6+
align-items: center;
7+
justify-content: space-between;
8+
max-width: 1240px;
9+
padding: 0 20px;
10+
`;
11+
12+
export const Brand = styled.div`
13+
padding-right: 20px;
14+
`;
15+
16+
export const NavList = styled.ul`
17+
display: flex;
18+
flex: 1;
19+
align-items: center;
20+
justify-content: flex-start;
21+
padding: 0 40px;
22+
`;
23+
24+
export const NavItem = styled.li`
25+
font-size: 20px;
26+
font-weight: normal;
27+
margin: 0 14px;
28+
cursor: pointer;
29+
list-style: none;
30+
31+
a {
32+
text-decoration: none;
33+
color: black;
34+
}
35+
`;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
22
import { render, screen } from 'utils/test/test-utils';
3-
import Header from './Header';
3+
import Header from './Desktop';
4+
import { links } from './domain/links';
45

56
test('testing i18n in Header', async () => {
6-
render(<Header />);
7+
render(<Header links={links} />);
78
expect(screen.getByText('Router example')).toBeTruthy();
89
});

src/components/Header/Header.tsx

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,18 @@
11
import React, { FC } from 'react';
2-
import { FixedContainer, Nav, NavContainer, Brand, NavList, NavItem } from './styles';
3-
import { useTranslation } from 'react-i18next';
2+
import { FixedContainer, Nav } from './styles';
43
import useScroll from 'hooks/useScroll';
5-
import { Link, NavLink } from 'react-router-dom';
6-
import { Routes } from 'routes/Routes';
7-
import Button from 'components/Button';
8-
import Sparkles from 'components/Sparkles';
9-
import NanBrand from 'components/NanBrand';
4+
import Desktop from './Desktop';
5+
import Mobile from './Mobile';
6+
import { links } from './domain/links';
107

118
const Header: FC = () => {
12-
const { t } = useTranslation(['config', 'translations']);
139
const isFixed = useScroll(50);
1410

1511
return (
1612
<FixedContainer>
1713
<Nav condensed={isFixed}>
18-
<NavContainer>
19-
<Link to={Routes.ROOT}>
20-
<Brand>
21-
<NanBrand />
22-
</Brand>
23-
</Link>
24-
25-
<NavList>
26-
<NavItem>
27-
<NavLink to={Routes.LINKS_EXAMPLES}>{t('header.routerLinkExample', { ns: 'translations' })}</NavLink>
28-
</NavItem>
29-
<NavItem>
30-
<NavLink to={Routes.API_EXAMPLES}>{t('header.integrations', { ns: 'translations' })}</NavLink>
31-
</NavItem>
32-
</NavList>
33-
34-
<Sparkles colors={['#FFC700', '#22d0b6', '#22d0b6', '#80a6e9', '#f280b9', '#e35da0', '#0cea86']}>
35-
<NavLink to={Routes.POWERED}>
36-
<Button>Powered</Button>
37-
</NavLink>
38-
</Sparkles>
39-
</NavContainer>
14+
<Desktop links={links} />
15+
<Mobile links={links} />
4016
</Nav>
4117
</FixedContainer>
4218
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { FC } from 'react';
2+
import { NavContainer, Brand, MobileContainer, NavList, NavItem, HiddenMenuInput, LabelMenu } from './styles';
3+
import { useTranslation } from 'react-i18next';
4+
import { Link, NavLink } from 'react-router-dom';
5+
import { Routes } from 'routes/Routes';
6+
import NanBrand from 'components/NanBrand';
7+
import type { NavLinkProp } from 'components/Header/domain/links';
8+
import { Divide as Hamburger } from 'hamburger-react';
9+
10+
type MobileNavProps = {
11+
links: NavLinkProp[];
12+
};
13+
14+
const MobileNav: FC<MobileNavProps> = ({ links }) => {
15+
const { t } = useTranslation(['config', 'translations']);
16+
17+
return (
18+
<NavContainer className="mobile-nav">
19+
<Link style={{ zIndex: 1001 }} to={Routes.ROOT}>
20+
<Brand>
21+
<NanBrand />
22+
</Brand>
23+
</Link>
24+
25+
<HiddenMenuInput className="side-menu" id="side-menu" />
26+
<LabelMenu htmlFor="side-menu">
27+
<Hamburger />
28+
</LabelMenu>
29+
30+
<MobileContainer>
31+
<NavList>
32+
{links.map((link) => (
33+
<NavItem key={link.to}>
34+
<NavLink to={link.to}>{link.title(t)}</NavLink>
35+
</NavItem>
36+
))}
37+
</NavList>
38+
</MobileContainer>
39+
</NavContainer>
40+
);
41+
};
42+
43+
export default MobileNav;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Mobile';

0 commit comments

Comments
 (0)