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