Skip to content

Commit

Permalink
install navigation menu
Browse files Browse the repository at this point in the history
  • Loading branch information
holtzy committed Aug 9, 2024
1 parent 9d888a4 commit 529f3bc
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 60 deletions.
5 changes: 0 additions & 5 deletions component/LayoutCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { HeadSeo } from './HeadSeo';
import Link from 'next/link';
import { Lesson } from '@/util/lessonList';

// The Layout component
// - adds the top navBar
// - adds the footer
// - adds the head: everything needed for SEO and social media sharing

type LayoutCourseProps = {
children: React.ReactNode;
title: string;
Expand Down
111 changes: 56 additions & 55 deletions component/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,63 @@ export default function Navbar() {
const [isAllSectionModalOpen, setIsAllSectionModalOpen] = useState(false);

return (
<>
<nav id="header" className="w-full h-24 wrapper">
<div
className={'flex flex-wrap items-center justify-between mt-2 py-2'}
>
<div className="flex items-center">
<Link href="/">
<span className="ml-2 text-black text-md lg:text-md cursor-pointer">
The <span className="gradient">React</span> Graph Gallery
</span>
</Link>
</div>
<div className="w-full bg-red-200">Hello</div>
// <>
// <nav id="header" className="w-full h-24 wrapper">
// <div
// className={'flex flex-wrap items-center justify-between mt-2 py-2'}
// >
// <div className="flex items-center">
// <Link href="/">
// <span className="ml-2 text-black text-md lg:text-md cursor-pointer">
// The <span className="gradient">React</span> Graph Gallery
// </span>
// </Link>
// </div>

<div className="">
<Link href="/articles">
<span className="pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider cursor-pointer">
Articles
</span>
</Link>
<Link href="/all" className="no-underline">
<span className="hidden cursor-pointer sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider hover:text-reactGallery">
All
</span>
</Link>
<span
onClick={() => setIsAllSectionModalOpen(true)}
className="hidden sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider cursor-pointer hover:text-reactGallery hiden"
>
Chart types
</span>
{/* <a href="#">
<span className="hidden sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider cursor-not-allowed">
Related
</span>
</a> */}
<Link href="/about" className="no-underline">
<span className="hidden cursor-pointer sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider hover:text-reactGallery">
About
</span>
</Link>
// <div className="">
// <Link href="/articles">
// <span className="pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider cursor-pointer">
// Articles
// </span>
// </Link>
// <Link href="/all" className="no-underline">
// <span className="hidden cursor-pointer sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider hover:text-reactGallery">
// All
// </span>
// </Link>
// <span
// onClick={() => setIsAllSectionModalOpen(true)}
// className="hidden sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider cursor-pointer hover:text-reactGallery hiden"
// >
// Chart types
// </span>
// {/* <a href="#">
// <span className="hidden sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider cursor-not-allowed">
// Related
// </span>
// </a> */}
// <Link href="/about" className="no-underline">
// <span className="hidden cursor-pointer sm:inline pl-8 text-black font-light text-sm lg:text-md uppercase tracking-wider hover:text-reactGallery">
// About
// </span>
// </Link>

<Link href="/subscribe" style={{ textDecoration: 'none' }}>
<span className="hidden cursor-pointer sm:inline ml-8 text-black font-light text-sm lg:text-md uppercase tracking-wider hover:text-reactGallery border border-gray-300 rounded-md p-2">
Subscribe
</span>
</Link>
</div>
</div>
<hr className="border-b border-gray-100 opacity-25 my-0 py-0" />
</nav>
{isAllSectionModalOpen && (
<AllChartsModal
isOpen={isAllSectionModalOpen}
setIsOpen={setIsAllSectionModalOpen}
/>
)}
</>
// <Link href="/subscribe" style={{ textDecoration: 'none' }}>
// <span className="hidden cursor-pointer sm:inline ml-8 text-black font-light text-sm lg:text-md uppercase tracking-wider hover:text-reactGallery border border-gray-300 rounded-md p-2">
// Subscribe
// </span>
// </Link>
// </div>
// </div>
// <hr className="border-b border-gray-100 opacity-25 my-0 py-0" />
// </nav>
// {isAllSectionModalOpen && (
// <AllChartsModal
// isOpen={isAllSectionModalOpen}
// setIsOpen={setIsAllSectionModalOpen}
// />
// )}
// </>
);
}
128 changes: 128 additions & 0 deletions component/UI/navigation-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import * as React from "react"
import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu"
import { cva } from "class-variance-authority"
import { ChevronDown } from "lucide-react"

import { cn } from "@/util/utils"

const NavigationMenu = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<NavigationMenuPrimitive.Root
ref={ref}
className={cn(
"relative z-10 flex max-w-max flex-1 items-center justify-center",
className
)}
{...props}
>
{children}
<NavigationMenuViewport />
</NavigationMenuPrimitive.Root>
))
NavigationMenu.displayName = NavigationMenuPrimitive.Root.displayName

const NavigationMenuList = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.List>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.List>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.List
ref={ref}
className={cn(
"group flex flex-1 list-none items-center justify-center space-x-1",
className
)}
{...props}
/>
))
NavigationMenuList.displayName = NavigationMenuPrimitive.List.displayName

const NavigationMenuItem = NavigationMenuPrimitive.Item

const navigationMenuTriggerStyle = cva(
"group inline-flex h-10 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/50 data-[state=open]:bg-accent/50"
)

const NavigationMenuTrigger = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<NavigationMenuPrimitive.Trigger
ref={ref}
className={cn(navigationMenuTriggerStyle(), "group", className)}
{...props}
>
{children}{" "}
<ChevronDown
className="relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180"
aria-hidden="true"
/>
</NavigationMenuPrimitive.Trigger>
))
NavigationMenuTrigger.displayName = NavigationMenuPrimitive.Trigger.displayName

const NavigationMenuContent = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.Content
ref={ref}
className={cn(
"left-0 top-0 w-full data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 md:absolute md:w-auto ",
className
)}
{...props}
/>
))
NavigationMenuContent.displayName = NavigationMenuPrimitive.Content.displayName

const NavigationMenuLink = NavigationMenuPrimitive.Link

const NavigationMenuViewport = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Viewport>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Viewport>
>(({ className, ...props }, ref) => (
<div className={cn("absolute left-0 top-full flex justify-center")}>
<NavigationMenuPrimitive.Viewport
className={cn(
"origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 md:w-[var(--radix-navigation-menu-viewport-width)]",
className
)}
ref={ref}
{...props}
/>
</div>
))
NavigationMenuViewport.displayName =
NavigationMenuPrimitive.Viewport.displayName

const NavigationMenuIndicator = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Indicator>,
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Indicator>
>(({ className, ...props }, ref) => (
<NavigationMenuPrimitive.Indicator
ref={ref}
className={cn(
"top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in",
className
)}
{...props}
>
<div className="relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md" />
</NavigationMenuPrimitive.Indicator>
))
NavigationMenuIndicator.displayName =
NavigationMenuPrimitive.Indicator.displayName

export {
navigationMenuTriggerStyle,
NavigationMenu,
NavigationMenuList,
NavigationMenuItem,
NavigationMenuContent,
NavigationMenuTrigger,
NavigationMenuLink,
NavigationMenuIndicator,
NavigationMenuViewport,
}
4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/component",
"utils": "@/util/utils"
}
}
58 changes: 58 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-menubar": "^1.1.1",
"@radix-ui/react-navigation-menu": "^1.2.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
Expand Down

0 comments on commit 529f3bc

Please sign in to comment.