AppHeader.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <script setup lang="ts">
  2. import type { NavigationMenuItem } from '@nuxt/ui'
  3. const navigation = inject(navigationInjectionKey)
  4. const { header } = useAppConfig()
  5. const navItems: NavigationMenuItem[] = [
  6. {
  7. label: 'Guide',
  8. to: '/getting-started/installation',
  9. },
  10. {
  11. label: 'API',
  12. to: '/api',
  13. },
  14. ]
  15. const route = useRoute()
  16. const version = useRuntimeConfig().public.pkgVersion
  17. </script>
  18. <template>
  19. <UHeader
  20. :ui="{ center: 'flex-1' }"
  21. :to="header?.to || '/'"
  22. >
  23. <UContentSearchButton
  24. v-if="header?.search"
  25. :collapsed="false"
  26. class="w-full"
  27. variant="subtle"
  28. />
  29. <template
  30. v-if="header?.logo?.dark || header?.logo?.light || header?.title"
  31. #title
  32. >
  33. <UColorModeImage
  34. v-if="header?.logo?.dark || header?.logo?.light"
  35. :light="header?.logo?.light!"
  36. :dark="header?.logo?.dark!"
  37. :alt="header?.logo?.alt"
  38. class="h-6 w-auto shrink-0"
  39. />
  40. <span v-else-if="header?.title">
  41. {{ header.title }}
  42. </span>
  43. </template>
  44. <template
  45. v-else
  46. #left
  47. >
  48. <NuxtLink
  49. :to="header?.to || '/'"
  50. class="mr-2"
  51. >
  52. <TheLogo class="w-auto h-6 shrink-0" />
  53. </NuxtLink>
  54. <UBadge
  55. color="primary"
  56. variant="subtle"
  57. size="sm"
  58. >
  59. {{ version }}
  60. </UBadge>
  61. </template>
  62. <template #right>
  63. <UContentSearchButton
  64. v-if="header?.search"
  65. class="lg:hidden"
  66. variant="subtle"
  67. />
  68. <UNavigationMenu
  69. v-if="route.path === '/'"
  70. :items="navItems"
  71. class="hidden md:flex"
  72. />
  73. <UColorModeButton v-if="header?.colorMode" />
  74. <template v-if="header?.links">
  75. <UButton
  76. v-for="(link, index) of header.links"
  77. :key="index"
  78. v-bind="{ color: 'neutral', variant: 'ghost', ...link }"
  79. />
  80. </template>
  81. </template>
  82. <template #body>
  83. <UContentNavigation
  84. highlight
  85. :navigation="navigation"
  86. />
  87. </template>
  88. </UHeader>
  89. </template>