SidebarGroup.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <section
  3. class="sidebar-group"
  4. :class="[
  5. {
  6. collapsable,
  7. 'is-sub-group': depth !== 0
  8. },
  9. `depth-${depth}`
  10. ]"
  11. >
  12. <router-link
  13. v-if="item.path"
  14. class="sidebar-heading clickable"
  15. :class="{
  16. open,
  17. 'active': isActive($route, item.path)
  18. }"
  19. :to="item.path"
  20. @click.native="$emit('toggle')"
  21. >
  22. <span>{{ item.title }}</span>
  23. <span
  24. class="arrow"
  25. v-if="collapsable"
  26. :class="open ? 'down' : 'right'">
  27. </span>
  28. </router-link>
  29. <p
  30. v-else
  31. class="sidebar-heading"
  32. :class="{ open }"
  33. @click="$emit('toggle')"
  34. >
  35. <span>{{ item.title }}</span>
  36. <span
  37. class="arrow"
  38. v-if="collapsable"
  39. :class="open ? 'down' : 'right'">
  40. </span>
  41. </p>
  42. <DropdownTransition>
  43. <SidebarLinks
  44. class="sidebar-group-items"
  45. :items="item.children"
  46. v-if="open || !collapsable"
  47. :sidebarDepth="item.sidebarDepth"
  48. :depth="depth + 1"
  49. />
  50. </DropdownTransition>
  51. </section>
  52. </template>
  53. <script>
  54. import { isActive } from '../util'
  55. import DropdownTransition from '@theme/components/DropdownTransition.vue'
  56. export default {
  57. name: 'SidebarGroup',
  58. props: ['item', 'open', 'collapsable', 'depth'],
  59. components: { DropdownTransition },
  60. // ref: https://vuejs.org/v2/guide/components-edge-cases.html#Circular-References-Between-Components
  61. beforeCreate () {
  62. this.$options.components.SidebarLinks = require('./SidebarLinks.vue').default
  63. },
  64. methods: { isActive }
  65. }
  66. </script>
  67. <style lang="stylus">
  68. .sidebar-group
  69. .sidebar-group
  70. padding-left 0.5em
  71. &:not(.collapsable)
  72. .sidebar-heading:not(.clickable)
  73. cursor auto
  74. color inherit
  75. // refine styles of nested sidebar groups
  76. &.is-sub-group
  77. padding-left 0
  78. & > .sidebar-heading
  79. font-size 0.95em
  80. line-height 1.4
  81. font-weight normal
  82. padding-left 2rem
  83. &:not(.clickable)
  84. opacity 0.5
  85. & > .sidebar-group-items
  86. padding-left 1rem
  87. & > li > .sidebar-link
  88. font-size: 0.95em;
  89. border-left none
  90. &.depth-2
  91. & > .sidebar-heading
  92. border-left none
  93. .sidebar-heading
  94. color $textColor
  95. transition color .15s ease
  96. cursor pointer
  97. font-size 1.1em
  98. font-weight bold
  99. // text-transform uppercase
  100. padding 0.35rem 1.5rem 0.35rem 1.25rem
  101. width 100%
  102. box-sizing border-box
  103. margin 0
  104. border-left 0.25rem solid transparent
  105. &.open, &:hover
  106. color inherit
  107. .arrow
  108. position relative
  109. top -0.12em
  110. left 0.5em
  111. &.clickable
  112. &.active
  113. font-weight 600
  114. color $accentColor
  115. border-left-color $accentColor
  116. &:hover
  117. color $accentColor
  118. .sidebar-group-items
  119. transition height .1s ease-out
  120. font-size 0.95em
  121. overflow hidden
  122. </style>