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