Welcome to mirror list, hosted at ThFree Co, Russian Federation.

table_of_contents.vue « components « default « frontend « content - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 542cd50bdc5d9579482a3b084811520243e9c48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script>
import { GlIcon } from '@gitlab/ui';
import { flattenItems } from '../../shared/toc/flatten_items';
import CollapsibleContainer from './collapsible_container.vue';
import TableOfContentsList from './table_of_contents_list.vue';

export default {
  name: 'TableOfContents',
  components: {
    CollapsibleContainer,
    TableOfContentsList,
    GlIcon,
  },
  props: {
    items: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isCollapsed: true,
    };
  },
  computed: {
    allItems() {
      // Flatten the items so that only one is highlighted at a time
      return flattenItems(this.items);
    },
    collapseIcon() {
      return this.isCollapsed ? 'chevron-right' : 'chevron-down';
    },
  },
  methods: {
    toggleCollapse() {
      this.$refs.container.collapse(!this.isCollapsed);
    },
  },
};
</script>
<template>
  <div class="markdown-toc table-of-contents-container position-sticky">
    <div class="table-of-contents">
      <h4 class="border-0 toc-sm d-xl-none">
        <a
          class="text-decoration-none border-bottom-0"
          href="#"
          role="button"
          :aria-expanded="!isCollapsed"
          aria-controls="markdown-toc"
          data-testid="collapse"
          @click.prevent="toggleCollapse"
        >
          <gl-icon :name="collapseIcon" />On this page</a
        >
      </h4>
      <h4 class="border-0 gl-font-base font-weight-bold toc-lg">On this page</h4>
      <collapsible-container ref="container" v-model="isCollapsed" data-testid="container">
        <table-of-contents-list :items="allItems" class="my-0" data-testid="main-list" />
      </collapsible-container>
    </div>
  </div>
</template>