docs/.vitepress/theme/components/NavActions.vue

ba4f23d3bab9e2bb3b8efdb22317c8cc8f353ec5
wotaku/docs/.vitepress/theme/components/NavActions.vue history · blame · raw

222 lines · 6292 bytes

  1<script setup lang="ts">
  2import { Moon, Search, Settings, Sun } from 'lucide-vue-next'
  3import { useData } from 'vitepress'
  4// @ts-ignore
  5import VPSocialLink from 'vitepress/dist/client/theme-default/components/VPSocialLink.vue'
  6import { inject } from 'vue'
  7
  8import { navActions } from '../navActions'
  9import { openSearch } from '../searchState'
 10import { openSettings } from '../settingsState'
 11import NolebaseEnhancedReadabilitiesMenu from './settings/Menu.vue'
 12import BookmarksPanel from './BookmarksPanel.vue'
 13import AnnouncementsPanel from './AnnouncementsPanel.vue'
 14import SettingsPanel from './SettingsPanel.vue'
 15
 16const ICON_SIZE = 18
 17const ICON_STROKE = 2
 18
 19const { isDark } = useData()
 20const toggleAppearance = inject<() => void>('toggle-appearance', () => {
 21  isDark.value = !isDark.value
 22})
 23</script>
 24
 25<template>
 26  <div class="nav-actions-container">
 27  <div class="nav-actions" role="group" aria-label="Site actions">
 28    <template v-for="(action, i) in navActions" :key="i">
 29      <div class="nav-action" :class="`nav-action--${action.type}`">
 30        <button
 31          v-if="action.type === 'search'"
 32          type="button"
 33          class="nav-action-btn"
 34          aria-label="Search"
 35          aria-keyshortcuts="/ control+k meta+k"
 36          @click="openSearch()"
 37        >
 38          <Search :size="ICON_SIZE" :stroke-width="ICON_STROKE" />
 39        </button>
 40
 41        <button
 42          v-else-if="action.type === 'appearance'"
 43          type="button"
 44          class="nav-action-btn"
 45          :aria-label="isDark ? 'Switch to light theme' : 'Switch to dark theme'"
 46          @click="toggleAppearance()"
 47        >
 48          <Moon :size="ICON_SIZE" :stroke-width="ICON_STROKE" class="nav-appearance-moon" />
 49          <Sun :size="ICON_SIZE" :stroke-width="ICON_STROKE" class="nav-appearance-sun" />
 50        </button>
 51
 52        <VPSocialLink
 53          v-else-if="action.type === 'link'"
 54          :icon="action.icon"
 55          :link="action.link"
 56          :aria-label="action.label"
 57          :me="false"
 58        />
 59
 60        <template v-else-if="action.type === 'settings'">
 61          <NolebaseEnhancedReadabilitiesMenu />
 62          <button
 63            type="button"
 64            class="nav-action-btn nav-settings-mobile"
 65            aria-label="Settings"
 66            @click="openSettings()"
 67          >
 68            <Settings :size="ICON_SIZE" :stroke-width="ICON_STROKE" />
 69          </button>
 70        </template>
 71        <BookmarksPanel v-else-if="action.type === 'bookmarks'" />
 72        <AnnouncementsPanel v-else-if="action.type === 'announcement'" />
 73      </div>
 74    </template>
 75  </div>
 76  <SettingsPanel />
 77  </div>
 78</template>
 79
 80<style scoped>
 81.nav-actions-container {
 82  display: flex;
 83  align-items: center;
 84}
 85
 86.nav-actions {
 87  display: flex;
 88  align-items: center;
 89  gap: var(--nav-pill-gap);
 90  height: var(--nav-pill-height);
 91  padding: 0 var(--nav-pill-pad);
 92  border-radius: var(--nav-pill-radius);
 93  background: var(--nav-pill-bg);
 94  border: 1px solid var(--nav-pill-border);
 95  backdrop-filter: blur(var(--nav-pill-blur));
 96  -webkit-backdrop-filter: blur(var(--nav-pill-blur));
 97  transition: background-color 0.3s cubic-bezier(0.16, 1, 0.3, 1);
 98}
 99
100.nav-action {
101  flex: none;
102  width: var(--nav-pill-item-size);
103  height: 100%;
104  display: flex;
105  align-items: center;
106  justify-content: center;
107}
108
109/* collapse the slot when announcements are disabled */
110.nav-action--announcement:empty {
111  display: none;
112}
113
114/* Social links move to the full-screen menu on phones. */
115.nav-action--link {
116  display: none;
117}
118
119@media (min-width: 768px) {
120  .nav-action--link {
121    display: flex;
122  }
123}
124
125/* Doubled class outranks the later `.nav-action-btn { display: flex }`. */
126@media (min-width: 768px) {
127  .nav-action-btn.nav-settings-mobile {
128    display: none;
129  }
130}
131
132.nav-action-btn {
133  display: flex;
134  align-items: center;
135  justify-content: center;
136  width: 100%;
137  height: 100%;
138  color: var(--vp-c-text-1);
139  opacity: 0.55;
140  transition:
141    opacity 0.25s,
142    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
143}
144
145.nav-action-btn:hover { opacity: 1; }
146.nav-action-btn:active { transform: scale(0.94); }
147
148.nav-actions :deep(.VPSocialLink) {
149  width: 100% !important;
150  height: 100% !important;
151  color: var(--vp-c-text-1) !important;
152  opacity: 0.55;
153  transition:
154    opacity 0.25s,
155    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
156}
157.nav-actions :deep(.VPSocialLink:hover) {
158  color: var(--vp-c-text-1) !important;
159  opacity: 1;
160}
161.nav-actions :deep(.VPSocialLink:active) { transform: scale(0.94); }
162.nav-actions :deep(.VPSocialLink > span) {
163  width: var(--nav-pill-icon-size) !important;
164  height: var(--nav-pill-icon-size) !important;
165}
166
167.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout) {
168  display: flex !important;
169  width: 100% !important;
170  height: 100% !important;
171  padding: 0 !important;
172  background: transparent !important;
173  border: 0 !important;
174  border-radius: 0 !important;
175  backdrop-filter: none !important;
176  -webkit-backdrop-filter: none !important;
177}
178
179/* Phones use the full-screen gear instead of the flyout. */
180@media (max-width: 767.9px) {
181  .nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout) {
182    display: none !important;
183  }
184}
185
186.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button) {
187  width: 100% !important;
188  height: 100% !important;
189  padding: 0 !important;
190  display: flex !important;
191  justify-content: center !important;
192  align-items: center !important;
193  color: var(--vp-c-text-1);
194  opacity: 0.55;
195  transition:
196    opacity 0.25s,
197    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
198}
199.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout:hover .button) {
200  opacity: 1;
201}
202.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button:active) {
203  transform: scale(0.94);
204}
205
206.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .text) {
207  color: var(--vp-c-text-1) !important;
208}
209
210.nav-action--settings :deep(.option-icon) {
211  width: var(--nav-pill-icon-size);
212  height: var(--nav-pill-icon-size);
213}
214
215.nav-action--settings :deep(.vpi-chevron-down) { display: none; }
216
217</style>
218
219<style>
220html.dark .nav-appearance-sun { display: none; }
221html:not(.dark) .nav-appearance-moon { display: none; }
222</style>