NextAndPrevLinks.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script setup lang="ts">
  2. import { withBase } from 'vitepress'
  3. import { useNextAndPrevLinks } from '../composables/nextAndPrevLinks'
  4. import ArrowLeft from './icons/ArrowLeft.vue'
  5. import ArrowRight from './icons/ArrowRight.vue'
  6. const { hasLinks, prev, next } = useNextAndPrevLinks()
  7. </script>
  8. <template>
  9. <div v-if="hasLinks" class="next-and-prev-link">
  10. <div class="container">
  11. <div class="prev">
  12. <a v-if="prev" class="link" :href="withBase(prev.link)">
  13. <ArrowLeft class="icon icon-prev" />
  14. <span class="text">{{ prev.text }}</span>
  15. </a>
  16. </div>
  17. <div class="next">
  18. <a v-if="next" class="link" :href="withBase(next.link)">
  19. <span class="text">{{ next.text }}</span>
  20. <ArrowRight class="icon icon-next" />
  21. </a>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <style scoped>
  27. .next-and-prev-link {
  28. padding-top: 1rem;
  29. }
  30. .container {
  31. display: flex;
  32. justify-content: space-between;
  33. border-top: 1px solid var(--c-divider);
  34. padding-top: 1rem;
  35. }
  36. .prev,
  37. .next {
  38. display: flex;
  39. flex-shrink: 0;
  40. width: 50%;
  41. }
  42. .prev {
  43. justify-content: flex-start;
  44. padding-right: 12px;
  45. }
  46. .next {
  47. justify-content: flex-end;
  48. padding-left: 12px;
  49. }
  50. .link {
  51. display: inline-flex;
  52. align-items: center;
  53. max-width: 100%;
  54. font-size: 1rem;
  55. font-weight: 500;
  56. }
  57. .text {
  58. display: block;
  59. white-space: nowrap;
  60. overflow: hidden;
  61. text-overflow: ellipsis;
  62. }
  63. .icon {
  64. display: block;
  65. flex-shrink: 0;
  66. width: 16px;
  67. height: 16px;
  68. fill: var(--c-text);
  69. transform: translateY(1px);
  70. }
  71. .icon-prev {
  72. margin-right: 8px;
  73. }
  74. .icon-next {
  75. margin-left: 8px;
  76. }
  77. </style>