Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added navigation for mobile devices #2198

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/icons/svg/nav/search-active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/icons/svg/nav/search-inactive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions components/MobileBottomNav/MobileBottomNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { FC, useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import Link from 'next/link'

import QuestionMarkIcon from 'assets/icons/svg/question-mark.svg'
import HomeInActiveIcon from 'assets/icons/svg/nav/home-inactive.svg'
import HomeActiveIcon from 'assets/icons/svg/nav/home-active.svg'
import SaveInActiveIcon from 'assets/icons/svg/nav/save-inactive.svg'
import SaveActiveIcon from 'assets/icons/svg/nav/save-active.svg'
import TeamInActiveIcon from 'assets/icons/svg/nav/team-inactive.svg'
import TeamActiveIcon from 'assets/icons/svg/nav/team-active.svg'
import SearchAciveIcon from 'assets/icons/svg/nav/search-active.svg'
import SearchInAciveIcon from 'assets/icons/svg/nav/search-inactive.svg'

const MobileBottomNav: FC = () => {
const router = useRouter()

const inActiveIconCls = 'stroke-gray-400'
const activeIconCls = 'fill-primary dark:fill-white'

const navLinks = [
{
inActiveIcon: <HomeInActiveIcon className={inActiveIconCls} />,
activeIcon: <HomeActiveIcon className={activeIconCls} />,
label: 'Home',
href: '/',
spaceActive: true,
},
{
inActiveIcon: <SaveInActiveIcon className={inActiveIconCls} />,
activeIcon: <SaveActiveIcon className={activeIconCls} />,
label: 'Saved',
href: '/saved',
},
{
inActiveIcon: <SearchInAciveIcon className={inActiveIconCls} />,
activeIcon: <SearchAciveIcon className={activeIconCls} />,
label: 'Search',
aftabrehan marked this conversation as resolved.
Show resolved Hide resolved
},
{
inActiveIcon: <TeamInActiveIcon className={inActiveIconCls} />,
activeIcon: <TeamActiveIcon className={activeIconCls} />,
label: 'Our Team',
href: '/contributors',
},
]

const renderLinks = () =>
navLinks.map(({ inActiveIcon, activeIcon, label, href }, i) => {
const checkRoute = (val: string) => router.asPath.startsWith(val)

const isHomeActive = !checkRoute('/saved') && !checkRoute('/contributors')
const isUrlMatched = href && checkRoute(href)
const isActive = label === 'Home' ? isHomeActive : isUrlMatched

return (
<li key={i} className="list-none">
{href ? (
<Link
href={href}
className={`w-full flex flex-col px-4 p-3 gap-2 font-medium rounded-xl hover:bg-slate-100 hover:bg-opacity-50 dark:hover:bg-zinc-400 dark:hover:bg-opacity-10 ${
isActive ? 'text-primary dark:text-white' : 'text-gray-400'
}`}
>
<span className="flex items-center justify-center">
{isActive ? activeIcon : inActiveIcon}
</span>
<span className="text-xs">{label}</span>
</Link>
) : (
<div
className={`w-full flex flex-col px-4 p-3 gap-2 font-medium rounded-xl hover:bg-slate-100 hover:bg-opacity-50 dark:hover:bg-zinc-400 dark:hover:bg-opacity-10 ${
isActive ? 'text-primary dark:text-white' : 'text-gray-400'
aftabrehan marked this conversation as resolved.
Show resolved Hide resolved
}`}
>
<span className="flex items-center justify-center">
{inActiveIcon}
</span>
<span className="text-xs">{label}</span>
</div>
)}
</li>
)
})

return (
<div className="sm:hidden -ml-4 fixed z-30 bottom-0 py-2 w-full flex gap-4 justify-evenly bg-white dark:bg-slate-800">
{renderLinks()}
</div>
)
}

export default MobileBottomNav
4 changes: 3 additions & 1 deletion layouts/GeneralLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IContext } from 'types'
import { GlobalContext } from 'context/GlobalContext'
import clsx from 'clsx'
import { usePathname } from 'next/navigation'
import MobileBottomNav from 'components/MobileBottomNav/MobileBottomNav'

const GeneralLayout = ({ children }: { children: ReactNode }) => {
const { sidebar } = useContext<IContext>(GlobalContext)
Expand All @@ -20,7 +21,7 @@ const GeneralLayout = ({ children }: { children: ReactNode }) => {
<Header />
<SideNavbar />
<div
className={`row-start-2 row-end-3 min-h-[100vh-72px] w-full bg-gray-100 dark:bg-[#101623] ${
className={`row-start-2 row-end-3 overflow-y-scroll max-h-[calc(100vh-156px)] sm:max-h-[calc(100vh-72px)] w-full bg-gray-100 dark:bg-[#101623] ${
aftabrehan marked this conversation as resolved.
Show resolved Hide resolved
sidebar ? 'max-[1024px]:overflow-hidden' : ''
}`}
>
Expand All @@ -38,6 +39,7 @@ const GeneralLayout = ({ children }: { children: ReactNode }) => {
>
{children}
<Footer />
<MobileBottomNav />
</main>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function Home() {
<Logo />
<span>👾</span>
</div>
<div className="flex flex-col mt-6 justify-center items-start w-96 max-md:w-64">
<div className="flex flex-col mt-6 justify-center items-start max-w-sm">
<p className="text-md">
{' '}
LinksHub aims to provide developers with access to a wide range of
Expand Down
Loading