Skip to content

Commit

Permalink
feat(navigation): side nav on mobile decives (#1516)
Browse files Browse the repository at this point in the history
* feat(navigation): hamburger menu on mobile devices

* chore(): refactor names on navigation

* chore(nav): refactor logic

* styling(hamburger-meny): color and add padding

* styling(login): make modal width smaller on mobile

* styling(modals): make modal width larger on mobile

* styling(hamburger-menu): add chevron and background color on nav-items

* fix(hamburger-meny): set modal to now show when logging out

* chore(navbar): add use client

* chore(navbar): remove inline styling

* chore(create): move logic

* chore(logout): remove form logic

* fix(navbar): show hamburger meny

* chore(nav): display block on sidenav

---------

Co-authored-by: lindtvedtsebastian <[email protected]>
  • Loading branch information
emilielr and lindtvedtsebastian authored May 29, 2024
1 parent 3669281 commit 66e3c0a
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function StopPlaceList({
}) {
if (!tiles || tiles.length === 0)
return (
<Paragraph className="mt-6">
<Paragraph margin="none" className="mt-6">
Du har ikke lagt til noen stoppesteder enda.
</Paragraph>
)
Expand Down
14 changes: 5 additions & 9 deletions next-tavla/app/(admin)/components/CreateBoard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client'
import { IconButton, PrimaryButton, SecondaryButton } from '@entur/button'
import { AddIcon, BackArrowIcon, ForwardIcon } from '@entur/icons'
import { PrimaryButton, SecondaryButton } from '@entur/button'
import { BackArrowIcon, ForwardIcon } from '@entur/icons'
import { Stepper } from '@entur/menu'
import { Modal } from '@entur/modal'
import { Heading3, Heading4, Label, Paragraph } from '@entur/typography'
import Link from 'next/link'
import { usePageParam } from 'app/(admin)/hooks/usePageParam'
import { usePathname, useRouter } from 'next/navigation'
import { useSearchParamsSetter } from 'app/(admin)/hooks/useSearchParamsSetter'
Expand Down Expand Up @@ -48,13 +47,10 @@ function CreateBoard() {

return (
<>
<IconButton as={Link} href="?board=name" className="gap-4 p-4">
<AddIcon /> Opprett tavle
</IconButton>
<Modal
open={open}
size="large"
className="flex flex-col items-center"
className="flex flex-col items-center w-11/12 lg:w-full"
onDismiss={() => {
setBoard(undefined)
setFormError(undefined)
Expand All @@ -65,7 +61,7 @@ function CreateBoard() {
>
<Stepper steps={stepTitles} activeIndex={stepIndex} />

<div className="w-3/4">
<div className="w-full md:w-3/4">
<NameAndOrganizationSelector
active={pageParam === 'name'}
title={board?.meta?.title}
Expand Down Expand Up @@ -246,7 +242,7 @@ function StopSelector({
}
/>
<FormError {...getFormFeedbackForField('general', state)} />
<div className="flex flex-row justify-between pt-4">
<div className="flex flex-col sm:flex-row gap-2 pt-4 justify-between">
<SecondaryButton onClick={() => router.back()}>
<BackArrowIcon />
Tilbake
Expand Down
36 changes: 36 additions & 0 deletions next-tavla/app/(admin)/components/HorizontalNavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use client'

import { TopNavigationItem } from '@entur/menu'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { IconButton } from '@entur/button'
import { AddIcon } from '@entur/icons'
import { CreateBoard } from './CreateBoard'

function HorizontalNavBar({ loggedIn }: { loggedIn: boolean }) {
const pathname = usePathname()
if (!loggedIn) return null
return (
<div className="flex-row hidden md:flex gap-4">
<IconButton as={Link} href="?board=name" className="gap-4 p-4">
<AddIcon /> Opprett tavle <CreateBoard />
</IconButton>
<TopNavigationItem
active={pathname?.includes('/boards')}
as={Link}
href="/boards"
>
Tavler
</TopNavigationItem>
<TopNavigationItem
active={pathname?.includes('/organizations')}
as={Link}
href="/organizations"
>
Organisasjoner
</TopNavigationItem>
</div>
)
}

export { HorizontalNavBar }
16 changes: 10 additions & 6 deletions next-tavla/app/(admin)/components/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ function Login({ loggedIn }: { loggedIn: boolean }) {

if (loggedIn)
return (
<form action={logout}>
<IconButton type="submit" className="gap-4 p-4">
<LogOutIcon />
Logg ut
</IconButton>
</form>
<IconButton
onClick={async () => {
await logout
}}
className="gap-4 p-4 hidden md:flex"
>
<LogOutIcon />
Logg ut
</IconButton>
)

return (
Expand All @@ -43,6 +46,7 @@ function Login({ loggedIn }: { loggedIn: boolean }) {
<Modal
open={open}
size="small"
className="w-11/12 lg:w-full"
onDismiss={() => router.push(pathname ?? '/')}
>
<div className="flex flex-row justify-between">
Expand Down
84 changes: 84 additions & 0 deletions next-tavla/app/(admin)/components/SideNavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use client'
import { SideNavigationItem } from '@entur/menu'
import Link from 'next/link'
import Image from 'next/image'
import TavlaLogoBlue from 'assets/logos/Tavla-blue.svg'
import { CreateBoard } from './CreateBoard'
import { usePathname } from 'next/navigation'
import { Button, IconButton } from '@entur/button'
import { LeftArrowIcon, MenuIcon } from '@entur/icons'
import { useState } from 'react'
import { SideNavigation } from '@entur/menu'
import { logout } from './Login/actions'
import { Heading2 } from '@entur/typography'
import { Modal } from '@entur/modal'

function SideNavBar({ loggedIn }: { loggedIn: boolean }) {
const pathname = usePathname()
const [isOpen, setIsOpen] = useState(false)

if (!loggedIn) return null

return (
<div className="block md:hidden">
<IconButton
onClick={() => setIsOpen(!isOpen)}
className="bg-contrast rounded-full p-3"
>
<MenuIcon content="Meny" color="background" />
</IconButton>
<Modal
open={isOpen}
onDismiss={() => setIsOpen(false)}
size="medium"
className="h-full w-9/12 fixed top-0 left-0 py-10 !max-h-full !rounded-none !p-0 overflow-visible"
>
<SideNavigation className="h-full pt-10">
<div className="pl-10">
<Link href="/" aria-label="Tilbake til landingssiden">
<Image src={TavlaLogoBlue} height={22} alt="" />
</Link>
<Heading2 className="mt-16 mb-4">Meny</Heading2>
</div>

<div className="bg-secondary">
<SideNavigationItem as={Link} href="?board=name">
Opprett tavle
<CreateBoard />
</SideNavigationItem>
<SideNavigationItem
href="/boards"
active={pathname?.includes('/boards')}
>
Tavler
</SideNavigationItem>
<SideNavigationItem
href="/organizations"
active={pathname?.includes('/organizations')}
>
Organisasjoner
</SideNavigationItem>
<SideNavigationItem
as={Button}
className="[&>button]:justify-start [&>button]:px-10"
onClick={async () => {
setIsOpen(false)
await logout()
}}
>
Logg ut
</SideNavigationItem>
</div>
</SideNavigation>
<IconButton
onClick={() => setIsOpen(false)}
className="bg-contrast rounded-full p-3 absolute bottom-[10%] -right-5"
>
<LeftArrowIcon color="background" />
</IconButton>
</Modal>
</div>
)
}

export { SideNavBar }
48 changes: 13 additions & 35 deletions next-tavla/app/(admin)/components/TopNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
'use client'
import { TopNavigationItem } from '@entur/menu'
import { Login } from './Login'
import Link from 'next/link'
import Image from 'next/image'
import TavlaLogoBlue from 'assets/logos/Tavla-blue.svg'
import { CreateBoard } from './CreateBoard'
import { usePathname } from 'next/navigation'
import { SideNavBar } from './SideNavBar'
import { HorizontalNavBar } from './HorizontalNavBar'
import { Login } from './Login'

function TopNavigation({ loggedIn }: { loggedIn: boolean }) {
const pathname = usePathname()

return (
<div className="container mx-auto">
<nav className="flex flex-row justify-between items-center py-8">
<Link href="/" aria-label="Tilbake til landingssiden">
<Image src={TavlaLogoBlue} height={32} alt="" />
</Link>
<div className="flex flex-row items-center gap-4">
{loggedIn && (
<>
<CreateBoard />
<TopNavigationItem
active={pathname?.includes('/boards')}
as={Link}
href="/boards"
>
Tavler
</TopNavigationItem>
<TopNavigationItem
active={pathname?.includes('/organizations')}
as={Link}
href="/organizations"
>
Organisasjoner
</TopNavigationItem>
</>
)}
<Login loggedIn={loggedIn} />
</div>
</nav>
</div>
<nav className="container mx-auto flex flex-row justify-between items-center py-8">
<Link href="/" aria-label="Tilbake til landingssiden">
<Image src={TavlaLogoBlue} height={32} alt="" />
</Link>
<div className="flex flex-row items-center">
<SideNavBar loggedIn={loggedIn} />
<HorizontalNavBar loggedIn={loggedIn} />
<Login loggedIn={loggedIn} />
</div>
</nav>
)
}

Expand Down
3 changes: 3 additions & 0 deletions next-tavla/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--main-background-color: var(--colors-brand-white);
--secondary-background-color: var(--colors-greys-grey80);
--tertiary-background-color: var(--colors-blues-blue60);
--contrast-background-color: var(--colors-brand-blue);

--main-text-color: var(--colors-brand-blue);
--secondary-text-color: var(--colors-greys-grey60);
Expand Down Expand Up @@ -43,6 +44,7 @@
--main-background-color: var(--colors-misc-black);
--secondary-background-color: var(--colors-greys-grey);
--tertiary-background-color: var(--colors-blues-blue30);
--contrast-background-color: var(--colors-brand-white);

--main-text-color: var(--colors-brand-white);
--secondary-text-color: var(--colors-brand-lavender);
Expand Down Expand Up @@ -78,6 +80,7 @@
--main-background-color: var(--colors-brand-blue);
--secondary-background-color: var(--colors-blues-blue10);
--tertiary-background-color: var(--colors-blues-blue30);
--contrast-background-color: var(--colors-brand-white);

--main-text-color: var(--colors-brand-white);
--secondary-text-color: var(--colors-brand-lavender);
Expand Down
1 change: 1 addition & 0 deletions next-tavla/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
primary: 'var(--main-background-color)',
secondary: 'var(--secondary-background-color)',
tertiary: 'var(--tertiary-background-color)',
contrast: 'var(--contrast-background-color)',
},
colors: {
background: 'var(--main-background-color)',
Expand Down

0 comments on commit 66e3c0a

Please sign in to comment.