Commit 1c94f24567
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/AnnouncementTypeSelect.vue +10 −10
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <script setup lang="ts"> |
| 2 | 2 | import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui' |
| 3 | import { onMounted, onUnmounted, ref } from 'vue' | |
| 3 | import { onClickOutside } from '@vueuse/core' | |
| 4 | import { ref } from 'vue' | |
| 4 | 5 | import type { AnnouncementType } from '../composables/useAnnouncements' |
| 5 | 6 | import MenuHelp from './settings/MenuHelp.vue' |
| 6 | 7 | import MenuTitle from './settings/MenuTitle.vue' |
| @@ -19,8 +20,10 @@ const OPTIONS: { value: AnnouncementType; label: string }[] = [ | ||
| 19 | 20 | { value: 'improvement', label: 'Improvement' } |
| 20 | 21 | ] |
| 21 | 22 | |
| 22 | function labelFor(value: string): string { | |
| 23 | return OPTIONS.find((o) => o.value === value)?.label ?? 'All types' | |
| 23 | const OPTIONS_MAP: Record<string, string> = { | |
| 24 | section: 'Section', | |
| 25 | component: 'Component', | |
| 26 | improvement: 'Improvement' | |
| 24 | 27 | } |
| 25 | 28 | |
| 26 | 29 | const rootRef = ref<HTMLElement>() |
| @@ -33,12 +36,9 @@ function select(value: string) { | ||
| 33 | 36 | open.value = false |
| 34 | 37 | } |
| 35 | 38 | |
| 36 | function onDocClick(e: MouseEvent) { | |
| 37 | if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false | |
| 38 | } | |
| 39 | ||
| 40 | onMounted(() => document.addEventListener('click', onDocClick, true)) | |
| 41 | onUnmounted(() => document.removeEventListener('click', onDocClick, true)) | |
| 39 | onClickOutside(rootRef, () => { | |
| 40 | open.value = false | |
| 41 | }) | |
| 42 | 42 | </script> |
| 43 | 43 | |
| 44 | 44 | <template> |
| @@ -91,7 +91,7 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true)) | ||
| 91 | 91 | :aria-expanded="open" |
| 92 | 92 | @click="open = !open" |
| 93 | 93 | > |
| 94 | <span class="ann-type-label">{{ labelFor(modelValue) }}</span> | |
| 94 | <span class="ann-type-label">{{ OPTIONS_MAP[modelValue] ?? 'All types' }}</span> | |
| 95 | 95 | <span class="ann-type-chevron i-lucide:chevron-down" :class="{ 'ann-type-chevron--open': open }" /> |
| 96 | 96 | </button> |
| 97 | 97 | |
docs/.vitepress/theme/components/AnnouncementsPanel.vue +11 −8
| @@ -103,9 +103,16 @@ watch(isOpen, async (open) => { | ||
| 103 | 103 | onScroll() |
| 104 | 104 | }) |
| 105 | 105 | |
| 106 | let resizeTick = false | |
| 106 | 107 | useEventListener(inBrowser ? window : undefined, 'resize', () => { |
| 107 | if (isOpen.value) updatePanelPosition() | |
| 108 | if (filterOpen.value) updateFilterPosition() | |
| 108 | if (!resizeTick) { | |
| 109 | window.requestAnimationFrame(() => { | |
| 110 | if (isOpen.value) updatePanelPosition() | |
| 111 | if (filterOpen.value) updateFilterPosition() | |
| 112 | resizeTick = false | |
| 113 | }) | |
| 114 | resizeTick = true | |
| 115 | } | |
| 109 | 116 | }) |
| 110 | 117 | |
| 111 | 118 | function updateFilterPosition() { |
| @@ -173,14 +180,10 @@ function onKeydown(e: KeyboardEvent) { | ||
| 173 | 180 | else if (isOpen.value) isOpen.value = false |
| 174 | 181 | } |
| 175 | 182 | |
| 176 | onMounted(() => { | |
| 177 | document.addEventListener('click', onFilterDocClick, true) | |
| 178 | document.addEventListener('keydown', onKeydown) | |
| 179 | }) | |
| 183 | useEventListener(inBrowser ? document : undefined, 'click', onFilterDocClick, { capture: true }) | |
| 184 | useEventListener(inBrowser ? document : undefined, 'keydown', onKeydown) | |
| 180 | 185 | |
| 181 | 186 | onUnmounted(() => { |
| 182 | document.removeEventListener('click', onFilterDocClick, true) | |
| 183 | document.removeEventListener('keydown', onKeydown) | |
| 184 | 187 | if (typeof document !== 'undefined') document.body.style.overflow = '' |
| 185 | 188 | }) |
| 186 | 189 | </script> |