-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Navbar): refactor navbar for better readbility
- Loading branch information
Showing
11 changed files
with
138 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
import { Navbar as NavbarBS } from 'react-bootstrap' | ||
import { Nav } from 'react-bootstrap' | ||
import { Link, NavbarProps } from './NavbarProps' | ||
import { NavDropdown } from './nav-dropdown/NavDropdown' | ||
import { NavbarDropdown } from './navbar-dropdown/NavbarDropdown' | ||
import { Container } from '../grid/Container' | ||
import { PropsWithChildren } from 'react' | ||
import { NavbarLink } from './NavbarLink' | ||
|
||
export function Navbar({ brand, links }: NavbarProps) { | ||
interface Brand { | ||
title: string | ||
href: string | ||
logoImgSrc: string | ||
} | ||
|
||
export interface NavbarProps { | ||
brand: Brand | ||
} | ||
|
||
function Navbar({ brand, children }: PropsWithChildren<NavbarProps>) { | ||
return ( | ||
<NavbarBS collapseOnSelect bg="light" expand="lg" fixed="top"> | ||
<Container> | ||
<NavbarBS.Brand href={brand.path}> | ||
<img width="28" height="28" src={brand.logo.src} alt={brand.logo.altText} /> | ||
<NavbarBS.Brand href={brand.href}> | ||
<img width="28" height="28" src={brand.logoImgSrc} alt="Brand Logo Image" /> | ||
{brand.title} | ||
</NavbarBS.Brand> | ||
<NavbarBS.Toggle aria-controls="responsive-navbar-nav" /> | ||
<NavbarBS.Collapse id="responsive-navbar-nav"> | ||
<Nav> | ||
{links.length != 0 && | ||
links.map((link: Link, index) => | ||
typeof link.value == 'string' ? ( | ||
<Nav.Link eventKey={index} key={index} href={link.value}> | ||
{link.title} | ||
</Nav.Link> | ||
) : ( | ||
<NavDropdown key={index} title={link.title} links={link.value} /> | ||
) | ||
)} | ||
</Nav> | ||
<Nav>{children}</Nav> | ||
</NavbarBS.Collapse> | ||
</Container> | ||
</NavbarBS> | ||
) | ||
} | ||
|
||
Navbar.Link = NavbarLink | ||
Navbar.Dropdown = NavbarDropdown | ||
|
||
export { Navbar } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Nav } from 'react-bootstrap' | ||
import { PropsWithChildren } from 'react' | ||
|
||
interface NavbarLinkProps { | ||
href: string | ||
} | ||
|
||
export function NavbarLink({ href, children }: PropsWithChildren<NavbarLinkProps>) { | ||
return <Nav.Link href={href}>{children}</Nav.Link> | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NavDropdown as NavDropdownBS } from 'react-bootstrap' | ||
import { PropsWithChildren } from 'react' | ||
import { NavbarDropdownItem } from './NavbarDropdownItem' | ||
|
||
interface DropdownProps { | ||
title: string | ||
id: string | ||
} | ||
|
||
function NavbarDropdown({ title, id, children }: PropsWithChildren<DropdownProps>) { | ||
return ( | ||
<NavDropdownBS title={title} id={id}> | ||
{children} | ||
</NavDropdownBS> | ||
) | ||
} | ||
|
||
NavbarDropdown.Item = NavbarDropdownItem | ||
|
||
export { NavbarDropdown } |
10 changes: 10 additions & 0 deletions
10
src/sections/ui/navbar/navbar-dropdown/NavbarDropdownItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NavDropdown } from 'react-bootstrap' | ||
import { PropsWithChildren } from 'react' | ||
|
||
interface NavbarDropdownItemProps { | ||
href: string | ||
} | ||
|
||
export function NavbarDropdownItem({ href, children }: PropsWithChildren<NavbarDropdownItemProps>) { | ||
return <NavDropdown.Item href={href}>{children}</NavDropdown.Item> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 20 additions & 17 deletions
37
.../navbar/nav-dropdown/NavDropdown.test.tsx → ...r/navbar-dropdown/NavbarDropdown.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters