|
1 | 1 | <script setup lang="ts"> |
| 2 | +import type { LogoContextMenuItem } from '../types' |
2 | 3 | import { useData, withBase } from 'vitepress' |
3 | | -import { computed } from 'vue' |
| 4 | +import { computed, ref } from 'vue' |
4 | 5 |
|
5 | 6 | const { site, theme } = useData() |
6 | 7 |
|
7 | 8 | const removeNimiqPrefix = (str: string) => str.toLocaleLowerCase().startsWith('nimiq') ? str.slice(6) : str |
8 | 9 | const name = computed(() => removeNimiqPrefix(site.value.title)) |
| 10 | +
|
| 11 | +// Context menu state |
| 12 | +const showContextMenu = ref(false) |
| 13 | +const contextMenuX = ref(0) |
| 14 | +const contextMenuY = ref(0) |
| 15 | +
|
| 16 | +// Get version from Vite config |
| 17 | +const version = (window as any).__NIMIQ_VITEPRESS_CONFIG__?.version |
| 18 | +
|
| 19 | +// Context menu configuration |
| 20 | +const showVersion = computed(() => theme.value.logoContextMenu?.showVersion !== false) |
| 21 | +const customItems = computed<LogoContextMenuItem[]>(() => theme.value.logoContextMenu?.items || []) |
| 22 | +const hasContextMenu = computed(() => (showVersion.value && version) || customItems.value.length > 0) |
| 23 | +
|
| 24 | +function handleContextMenu(event: MouseEvent) { |
| 25 | + if (!hasContextMenu.value) |
| 26 | + return |
| 27 | +
|
| 28 | + event.preventDefault() |
| 29 | + contextMenuX.value = event.clientX |
| 30 | + contextMenuY.value = event.clientY |
| 31 | + showContextMenu.value = true |
| 32 | +} |
| 33 | +
|
| 34 | +function closeContextMenu() { |
| 35 | + showContextMenu.value = false |
| 36 | +} |
| 37 | +
|
| 38 | +function handleItemClick(item: LogoContextMenuItem) { |
| 39 | + if (item.onClick) { |
| 40 | + item.onClick() |
| 41 | + } |
| 42 | + else if (item.href) { |
| 43 | + window.open(item.href, '_blank') |
| 44 | + } |
| 45 | + closeContextMenu() |
| 46 | +} |
| 47 | +
|
| 48 | +// Close context menu on click outside |
| 49 | +if (typeof window !== 'undefined') { |
| 50 | + window.addEventListener('click', () => { |
| 51 | + if (showContextMenu.value) |
| 52 | + closeContextMenu() |
| 53 | + }) |
| 54 | +} |
9 | 55 | </script> |
10 | 56 |
|
11 | 57 | <template> |
12 | 58 | <div> |
13 | | - <a flex="~ items-center gap-8 shrink-0" w-full text-neutral font-semibold :href="withBase('/')"> |
| 59 | + <a |
| 60 | + flex="~ items-center gap-8 shrink-0" |
| 61 | + w-full |
| 62 | + text-neutral |
| 63 | + font-semibold |
| 64 | + :href="withBase('/')" |
| 65 | + @contextmenu="handleContextMenu" |
| 66 | + > |
14 | 67 | <img v-if="theme.logo" class="logo" :src="theme.logo"> |
15 | 68 | <div v-else i-nimiq:logos-nimiq-horizontal text-20 dark:i-nimiq:logos-nimiq-white-horizontal /> |
16 | 69 | <span translate-y--1 text-16 font-light tracking-wide>{{ name }}</span> |
17 | 70 | <span v-if="theme.betaBadge" text-10 font-semibold px-6 py-2 bg-blue-500 text-white rounded-4 translate-y--1>BETA</span> |
18 | 71 | </a> |
| 72 | + |
| 73 | + <!-- Context Menu --> |
| 74 | + <Teleport v-if="showContextMenu" to="body"> |
| 75 | + <div |
| 76 | + fixed |
| 77 | + bg-white |
| 78 | + dark:bg-neutral-800 |
| 79 | + border="1 solid neutral-200 dark:neutral-700" |
| 80 | + rounded-8 |
| 81 | + shadow-lg |
| 82 | + py-4 |
| 83 | + min-w-150 |
| 84 | + z-9999 |
| 85 | + :style="{ left: `${contextMenuX}px`, |
| 86 | + top: `${contextMenuY}px` }" |
| 87 | + @click.stop |
| 88 | + > |
| 89 | + <!-- Version --> |
| 90 | + <div |
| 91 | + v-if="showVersion && version" |
| 92 | + px-12 |
| 93 | + py-6 |
| 94 | + text-12 |
| 95 | + text-neutral-500 |
| 96 | + dark:text-neutral-400 |
| 97 | + font-mono |
| 98 | + border-b="1 solid neutral-200 dark:neutral-700" |
| 99 | + mb-4 |
| 100 | + > |
| 101 | + v{{ version }} |
| 102 | + </div> |
| 103 | + |
| 104 | + <!-- Custom Items --> |
| 105 | + <button |
| 106 | + v-for="(item, index) in customItems" |
| 107 | + :key="index" |
| 108 | + w-full |
| 109 | + px-12 |
| 110 | + py-8 |
| 111 | + text-left |
| 112 | + text-14 |
| 113 | + text-neutral-700 |
| 114 | + dark:text-neutral-300 |
| 115 | + hover="bg-neutral-100 dark:bg-neutral-700" |
| 116 | + transition-colors |
| 117 | + cursor-pointer |
| 118 | + @click="handleItemClick(item)" |
| 119 | + > |
| 120 | + {{ item.label }} |
| 121 | + </button> |
| 122 | + </div> |
| 123 | + </Teleport> |
19 | 124 | </div> |
20 | 125 | </template> |
0 commit comments