Skip to content

Commit

Permalink
added mobile responsivity for tab bar along with light/dark mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
sashaaldrick committed Jul 10, 2023
1 parent c2ac35f commit 62393c3
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 64 deletions.
82 changes: 20 additions & 62 deletions src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import clsx from 'clsx'
import { Logo, Logomark } from '@/components/Logo'
import { MobileNavigation } from '@/components/MobileNavigation'
import { Navigation } from '@/components/Navigation'
import { TabLinks } from '@/components/TabLinks'
import { Prose } from '@/components/Prose'
import { Search } from '@/components/Search'
import { ThemeSelector } from '@/components/ThemeSelector'
Expand Down Expand Up @@ -377,7 +378,7 @@ const tutorialNavigation = [
},
],
},
];
]

const toolingNavigation = [
{
Expand Down Expand Up @@ -872,87 +873,44 @@ function Header({ navigation }) {
return (
<header
className={clsx(
'sticky top-0 z-50 flex flex-wrap items-center justify-between bg-slate-900 px-4 py-5 shadow-md shadow-slate-900/5 transition duration-500 dark:border-b-2 dark:shadow-none sm:px-6 lg:px-8',
'sticky top-0 z-50 flex flex-wrap items-center justify-between bg-slate-900 px-4 py-5 shadow-md shadow-slate-900/5 transition duration-500 dark:border-b-2 dark:shadow-none sm:px-6 custom:px-8',
isScrolled
? 'dark:bg-slate-900/95 dark:backdrop-blur dark:[@supports(backdrop-filter:blur(0))]:bg-slate-900/75'
: 'dark:bg-transparent'
)}
>
<div className="mr-6 flex lg:hidden">
<div className="mr-6 flex custom:hidden">
<MobileNavigation navigation={navigation} />
</div>
<div className="flex flex-grow items-center justify-between">
<div className="flex items-center">
<Link href="/" aria-label="Home page">
<Logomark className="inline-flex h-8 w-8" />
<h1 className="hidden h-8 w-auto fill-slate-700 text-xl text-white dark:fill-sky-100 dark:text-white lg:inline-flex">
<h1 className="hidden h-8 w-auto fill-slate-700 text-xl text-white dark:fill-sky-100 dark:text-white custom:inline-flex">
Tezos Docs
<span class="m-2 inline-flex items-center rounded-md bg-transparent px-1.5 py-0.5 text-xxs text-white ring-1 ring-inset ring-white dark:bg-transparent dark:text-white dark:ring-white">
Beta
</span>
</h1>
</Link>
<div className="ml-6 flex">
<Link
href="/tezos-blockchain-overview/"
// className="px-4 py-2 text-white hover:text-gray-300"
className={`px-4 py-2 ${
(!router.pathname.includes('tutorials') &&
!router.pathname.includes('office-hours') &&
!isHomePage) ? 'text-blue-400' : 'text-white'
} hover:text-gray-300`}
>
Documentation
</Link>
<Link
href="/tutorials"
// className="px-4 py-2 text-white hover:text-gray-300"
className={`px-4 py-2 ${
router.pathname.includes('/tutorials') ? 'text-blue-400' : 'text-white'
} hover:text-gray-300`}
>
Tutorials
</Link>
<Link
href="/office-hours"
// className="px-4 py-2 text-white hover:text-gray-300"
className={`px-4 py-2 ${
router.pathname.endsWith('office-hours') ? 'text-blue-400' : 'text-white'
} hover:text-gray-300`}
>
Office Hours
</Link>

{/* <Link
href="/tooling"
className="px-4 py-2 text-white hover:text-gray-300"
>
Tooling
</Link>
<Link
href="/resources"
className="px-4 py-2 text-white hover:text-gray-300"
>
Resources
</Link> */}
<div className="hidden custom:flex">
<TabLinks isHomePage={isHomePage} />
</div>
</div>
<div className="-my-5 ">
<div className="relative flex items-center justify-end gap-6 sm:gap-8 custom:flex">
<Search />
<ThemeSelector className="relative z-10" />
<Link
href="https://github.com/trilitech/tezos-developer-docs"
target="_blank"
rel="noopener noreferrer"
className="group"
aria-label="GitHub"
>
<GitHubIcon className="h-6 w-6 fill-slate-400 group-hover:fill-slate-300" />
</Link>
</div>
</div>
<div className="relative flex justify-end gap-6 sm:gap-8">
<ThemeSelector className="relative z-10 ml-4" />
<Link
href="https://github.com/trilitech/tezos-developer-docs"
target="_blank"
rel="noopener noreferrer"
className="group"
aria-label="GitHub"
>
<GitHubIcon className="h-6 w-6 fill-slate-400 group-hover:fill-slate-300" />
</Link>
</div>
</header>
)
}
Expand Down Expand Up @@ -1042,7 +1000,7 @@ export function Layout({ children, title, tableOfContents }) {
}
}, [])
}

let allLinks = flattenLinks(navigation.flatMap((section) => section.links))
let lastLinkIndex = allLinks
.slice()
Expand Down Expand Up @@ -1093,7 +1051,7 @@ export function Layout({ children, title, tableOfContents }) {
<div className="relative mx-auto flex max-w-8xl justify-center sm:px-2 lg:px-8 xl:px-12">
{!isHomePage && !router.pathname.includes('office-hours') && (
// Don't show the left sidebar on the homepage or on office-hours page
<div className="hidden lg:relative lg:block lg:flex-none">
<div className="hidden custom:relative custom:block custom:flex-none">
<div className="absolute inset-y-0 right-0 w-[50vw] bg-slate-50 dark:hidden" />
<div className="absolute top-16 bottom-0 right-0 hidden h-12 w-px bg-gradient-to-t from-slate-800 dark:block" />
<div className="absolute top-28 bottom-0 right-0 hidden w-px bg-slate-800 dark:block" />
Expand Down
7 changes: 6 additions & 1 deletion src/components/MobileNavigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
import { Dialog } from '@headlessui/react'

import { TabLinks } from '@/components/TabLinks'
import { Logomark } from '@/components/Logo'
import { Navigation } from '@/components/Navigation'

Expand Down Expand Up @@ -38,6 +39,7 @@ function CloseIcon(props) {

export function MobileNavigation({ navigation }) {
let router = useRouter()
let isHomePage = router.pathname === '/'
let [isOpen, setIsOpen] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -69,7 +71,7 @@ export function MobileNavigation({ navigation }) {
<Dialog
open={isOpen}
onClose={setIsOpen}
className="fixed inset-0 z-50 flex items-start overflow-y-auto bg-slate-900/50 pr-10 backdrop-blur lg:hidden"
className="fixed inset-0 z-50 flex items-start overflow-y-auto bg-slate-900/50 pr-10 backdrop-blur custom:hidden"
aria-label="Navigation"
>
<Dialog.Panel className="min-h-full w-full max-w-xs bg-white px-4 pt-5 pb-12 dark:bg-slate-900 sm:px-6">
Expand All @@ -85,6 +87,9 @@ export function MobileNavigation({ navigation }) {
<Logomark className="h-9 w-9" />
</Link>
</div>
<div className="block custom:hidden border-b-2 border-gray-300 w-full my-4" /> {/* divider */}
<TabLinks isHomePage={isHomePage} />
<div className="block custom:hidden border-b-2 border-gray-300 w-full my-4" /> {/* divider */}
<Navigation navigation={navigation} className="mt-5 px-1" />
</Dialog.Panel>
</Dialog>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function Search() {
<>
<button
type="button"
className="group flex h-6 w-6 items-center justify-center sm:justify-start md:h-auto md:w-80 md:flex-none md:rounded-lg md:py-2.5 md:pl-4 md:pr-3.5 md:text-sm md:ring-1 md:ring-white/5 md:hover:bg-slate-700/40 md:bg-slate-800/75 md:ring-inset md:ring-white/5 md:hover:bg-slate-700/40 md:hover:ring-slate-500 lg:w-96"
className="group flex h-6 w-6 items-center justify-center sm:justify-start md:h-auto md:w-80 md:flex-none md:rounded-lg md:py-2.5 md:pl-4 md:pr-3.5 md:text-sm md:ring-1 md:bg-slate-800/75 md:ring-inset md:ring-white/5 md:hover:bg-slate-700/40 md:hover:ring-slate-500 lg:w-96"
onClick={onOpen}
>
<SearchIcon className="h-5 w-5 flex-none fill-slate-400 group-hover:fill-slate-500 dark:fill-slate-500 md:group-hover:fill-slate-400" />
Expand Down
131 changes: 131 additions & 0 deletions src/components/TabLinks.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { useRouter } from 'next/router'
import Link from 'next/link'
import { useState, useEffect } from 'react'

export function TabLinks({ isHomePage }) {
const router = useRouter()
const [isLargeScreen, setIsLargeScreen] = useState(false)

useEffect(() => {
const checkScreenSize = () => {
setIsLargeScreen(window.innerWidth >= 1140)
}

// Check initial screen size
checkScreenSize()

window.addEventListener('resize', checkScreenSize)

return () => {
// Clean up event listener
window.removeEventListener('resize', checkScreenSize)
}
}, [])

return (
<div className="-ml-3 flex flex-col custom:-ml-0 custom:flex-row custom:items-center">
<Link
href="/tezos-blockchain-overview/"
className={`px-4 py-2 ${
!router.pathname.includes('tutorials') &&
!router.pathname.includes('office-hours') &&
!isHomePage
? 'text-blue-400'
: 'text-white'
}`}
>
{isLargeScreen ? (
<div className="hover:text-gray-300 dark:hover:text-gray-500">
Documentation
</div>
) : (
<h2
className="font-display font-medium text-slate-900 hover:text-blue-400 dark:text-white"
style={{ fontSize: '1.3em' }}
>
Documentation
</h2>
)}
</Link>
<Link
href="/tutorials"
className={`px-4 py-2 ${
router.pathname.includes('/tutorials')
? 'text-blue-400'
: 'text-white'
}`}
>
{isLargeScreen ? (
<div className="hover:text-gray-300 dark:hover:text-gray-500">
Tutorials
</div>
) : (
<h2
className="font-display font-medium text-slate-900 hover:text-blue-400 dark:text-white"
style={{ fontSize: '1.3em' }}
>
Tutorials
</h2>
)}
</Link>
<Link
href="/office-hours"
className={`px-4 py-2 ${
router.pathname.endsWith('office-hours')
? 'text-blue-400'
: 'text-white'
}`}
>
{isLargeScreen ? (
<div className="hover:text-gray-300 dark:hover:text-gray-500">
Office Hours
</div>
) : (
<h2
className="font-display font-medium text-slate-900 hover:text-blue-400 dark:text-white"
style={{ fontSize: '1.3em' }}
>
Office Hours
</h2>
)}
</Link>
</div>
)

// return (
// <div className="ml-6 flex flex-col custom:flex-row">
// <Link
// href="/tezos-blockchain-overview/"
// className={`px-4 py-2 ${
// (!router.pathname.includes('tutorials') &&
// !router.pathname.includes('office-hours') &&
// !isHomePage)
// ? 'text-blue-400'
// : 'text-white'
// } hover:text-gray-300 dark:hover:text-gray-500`}
// >
// Documentation
// </Link>
// <Link
// href="/tutorials"
// className={`px-4 py-2 ${
// router.pathname.includes('/tutorials')
// ? 'text-blue-400'
// : 'text-white'
// } hover:text-gray-300 dark:hover:text-gray-500`}
// >
// Tutorials
// </Link>
// <Link
// href="/office-hours"
// className={`px-4 py-2 ${
// router.pathname.endsWith('office-hours')
// ? 'text-blue-400'
// : 'text-white'
// } hover:text-gray-300 dark:hover:text-gray-500`}
// >
// Office Hours
// </Link>
// </div>
// );
}
8 changes: 8 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ module.exports = {
'8xl': ['6rem', { lineHeight: '1' }],
'9xl': ['8rem', { lineHeight: '1' }],
},
screens: {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
'custom': '1150px'
},
extend: {
fontFamily: {
sans: ['Inter', ...defaultTheme.fontFamily.sans],
Expand Down

0 comments on commit 62393c3

Please sign in to comment.