Navbar.vue 3.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
<template>
  <header class="navbar" :class="{ 'can-hide': canHide }">
    <slot name="start" />

    <SidebarButton @toggle-sidebar="$emit('toggle-sidebar')" />

    <RouterLink ref="siteInfo" :to="$localePath" class="home-link">
      <img
        v-if="siteBrandLogo"
        class="logo"
        :class="{ light: Boolean(siteBrandDarkLogo) }"
        :src="siteBrandLogo"
        :alt="siteBrandTitle"
      />
      <img
        v-if="siteBrandDarkLogo"
        class="logo dark"
        :src="siteBrandDarkLogo"
        :alt="siteBrandTitle"
      />
      <span
        v-if="siteBrandTitle"
        class="site-name"
        :class="{ 'can-hide': canHideSiteBrandTitle }"
        >{{ siteBrandTitle }}</span
      >
    </RouterLink>

    <slot name="center" />

    <div
      :style="
        linksWrapMaxWidth ? { 'max-width': `${linksWrapMaxWidth}px` } : {}
      "
      class="links"
    >
      <ThemeColor />
      <AlgoliaSearchBox v-if="isAlgoliaSearch" :options="algoliaConfig" />
      <SearchBox
        v-else-if="
          $themeConfig.search !== false && $page.frontmatter.search !== false
        "
      />
      <NavLinks class="can-hide" />
      <LanguageDropdown />
      <RepoLink class="can-hide" />

      <slot name="end" />
    </div>
  </header>
</template>

<script src="./Navbar" />

<style lang="stylus">
.navbar
  position fixed
  z-index 200
  top 0
  left 0
  right 0
  height $navbarHeight
  padding $navbarVerticalPadding $navbarHorizontalPadding
  background var(--bgcolor-blur)
  box-sizing border-box
  box-shadow 0 2px 8px var(--card-shadow-color)
  backdrop-filter saturate(200%) blur(20px)
  line-height: $navbarHeight - $navbarVerticalPadding * 2
  transition transform 0.3s ease-in-out

  @media (max-width $MQMedium)
    height $navbarMobileHeight
    padding $navbarMobileVerticalPadding $navbarMobileHorizontalPadding
    padding-left: $navbarMobileHorizontalPadding + 2.4rem
    line-height: $navbarMobileHeight - $navbarMobileVerticalPadding * 2

  .hide-navbar &.can-hide
    transform translateY(-100%)

  a, span, img
    display inline-block

  .logo
    min-width: 200px
    height: $navbarHeight - $navbarVerticalPadding * 2
    margin-right 0.8rem
    vertical-align top

    @media (max-width $MQMedium)
      min-width: $navbarMobileHeight - $navbarMobileVerticalPadding * 2
      height: $navbarMobileHeight - $navbarMobileVerticalPadding * 2

    .theme-light &
      &.light
        display inline-block

      &.dark
        display none

    .theme-dark &
      &.light
        display none

      &.dark
        display inline-block

  .can-hide
    @media (max-width $MQMedium)
      display none

  .site-name
    font-size 1.5rem
    color var(--text-color)
    position relative

    @media (max-width $MQMedium)
      width calc(100vw - 9.4rem)
      overflow hidden
      white-space nowrap
      text-overflow ellipsis

  .links
    position absolute
    top $navbarVerticalPadding
    right $navbarHorizontalPadding
    display flex
    box-sizing border-box
    padding-left 1.5rem
    font-size 0.9rem
    white-space nowrap

    @media (max-width $MQMedium)
      padding-left 0
      top $navbarMobileVerticalPadding
      right $navbarMobileHorizontalPadding
</style>