| 1 | import * as React from "react"; |
| 2 | import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu"; |
| 3 | import { cva } from "class-variance-authority"; |
| 4 | import { ChevronDown } from "lucide-react"; |
| 5 | |
| 6 | import { cn } from "@/lib/utils"; |
| 7 | |
| 8 | const NavigationMenu = React.forwardRef< |
| 9 | React.ElementRef<typeof NavigationMenuPrimitive.Root>, |
| 10 | React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Root> |
| 11 | >(({ className, children, ...props }, ref) => ( |
| 12 | <NavigationMenuPrimitive.Root |
| 13 | ref={ref} |
| 14 | className={cn("relative z-10 flex max-w-max flex-1 items-center justify-center", className)} |
| 15 | {...props} |
| 16 | > |
| 17 | {children} |
| 18 | <NavigationMenuViewport /> |
| 19 | </NavigationMenuPrimitive.Root> |
| 20 | )); |
| 21 | NavigationMenu.displayName = NavigationMenuPrimitive.Root.displayName; |
| 22 | |
| 23 | const NavigationMenuList = React.forwardRef< |
| 24 | React.ElementRef<typeof NavigationMenuPrimitive.List>, |
| 25 | React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.List> |
| 26 | >(({ className, ...props }, ref) => ( |
| 27 | <NavigationMenuPrimitive.List |
| 28 | ref={ref} |
| 29 | className={cn("group flex flex-1 list-none items-center justify-center space-x-1", className)} |
| 30 | {...props} |
| 31 | /> |
| 32 | )); |
| 33 | NavigationMenuList.displayName = NavigationMenuPrimitive.List.displayName; |
| 34 | |
| 35 | const NavigationMenuItem = NavigationMenuPrimitive.Item; |
| 36 | |
| 37 | const navigationMenuTriggerStyle = cva( |
| 38 | "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", |
| 39 | ); |
| 40 | |
| 41 | const NavigationMenuTrigger = React.forwardRef< |
| 42 | React.ElementRef<typeof NavigationMenuPrimitive.Trigger>, |
| 43 | React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Trigger> |
| 44 | >(({ className, children, ...props }, ref) => ( |
| 45 | <NavigationMenuPrimitive.Trigger |
| 46 | ref={ref} |
| 47 | className={cn(navigationMenuTriggerStyle(), "group", className)} |
| 48 | {...props} |
| 49 | > |
| 50 | {children}{" "} |
| 51 | <ChevronDown |
| 52 | className="relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180" |
| 53 | aria-hidden="true" |
| 54 | /> |
| 55 | </NavigationMenuPrimitive.Trigger> |
| 56 | )); |
| 57 | NavigationMenuTrigger.displayName = NavigationMenuPrimitive.Trigger.displayName; |
| 58 | |
| 59 | const NavigationMenuContent = React.forwardRef< |
| 60 | React.ElementRef<typeof NavigationMenuPrimitive.Content>, |
| 61 | React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content> |
| 62 | >(({ className, ...props }, ref) => ( |
| 63 | <NavigationMenuPrimitive.Content |
| 64 | ref={ref} |
| 65 | className={cn( |
| 66 | "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", |
| 67 | className, |
| 68 | )} |
| 69 | {...props} |
| 70 | /> |
| 71 | )); |
| 72 | NavigationMenuContent.displayName = NavigationMenuPrimitive.Content.displayName; |
| 73 | |
| 74 | const NavigationMenuLink = NavigationMenuPrimitive.Link; |
| 75 | |
| 76 | const NavigationMenuViewport = React.forwardRef< |
| 77 | React.ElementRef<typeof NavigationMenuPrimitive.Viewport>, |
| 78 | React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Viewport> |
| 79 | >(({ className, ...props }, ref) => ( |
| 80 | <div className={cn("absolute left-0 top-full flex justify-center")}> |
| 81 | <NavigationMenuPrimitive.Viewport |
| 82 | className={cn( |
| 83 | "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)]", |
| 84 | className, |
| 85 | )} |
| 86 | ref={ref} |
| 87 | {...props} |
| 88 | /> |
| 89 | </div> |
| 90 | )); |
| 91 | NavigationMenuViewport.displayName = NavigationMenuPrimitive.Viewport.displayName; |
| 92 | |
| 93 | const NavigationMenuIndicator = React.forwardRef< |
| 94 | React.ElementRef<typeof NavigationMenuPrimitive.Indicator>, |
| 95 | React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Indicator> |
| 96 | >(({ className, ...props }, ref) => ( |
| 97 | <NavigationMenuPrimitive.Indicator |
| 98 | ref={ref} |
| 99 | className={cn( |
| 100 | "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", |
| 101 | className, |
| 102 | )} |
| 103 | {...props} |
| 104 | > |
| 105 | <div className="relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md" /> |
| 106 | </NavigationMenuPrimitive.Indicator> |
| 107 | )); |
| 108 | NavigationMenuIndicator.displayName = NavigationMenuPrimitive.Indicator.displayName; |
| 109 | |
| 110 | export { |
| 111 | navigationMenuTriggerStyle, |
| 112 | NavigationMenu, |
| 113 | NavigationMenuList, |
| 114 | NavigationMenuItem, |
| 115 | NavigationMenuContent, |
| 116 | NavigationMenuTrigger, |
| 117 | NavigationMenuLink, |
| 118 | NavigationMenuIndicator, |
| 119 | NavigationMenuViewport, |
| 120 | }; |