-
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.
Merge pull request #54 from IQSS/feature/create-the-navigation-elemen…
…ts-of-the-design-system 33 - Create the navigation elements of the design system
- Loading branch information
Showing
30 changed files
with
476 additions
and
240 deletions.
There are no files selected for viewing
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,55 @@ | ||
import { Navbar } from '../../../../src/sections/ui/navbar/Navbar' | ||
|
||
const brand = { | ||
logoImgSrc: '/logo.svg', | ||
title: 'Brand Title', | ||
href: '/home' | ||
} | ||
|
||
describe('Navbar component', () => { | ||
it('renders the brand logo and title', () => { | ||
cy.mount(<Navbar brand={brand} />) | ||
|
||
cy.findByRole('img', { name: 'Brand Logo Image' }).should('exist') | ||
cy.findByText('Brand Title').should('exist') | ||
}) | ||
|
||
it('renders the navbar links', () => { | ||
cy.mount( | ||
<Navbar brand={brand}> | ||
<Navbar.Link href="/link-1">Link 1</Navbar.Link> | ||
<Navbar.Link href="/link-2">Link 2</Navbar.Link> | ||
<Navbar.Dropdown title="Dropdown" id="dropdown"> | ||
<Navbar.Dropdown.Item href="/sublink-1">Sublink 1</Navbar.Dropdown.Item> | ||
<Navbar.Dropdown.Item href="/sublink-2">Sublink 2</Navbar.Dropdown.Item> | ||
</Navbar.Dropdown> | ||
</Navbar> | ||
) | ||
|
||
cy.findByRole('button', { name: 'Toggle navigation' }).click() | ||
cy.findByRole('link', { name: 'Link 1' }).should('exist') | ||
cy.findByRole('link', { name: 'Link 2' }).should('exist') | ||
|
||
const dropdownElement = cy.findByRole('button', { name: 'Dropdown' }) | ||
dropdownElement.should('exist') | ||
}) | ||
|
||
it('shows the sublinks when the dropdown is clicked', () => { | ||
cy.mount( | ||
<Navbar brand={brand}> | ||
<Navbar.Link href="/link-1">Link 1</Navbar.Link> | ||
<Navbar.Link href="/link-2">Link 2</Navbar.Link> | ||
<Navbar.Dropdown title="Dropdown" id="dropdown"> | ||
<Navbar.Dropdown.Item href="/sublink-1">Sublink 1</Navbar.Dropdown.Item> | ||
<Navbar.Dropdown.Item href="/sublink-2">Sublink 2</Navbar.Dropdown.Item> | ||
</Navbar.Dropdown> | ||
</Navbar> | ||
) | ||
cy.findByRole('button', { name: 'Toggle navigation' }).click() | ||
const dropdownElement = cy.findByRole('button', { name: 'Dropdown' }) | ||
dropdownElement.click() | ||
|
||
cy.findByRole('link', { name: 'Sublink 1' }).should('exist') | ||
cy.findByRole('link', { name: 'Sublink 2' }).should('exist') | ||
}) | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Breadcrumb as BreadcrumbBS } from 'react-bootstrap' | ||
import { PropsWithChildren } from 'react' | ||
import { BreadcrumbItem } from './BreadcrumbItem' | ||
|
||
function Breadcrumb({ children }: PropsWithChildren) { | ||
return <BreadcrumbBS>{children}</BreadcrumbBS> | ||
} | ||
|
||
Breadcrumb.Item = BreadcrumbItem | ||
|
||
export { Breadcrumb } |
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,14 @@ | ||
import { BreadcrumbItem as BreadcrumbItemBS } from 'react-bootstrap' | ||
import { PropsWithChildren } from 'react' | ||
|
||
interface BreadcrumbItemProps { | ||
href?: string | ||
active?: boolean | ||
} | ||
export function BreadcrumbItem({ href, active, children }: PropsWithChildren<BreadcrumbItemProps>) { | ||
return ( | ||
<BreadcrumbItemBS href={href} active={active}> | ||
{children} | ||
</BreadcrumbItemBS> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { PropsWithChildren } from 'react' | ||
import { Tab as TabBS } from 'react-bootstrap' | ||
|
||
export interface TabProps { | ||
title: string | ||
eventKey: string | ||
} | ||
|
||
export function Tab({ title, eventKey, children }: PropsWithChildren<TabProps>) { | ||
return ( | ||
<TabBS title={title} eventKey={eventKey}> | ||
{children} | ||
</TabBS> | ||
) | ||
} |
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,15 @@ | ||
import { PropsWithChildren } from 'react' | ||
import { Tab } from './Tab' | ||
import { Tabs as TabsBS } from 'react-bootstrap' | ||
|
||
interface TabsProps { | ||
defaultActiveKey: string | ||
} | ||
|
||
function Tabs({ defaultActiveKey, children }: PropsWithChildren<TabsProps>) { | ||
return <TabsBS defaultActiveKey={defaultActiveKey}>{children}</TabsBS> | ||
} | ||
|
||
Tabs.Tab = Tab | ||
|
||
export { Tabs } |
Oops, something went wrong.