Commit 9ac6d75f08
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/search/SearchRibbon.vue +82 −11
| @@ -1,5 +1,5 @@ | |||
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { ChevronRight, Menu } from 'lucide-vue-next' | 2 | import { ChevronLeft, ChevronRight, Menu } from 'lucide-vue-next' |
| 3 | import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue' | 3 | import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue' |
| 4 | import { onClickOutside, useEventListener } from '@vueuse/core' | 4 | import { onClickOutside, useEventListener } from '@vueuse/core' |
| 5 | import { homeCards } from '../../../configs/constants' | 5 | import { homeCards } from '../../../configs/constants' |
| @@ -368,6 +368,35 @@ const activePageData = computed(() => { | |||
| 368 | function toggleListMenu() { | 368 | function toggleListMenu() { |
| 369 | showListMenu.value = !showListMenu.value | 369 | showListMenu.value = !showListMenu.value |
| 370 | } | 370 | } |
| 371 | |||
| 372 | const allPages = computed((): (string | null)[] => { | ||
| 373 | const pages: (string | null)[] = [null] | ||
| 374 | for (const entry of groupedMenuEntries.value) { | ||
| 375 | if (entry.type === 'page') { | ||
| 376 | pages.push(entry.page.key) | ||
| 377 | } else { | ||
| 378 | for (const page of entry.folder.pages) { | ||
| 379 | pages.push(page.key) | ||
| 380 | } | ||
| 381 | } | ||
| 382 | } | ||
| 383 | return pages | ||
| 384 | }) | ||
| 385 | |||
| 386 | const currentPageIndex = computed(() => { | ||
| 387 | const activeKey = props.urlSearchMode ? props.urlActivePageFilter : props.activePageFilter | ||
| 388 | return allPages.value.indexOf(activeKey) | ||
| 389 | }) | ||
| 390 | |||
| 391 | function pageNav(delta: number) { | ||
| 392 | const pages = allPages.value | ||
| 393 | if (pages.length <= 1) return | ||
| 394 | const idx = currentPageIndex.value | ||
| 395 | const nextIdx = ((idx + delta) % pages.length + pages.length) % pages.length | ||
| 396 | const key = pages[nextIdx] | ||
| 397 | if (props.urlSearchMode) setUrlPageFilter(key) | ||
| 398 | else setPageFilter(key) | ||
| 399 | } | ||
| 371 | </script> | 400 | </script> |
| 372 | 401 | ||
| 373 | <template> | 402 | <template> |
| @@ -386,16 +415,34 @@ function toggleListMenu() { | |||
| 386 | <span class="page-ribbon-list-badge">{{ activePageData.count }}</span> | 415 | <span class="page-ribbon-list-badge">{{ activePageData.count }}</span> |
| 387 | </div> | 416 | </div> |
| 388 | 417 | ||
| 389 | <button | 418 | <div class="page-ribbon-list-actions"> |
| 390 | ref="listMenuButtonRef" | 419 | <button |
| 391 | type="button" | 420 | type="button" |
| 392 | class="ribbon-menu-btn" | 421 | class="ribbon-menu-btn ribbon-page-nav" |
| 393 | :class="{ active: showListMenu }" | 422 | title="Previous page" |
| 394 | title="Filter by page" | 423 | @click="pageNav(-1)" |
| 395 | @click.stop="toggleListMenu" | 424 | > |
| 396 | > | 425 | <ChevronLeft :size="18" stroke-width="2" /> |
| 397 | <Menu :size="18" stroke-width="2" /> | 426 | </button> |
| 398 | </button> | 427 | <button |
| 428 | type="button" | ||
| 429 | class="ribbon-menu-btn ribbon-page-nav" | ||
| 430 | title="Next page" | ||
| 431 | @click="pageNav(1)" | ||
| 432 | > | ||
| 433 | <ChevronRight :size="18" stroke-width="2" /> | ||
| 434 | </button> | ||
| 435 | <button | ||
| 436 | ref="listMenuButtonRef" | ||
| 437 | type="button" | ||
| 438 | class="ribbon-menu-btn" | ||
| 439 | :class="{ active: showListMenu }" | ||
| 440 | title="Filter by page" | ||
| 441 | @click.stop="toggleListMenu" | ||
| 442 | > | ||
| 443 | <Menu :size="18" stroke-width="2" /> | ||
| 444 | </button> | ||
| 445 | </div> | ||
| 399 | 446 | ||
| 400 | <!-- List menu dropdown --> | 447 | <!-- List menu dropdown --> |
| 401 | <Transition name="ribbon-menu-popup"> | 448 | <Transition name="ribbon-menu-popup"> |
| @@ -732,6 +779,17 @@ function toggleListMenu() { | |||
| 732 | overflow: visible; | 779 | overflow: visible; |
| 733 | } | 780 | } |
| 734 | 781 | ||
| 782 | @media (min-width: 768px) { | ||
| 783 | .ribbon-page-nav { | ||
| 784 | display: none; | ||
| 785 | } | ||
| 786 | } | ||
| 787 | |||
| 788 | .page-ribbon-list-actions { | ||
| 789 | display: flex; | ||
| 790 | align-items: center; | ||
| 791 | } | ||
| 792 | |||
| 735 | .page-ribbon-list-label { | 793 | .page-ribbon-list-label { |
| 736 | display: flex; | 794 | display: flex; |
| 737 | align-items: center; | 795 | align-items: center; |
| @@ -797,8 +855,21 @@ function toggleListMenu() { | |||
| 797 | background: transparent; | 855 | background: transparent; |
| 798 | } | 856 | } |
| 799 | 857 | ||
| 858 | @media (hover: none) { | ||
| 859 | .ribbon-menu-btn:hover { | ||
| 860 | opacity: 0.55; | ||
| 861 | color: var(--vp-c-text-1); | ||
| 862 | } | ||
| 863 | } | ||
| 864 | |||
| 865 | .ribbon-menu-btn:focus { | ||
| 866 | outline: none; | ||
| 867 | } | ||
| 868 | |||
| 800 | .ribbon-menu-btn:active { | 869 | .ribbon-menu-btn:active { |
| 801 | transform: scale(0.94); | 870 | transform: scale(0.94); |
| 871 | opacity: 1; | ||
| 872 | color: var(--vp-c-text-1); | ||
| 802 | } | 873 | } |
| 803 | 874 | ||
| 804 | html.effects-disabled .ribbon-menu-btn { | 875 | html.effects-disabled .ribbon-menu-btn { |