docs/.vitepress/theme/components/NavActions.vue
169 lines · 4719 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'
11
12const ICON_SIZE = 18
13const ICON_STROKE = 2
14
15const { isDark } = useData()
16const toggleAppearance = inject<() => void>('toggle-appearance', () => {
17 isDark.value = !isDark.value
18})
19</script>
20
21<template>
22 <div class="nav-actions" role="group" aria-label="Site actions">
23 <template v-for="(action, i) in navActions" :key="i">
24 <div class="nav-action" :class="`nav-action--${action.type}`">
25 <button
26 v-if="action.type === 'search'"
27 type="button"
28 class="nav-action-btn"
29 aria-label="Search"
30 aria-keyshortcuts="/ control+k meta+k"
31 @click="openSearch()"
32 >
33 <Search :size="ICON_SIZE" :stroke-width="ICON_STROKE" />
34 </button>
35
36 <button
37 v-else-if="action.type === 'appearance'"
38 type="button"
39 class="nav-action-btn"
40 :aria-label="isDark ? 'Switch to light theme' : 'Switch to dark theme'"
41 @click="toggleAppearance()"
42 >
43 <Moon :size="ICON_SIZE" :stroke-width="ICON_STROKE" class="nav-appearance-moon" />
44 <Sun :size="ICON_SIZE" :stroke-width="ICON_STROKE" class="nav-appearance-sun" />
45 </button>
46
47 <VPSocialLink
48 v-else-if="action.type === 'link'"
49 :icon="action.icon"
50 :link="action.link"
51 :aria-label="action.label"
52 :me="false"
53 />
54
55 <NolebaseEnhancedReadabilitiesMenu v-else-if="action.type === 'settings'" />
56 </div>
57 </template>
58 </div>
59</template>
60
61<style scoped>
62.nav-actions {
63 display: none;
64 align-items: center;
65 gap: var(--nav-pill-gap);
66 height: var(--nav-pill-height);
67 padding: 0 var(--nav-pill-pad);
68 border-radius: var(--nav-pill-radius);
69 background: var(--nav-pill-bg);
70 border: 1px solid var(--nav-pill-border);
71 backdrop-filter: blur(var(--nav-pill-blur));
72 -webkit-backdrop-filter: blur(var(--nav-pill-blur));
73 transition: background-color 0.3s cubic-bezier(0.16, 1, 0.3, 1);
74}
75
76@media (min-width: 768px) {
77 .nav-actions {
78 display: flex;
79 }
80}
81
82.nav-action {
83 flex: none;
84 width: var(--nav-pill-item-size);
85 height: 100%;
86 display: flex;
87 align-items: center;
88 justify-content: center;
89}
90
91.nav-action-btn {
92 display: flex;
93 align-items: center;
94 justify-content: center;
95 width: 100%;
96 height: 100%;
97 color: var(--vp-c-text-1);
98 opacity: 0.55;
99 transition:
100 opacity 0.25s,
101 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
102}
103
104.nav-action-btn:hover { opacity: 1; }
105.nav-action-btn:active { transform: scale(0.94); }
106
107.nav-actions :deep(.VPSocialLink) {
108 width: 100% !important;
109 height: 100% !important;
110 color: var(--vp-c-text-1) !important;
111 opacity: 0.55;
112 transition:
113 opacity 0.25s,
114 transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
115}
116.nav-actions :deep(.VPSocialLink:hover) {
117 color: var(--vp-c-text-1) !important;
118 opacity: 1;
119}
120.nav-actions :deep(.VPSocialLink:active) { transform: scale(0.94); }
121.nav-actions :deep(.VPSocialLink > span) {
122 width: var(--nav-pill-icon-size) !important;
123 height: var(--nav-pill-icon-size) !important;
124}
125
126.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout) {
127 display: flex !important;
128 width: 100% !important;
129 height: 100% !important;
130 padding: 0 !important;
131 background: transparent !important;
132 border: 0 !important;
133 border-radius: 0 !important;
134 backdrop-filter: none !important;
135 -webkit-backdrop-filter: none !important;
136}
137
138.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .button) {
139 width: 100% !important;
140 height: auto !important;
141 padding: 0 !important;
142 display: flex !important;
143 justify-content: center !important;
144 align-items: center !important;
145 color: var(--vp-c-text-1);
146 opacity: 0.55;
147 transition: opacity 0.25s;
148}
149.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout:hover .button) {
150 opacity: 1;
151}
152
153.nav-action--settings :deep(.VPNolebaseEnhancedReadabilitiesMenuFlyout .text) {
154 color: var(--vp-c-text-1) !important;
155}
156
157.nav-action--settings :deep(.option-icon) {
158 width: var(--nav-pill-icon-size);
159 height: var(--nav-pill-icon-size);
160}
161
162.nav-action--settings :deep(.vpi-chevron-down) { display: none; }
163
164</style>
165
166<style>
167html.dark .nav-appearance-sun { display: none; }
168html:not(.dark) .nav-appearance-moon { display: none; }
169</style>