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

Created Dropdown Options #897

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 1 addition & 20 deletions app/tag-data.json
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
{
"markdown": 1,
"code": 1,
"features": 1,
"next-js": 6,
"math": 1,
"ols": 1,
"github": 1,
"guide": 5,
"tailwind": 3,
"hello": 1,
"holiday": 1,
"canada": 1,
"images": 1,
"feature": 2,
"writings": 1,
"book": 1,
"reflection": 1,
"multi-author": 1
}
{"markdown":1,"code":1,"features":1,"next-js":6,"math":1,"ols":1,"github":1,"guide":5,"tailwind":3,"holiday":1,"canada":1,"images":1,"feature":2,"writings":1,"book":1,"reflection":1,"multi-author":1}
2 changes: 2 additions & 0 deletions components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from './Link'
import MobileNav from './MobileNav'
import ThemeSwitch from './ThemeSwitch'
import SearchButton from './SearchButton'
import { NavOptions } from './NavOptions'

const Header = () => {
return (
Expand Down Expand Up @@ -37,6 +38,7 @@ const Header = () => {
{link.title}
</Link>
))}
<NavOptions />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the rendering of all the headerNavLinks to NavOptions

<SearchButton />
<ThemeSwitch />
<MobileNav />
Expand Down
14 changes: 13 additions & 1 deletion components/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useState } from 'react'
import Link from './Link'
import headerNavLinks from '@/data/headerNavLinks'
import headerNavLinks, { headerNavOptions } from '@/data/headerNavLinks'

const MobileNav = () => {
const [navShow, setNavShow] = useState(false)
Expand Down Expand Up @@ -68,6 +68,18 @@ const MobileNav = () => {
</Link>
</div>
))}
{headerNavOptions.children &&
headerNavOptions.children.map((link) => (
<div key={link.title} className="px-12 py-4">
<Link
href={link.href}
className="text-2xl font-bold tracking-widest text-gray-900 dark:text-gray-100"
onClick={onToggleNav}
>
{link.title}
</Link>
</div>
))}
</nav>
</div>
</>
Expand Down
48 changes: 48 additions & 0 deletions components/NavOptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use client'

import { Fragment, useEffect, useState } from 'react'
import { useTheme } from 'next-themes'
import { Menu, RadioGroup, Transition } from '@headlessui/react'
import { headerNavOptions } from '@/data/headerNavLinks'
import Link from 'next/link'

export const NavOptions = () => {
return (
<div className="mr-5">
<Menu as="div" className="relative inline-block text-left">
<div>
{headerNavOptions.title && (
<Menu.Button className={'hidden font-medium text-gray-900 dark:text-gray-100 sm:block'}>
{headerNavOptions.title}
</Menu.Button>
)}
</div>
<Transition
as={Fragment}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items className="absolute right-0 mt-2 w-32 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-800">
<div className="p-1">
{headerNavOptions.children &&
headerNavOptions.children.map((link) => (
<Menu.Item key={link.title}>
<Link
href={link.href}
className="group flex w-full items-center rounded-md px-2 py-2 text-sm"
>
{link.title}
</Link>
</Menu.Item>
))}
</div>
</Menu.Items>
</Transition>
</Menu>
</div>
)
}
8 changes: 8 additions & 0 deletions data/headerNavLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ const headerNavLinks = [
{ href: '/about', title: 'About' },
]

export const headerNavOptions = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an additional field. You can modify the original headerNavLink to something like this:

const headerNavLinks = [
  { href: '/', title: 'Home' },
  { href: '/blog', title: 'Blog' },
  { href: '/tags', title: 'Tags' },
  { title: 'Others': children: [
    { href: '/projects', title: 'Projects' },
    { href: '/about', title: 'About' },
  ]
]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it I'll see if i could do that and will change

title: 'Dropdown', children: [
{href: '/projects', title: 'Projects',},
{href: '/about', title: 'About',},
]
}


export default headerNavLinks