page-toc-item.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template lang="pug">
  2. .page-toc-item
  3. template(v-if='level >= min')
  4. v-list-item(@click='click(item.anchor)', v-if='(item.children.length === 0 && max > level) || max > level',
  5. :key='item.anchor', :class='isNestedLevel ? `pl-9` : `pl-6`')
  6. v-icon.pl-0(small, color='grey lighten-1') {{ $vuetify.rtl ? `mdi-chevron-left` : `mdi-chevron-right` }}
  7. v-list-item-title.pl-4(v-bind:class='titleClasses') {{item.title}}
  8. v-list-group(sub-group, v-else, v-bind:class='{"pl-3": isNestedLevel}')
  9. template(v-slot:activator)
  10. v-list-item.pl-0(@click='click(item.anchor)', :key='item.anchor')
  11. v-list-item-title(v-bind:class='titleClasses') {{item.title}}
  12. template(v-if='item.children.length !== 0', v-for='subItem in item.children')
  13. page-toc-item(:item='subItem', :level='level + 1', :min='min', :max='max')
  14. template(v-if='max > level', v-for='subItem in item.children')
  15. page-toc-item(:item='subItem', :level='level + 1', :min='min', :max='max')
  16. template(v-else, v-for='subItem in item.children')
  17. page-toc-item(:item='subItem', :level='level + 1', :min='min', :max='max')
  18. </template>
  19. <script>
  20. export default {
  21. name: 'PageTocItem',
  22. props: {
  23. item: {
  24. type: Object,
  25. default: () => {}
  26. },
  27. min: {
  28. type: Number,
  29. default: 1
  30. },
  31. max: {
  32. type: Number,
  33. default: 2
  34. },
  35. level: {
  36. type: Number,
  37. default: 1
  38. }
  39. },
  40. data() {
  41. return {
  42. scrollOpts: {
  43. duration: 1500,
  44. offset: 0,
  45. easing: 'easeInOutCubic'
  46. }
  47. }
  48. },
  49. computed: {
  50. isNestedLevel() {
  51. return this.level > this.min
  52. },
  53. titleClasses() {
  54. return {
  55. 'caption': this.isNestedLevel,
  56. 'grey--text': this.isNestedLevel,
  57. 'text--lighten-1': this.$vuetify.theme.dark && this.isNestedLevel,
  58. 'text--darken-1': !this.$vuetify.theme.dark && this.isNestedLevel
  59. }
  60. }
  61. },
  62. methods: {
  63. click (anchor) {
  64. this.$vuetify.goTo(anchor, this.scrollOpts)
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang='scss'>
  70. // Hack to fix animations of multi level nesting v-list-group
  71. .page-toc-item .v-list-group--sub-group.v-list-group--active .v-list-item:not(.v-list-item--active) .v-list-item__icon.v-list-group__header__prepend-icon .v-icon {
  72. transform: rotate(0deg)!important;
  73. }
  74. </style>