docs/.vitepress/theme/components/NavActions.vue
200 lines · 5420 bytes
1<script setup lang="ts">
2import { Moon, Search, 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 NolebaseEnhancedReadabilitiesMenu from './settings/Menu.vue'
11import BookmarksPanel from './BookmarksPanel.vue'
12
13const ICON_SIZE = 18
14const ICON_STROKE = 2
15
16const { isDark } = useData()
17const toggleAppearance = inject<() => void>('toggle-appearance', () => {
18 isDark.value = !isDark.value
19})
20</script>
21
22<template>
23 <div class="nav-actions-container">
24 <div class="nav-bookmark-mobile">
25 <BookmarksPanel />
26 </div>
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 <NolebaseEnhancedReadabilitiesMenu v-else-if="action.type === 'settings'" />
61 <BookmarksPanel v-else-if="action.type === 'bookmarks'" />
62 </div>
63 </template>
64 </div>
65 </div>
66</template>
67
68<style scoped>
69.nav-actions-container {
70 display: flex;
71 align-items: center;
72}
73
74.nav-bookmark-mobile {
75 display: flex;
76 align-items: center;
77 justify-content: center;
78 width: 36px;
79 height: var(--vp-nav-height);
80}
81
82@media (min-width: 768px) {
83 .nav-bookmark-mobile {
84 display: none;
85 }
86}
87
88.nav-actions {
89 display: none;
90 align-items: center;
91 gap: var(--nav-pill-gap);
92 height: var(--nav-pill-height);
93 padding: 0 var(--nav-pill-pad);
94 border-radius: var(--nav-pill-radius);
95 background: var(--nav-pill-bg);
96 border: 1px solid var(--nav-pill-border);
97 backdrop-filter: blur(var(--nav-pill-blur));
98 -webkit-backdrop-filter: blur(var(--nav-pill-blur));
99 transition: background-color 0.3s cubic-bezier(0.16, 1, 0.3, 1);
100}
101
102@media (min-width: 768px) {
103 .nav-actions {
104 display: flex;
105 }
106}
107
108.nav-action {
109 flex: none;
110 width: var(--nav-pill-item-size);
111 height: 100%;
112 display: flex;
113 align-items: center;
114 justify-content: center;
115}
116
117.nav-action-btn {
118 display: flex;
119 align-items: center;
120 justify-content: center;
121 width: 100%;
122 height: 100%;
123 color: var(--vp-c-text-1);
124 opacity: 0.55;
125 transition:
126 opacity 0.25s,
127 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
128}
129
130.nav-action-btn:hover { opacity: 1; }
131.nav-action-btn:active { transform: scale(0.94); }
132
133.nav-actions :deep(.VPSocialLink) {
134 width: 100% !important;
135 height: 100% !important;
136 color: var(--vp-c-text-1) !important;
137 opacity: 0.55;
138 transition:
139 opacity 0.25s,
140 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
141}
142.nav-actions :deep(.VPSocialLink:hover) {
143 color: var(--vp-c-text-1) !important;
144 opacity: 1;
145}
146.nav-actions :deep(.VPSocialLink:active) { transform: scale(0.94); }
147.nav-actions :deep(.VPSocialLink > span) {
148 width: var(--nav-pill-icon-size) !important;
149 height: var(--nav-pill-icon-size) !important;
150}
151
152.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout) {
153 display: flex !important;
154 width: 100% !important;
155 height: 100% !important;
156 padding: 0 !important;
157 background: transparent !important;
158 border: 0 !important;
159 border-radius: 0 !important;
160 backdrop-filter: none !important;
161 -webkit-backdrop-filter: none !important;
162}
163
164.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button) {
165 width: 100% !important;
166 height: 100% !important;
167 padding: 0 !important;
168 display: flex !important;
169 justify-content: center !important;
170 align-items: center !important;
171 color: var(--vp-c-text-1);
172 opacity: 0.55;
173 transition:
174 opacity 0.25s,
175 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
176}
177.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout:hover .button) {
178 opacity: 1;
179}
180.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button:active) {
181 transform: scale(0.94);
182}
183
184.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .text) {
185 color: var(--vp-c-text-1) !important;
186}
187
188.nav-action--settings :deep(.option-icon) {
189 width: var(--nav-pill-icon-size);
190 height: var(--nav-pill-icon-size);
191}
192
193.nav-action--settings :deep(.vpi-chevron-down) { display: none; }
194
195</style>
196
197<style>
198html.dark .nav-appearance-sun { display: none; }
199html:not(.dark) .nav-appearance-moon { display: none; }
200</style>