|
| 1 | +<script setup lang="ts"> |
| 2 | +const { bookmarks, hasBookmarks, removeBookmark, clearBookmarks } = useBookmarks() |
| 3 | +
|
| 4 | +const isOpen = ref(false) |
| 5 | +
|
| 6 | +function handleMouseEnter() { |
| 7 | + isOpen.value = true |
| 8 | +} |
| 9 | +
|
| 10 | +function handleMouseLeave() { |
| 11 | + isOpen.value = false |
| 12 | +} |
| 13 | +
|
| 14 | +function handleKeydown(event: KeyboardEvent) { |
| 15 | + if (event.key === 'Escape' && isOpen.value) { |
| 16 | + isOpen.value = false |
| 17 | + } |
| 18 | +} |
| 19 | +
|
| 20 | +function handleRemove(packageName: string, event: Event) { |
| 21 | + event.preventDefault() |
| 22 | + event.stopPropagation() |
| 23 | + removeBookmark(packageName) |
| 24 | +} |
| 25 | +
|
| 26 | +function handleClearAll(event: Event) { |
| 27 | + event.preventDefault() |
| 28 | + clearBookmarks() |
| 29 | +} |
| 30 | +</script> |
| 31 | + |
| 32 | +<template> |
| 33 | + <div |
| 34 | + class="relative flex items-center" |
| 35 | + @mouseenter="handleMouseEnter" |
| 36 | + @mouseleave="handleMouseLeave" |
| 37 | + @keydown="handleKeydown" |
| 38 | + > |
| 39 | + <button |
| 40 | + type="button" |
| 41 | + class="link-subtle font-mono text-sm inline-flex items-center gap-1 leading-tight" |
| 42 | + :aria-expanded="isOpen" |
| 43 | + aria-haspopup="true" |
| 44 | + > |
| 45 | + <span |
| 46 | + class="w-[1em] h-[1em] shrink-0" |
| 47 | + :class="hasBookmarks ? 'i-carbon-bookmark-filled' : 'i-carbon-bookmark'" |
| 48 | + aria-hidden="true" |
| 49 | + /> |
| 50 | + <span class="hidden sm:inline">{{ $t('header.bookmarks') }}</span> |
| 51 | + <span |
| 52 | + class="hidden sm:inline i-carbon-chevron-down w-3 h-3 transition-transform duration-200" |
| 53 | + :class="{ 'rotate-180': isOpen }" |
| 54 | + aria-hidden="true" |
| 55 | + /> |
| 56 | + </button> |
| 57 | + |
| 58 | + <Transition |
| 59 | + enter-active-class="transition-all duration-150" |
| 60 | + leave-active-class="transition-all duration-100" |
| 61 | + enter-from-class="opacity-0 translate-y-1" |
| 62 | + leave-to-class="opacity-0 translate-y-1" |
| 63 | + > |
| 64 | + <div v-if="isOpen" class="absolute inset-ie-0 top-full pt-2 w-72 z-50"> |
| 65 | + <div class="bg-bg-elevated border border-border rounded-lg shadow-lg overflow-hidden"> |
| 66 | + <div class="px-3 py-2 border-b border-border flex items-center justify-between"> |
| 67 | + <span class="font-mono text-xs text-fg-subtle"> |
| 68 | + {{ $t('header.bookmarks_dropdown.title') }} |
| 69 | + </span> |
| 70 | + <button |
| 71 | + v-if="hasBookmarks" |
| 72 | + type="button" |
| 73 | + class="font-mono text-xs text-fg-subtle hover:text-fg transition-colors" |
| 74 | + @click="handleClearAll" |
| 75 | + > |
| 76 | + {{ $t('header.bookmarks_dropdown.clear_all') }} |
| 77 | + </button> |
| 78 | + </div> |
| 79 | + |
| 80 | + <ul v-if="hasBookmarks" class="py-1 max-h-80 overflow-y-auto"> |
| 81 | + <li v-for="bookmark in bookmarks" :key="bookmark.packageName"> |
| 82 | + <div class="flex items-center gap-1 px-3 hover:bg-bg-subtle transition-colors"> |
| 83 | + <NuxtLink |
| 84 | + :to="`/${bookmark.packageName}`" |
| 85 | + class="flex-1 py-2 font-mono text-sm text-fg truncate" |
| 86 | + > |
| 87 | + {{ bookmark.packageName }} |
| 88 | + </NuxtLink> |
| 89 | + <button |
| 90 | + type="button" |
| 91 | + class="p-1 text-fg-subtle hover:text-fg transition-colors shrink-0" |
| 92 | + :aria-label=" |
| 93 | + $t('header.bookmarks_dropdown.remove', { name: bookmark.packageName }) |
| 94 | + " |
| 95 | + @click="handleRemove(bookmark.packageName, $event)" |
| 96 | + > |
| 97 | + <span class="i-carbon-close w-3 h-3 block" aria-hidden="true" /> |
| 98 | + </button> |
| 99 | + </div> |
| 100 | + </li> |
| 101 | + </ul> |
| 102 | + |
| 103 | + <div v-else class="px-3 py-4 text-center"> |
| 104 | + <span class="text-fg-muted text-sm"> |
| 105 | + {{ $t('header.bookmarks_dropdown.empty') }} |
| 106 | + </span> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </Transition> |
| 111 | + </div> |
| 112 | +</template> |
0 commit comments