AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

app-header.tsx 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { Link, usePage } from '@inertiajs/react';
  2. import { BookOpen, Folder, LayoutGrid, Menu, Search } from 'lucide-react';
  3. import AppLogo from '@/components/app-logo';
  4. import AppLogoIcon from '@/components/app-logo-icon';
  5. import { Breadcrumbs } from '@/components/breadcrumbs';
  6. import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
  7. import { Button } from '@/components/ui/button';
  8. import {
  9. DropdownMenu,
  10. DropdownMenuContent,
  11. DropdownMenuTrigger,
  12. } from '@/components/ui/dropdown-menu';
  13. import {
  14. NavigationMenu,
  15. NavigationMenuItem,
  16. NavigationMenuList,
  17. navigationMenuTriggerStyle,
  18. } from '@/components/ui/navigation-menu';
  19. import {
  20. Sheet,
  21. SheetContent,
  22. SheetHeader,
  23. SheetTitle,
  24. SheetTrigger,
  25. } from '@/components/ui/sheet';
  26. import {
  27. Tooltip,
  28. TooltipContent,
  29. TooltipTrigger,
  30. } from '@/components/ui/tooltip';
  31. import { UserMenuContent } from '@/components/user-menu-content';
  32. import { useCurrentUrl } from '@/hooks/use-current-url';
  33. import { useInitials } from '@/hooks/use-initials';
  34. import { cn, toUrl } from '@/lib/utils';
  35. import { dashboard } from '@/routes';
  36. import type { BreadcrumbItem, NavItem } from '@/types';
  37. type Props = {
  38. breadcrumbs?: BreadcrumbItem[];
  39. };
  40. const mainNavItems: NavItem[] = [
  41. {
  42. title: 'Dashboard',
  43. href: dashboard(),
  44. icon: LayoutGrid,
  45. },
  46. ];
  47. const rightNavItems: NavItem[] = [
  48. {
  49. title: 'Repository',
  50. href: 'https://github.com/laravel/react-starter-kit',
  51. icon: Folder,
  52. },
  53. {
  54. title: 'Documentation',
  55. href: 'https://laravel.com/docs/starter-kits#react',
  56. icon: BookOpen,
  57. },
  58. ];
  59. const activeItemStyles =
  60. 'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100';
  61. export function AppHeader({ breadcrumbs = [] }: Props) {
  62. const page = usePage();
  63. const { auth } = page.props;
  64. const getInitials = useInitials();
  65. const { isCurrentUrl, whenCurrentUrl } = useCurrentUrl();
  66. return (
  67. <>
  68. <div className="border-b border-sidebar-border/80">
  69. <div className="mx-auto flex h-16 items-center px-4 md:max-w-7xl">
  70. {/* Mobile Menu */}
  71. <div className="lg:hidden">
  72. <Sheet>
  73. <SheetTrigger asChild>
  74. <Button
  75. variant="ghost"
  76. size="icon"
  77. className="mr-2 h-[34px] w-[34px]"
  78. >
  79. <Menu className="h-5 w-5" />
  80. </Button>
  81. </SheetTrigger>
  82. <SheetContent
  83. side="left"
  84. className="flex h-full w-64 flex-col items-stretch justify-between bg-sidebar"
  85. >
  86. <SheetTitle className="sr-only">
  87. Navigation menu
  88. </SheetTitle>
  89. <SheetHeader className="flex justify-start text-left">
  90. <AppLogoIcon className="h-6 w-6 fill-current text-black dark:text-white" />
  91. </SheetHeader>
  92. <div className="flex h-full flex-1 flex-col space-y-4 p-4">
  93. <div className="flex h-full flex-col justify-between text-sm">
  94. <div className="flex flex-col space-y-4">
  95. {mainNavItems.map((item) => (
  96. <Link
  97. key={item.title}
  98. href={item.href}
  99. className="flex items-center space-x-2 font-medium"
  100. >
  101. {item.icon && (
  102. <item.icon className="h-5 w-5" />
  103. )}
  104. <span>{item.title}</span>
  105. </Link>
  106. ))}
  107. </div>
  108. <div className="flex flex-col space-y-4">
  109. {rightNavItems.map((item) => (
  110. <a
  111. key={item.title}
  112. href={toUrl(item.href)}
  113. target="_blank"
  114. rel="noopener noreferrer"
  115. className="flex items-center space-x-2 font-medium"
  116. >
  117. {item.icon && (
  118. <item.icon className="h-5 w-5" />
  119. )}
  120. <span>{item.title}</span>
  121. </a>
  122. ))}
  123. </div>
  124. </div>
  125. </div>
  126. </SheetContent>
  127. </Sheet>
  128. </div>
  129. <Link
  130. href={dashboard()}
  131. prefetch
  132. className="flex items-center space-x-2"
  133. >
  134. <AppLogo />
  135. </Link>
  136. {/* Desktop Navigation */}
  137. <div className="ml-6 hidden h-full items-center space-x-6 lg:flex">
  138. <NavigationMenu className="flex h-full items-stretch">
  139. <NavigationMenuList className="flex h-full items-stretch space-x-2">
  140. {mainNavItems.map((item, index) => (
  141. <NavigationMenuItem
  142. key={index}
  143. className="relative flex h-full items-center"
  144. >
  145. <Link
  146. href={item.href}
  147. className={cn(
  148. navigationMenuTriggerStyle(),
  149. whenCurrentUrl(
  150. item.href,
  151. activeItemStyles,
  152. ),
  153. 'h-9 cursor-pointer px-3',
  154. )}
  155. >
  156. {item.icon && (
  157. <item.icon className="mr-2 h-4 w-4" />
  158. )}
  159. {item.title}
  160. </Link>
  161. {isCurrentUrl(item.href) && (
  162. <div className="absolute bottom-0 left-0 h-0.5 w-full translate-y-px bg-black dark:bg-white"></div>
  163. )}
  164. </NavigationMenuItem>
  165. ))}
  166. </NavigationMenuList>
  167. </NavigationMenu>
  168. </div>
  169. <div className="ml-auto flex items-center space-x-2">
  170. <div className="relative flex items-center space-x-1">
  171. <Button
  172. variant="ghost"
  173. size="icon"
  174. className="group h-9 w-9 cursor-pointer"
  175. >
  176. <Search className="!size-5 opacity-80 group-hover:opacity-100" />
  177. </Button>
  178. <div className="ml-1 hidden gap-1 lg:flex">
  179. {rightNavItems.map((item) => (
  180. <Tooltip key={item.title}>
  181. <TooltipTrigger>
  182. <a
  183. href={toUrl(item.href)}
  184. target="_blank"
  185. rel="noopener noreferrer"
  186. className="group inline-flex h-9 w-9 items-center justify-center rounded-md bg-transparent p-0 text-sm font-medium text-accent-foreground ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50"
  187. >
  188. <span className="sr-only">
  189. {item.title}
  190. </span>
  191. {item.icon && (
  192. <item.icon className="size-5 opacity-80 group-hover:opacity-100" />
  193. )}
  194. </a>
  195. </TooltipTrigger>
  196. <TooltipContent>
  197. <p>{item.title}</p>
  198. </TooltipContent>
  199. </Tooltip>
  200. ))}
  201. </div>
  202. </div>
  203. <DropdownMenu>
  204. <DropdownMenuTrigger asChild>
  205. <Button
  206. variant="ghost"
  207. className="size-10 rounded-full p-1"
  208. >
  209. <Avatar className="size-8 overflow-hidden rounded-full">
  210. <AvatarImage
  211. src={auth.user?.avatar}
  212. alt={auth.user?.name}
  213. />
  214. <AvatarFallback className="rounded-lg bg-neutral-200 text-black dark:bg-neutral-700 dark:text-white">
  215. {getInitials(auth.user?.name ?? '')}
  216. </AvatarFallback>
  217. </Avatar>
  218. </Button>
  219. </DropdownMenuTrigger>
  220. <DropdownMenuContent className="w-56" align="end">
  221. {auth.user && (
  222. <UserMenuContent user={auth.user} />
  223. )}
  224. </DropdownMenuContent>
  225. </DropdownMenu>
  226. </div>
  227. </div>
  228. </div>
  229. {breadcrumbs.length > 1 && (
  230. <div className="flex w-full border-b border-sidebar-border/70">
  231. <div className="mx-auto flex h-12 w-full items-center justify-start px-4 text-neutral-500 md:max-w-7xl">
  232. <Breadcrumbs breadcrumbs={breadcrumbs} />
  233. </div>
  234. </div>
  235. )}
  236. </>
  237. );
  238. }