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

collapsible_container.vue « components « default « frontend « content - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 59653ab8be994766020c87e7a1cfc0fe514fcfc1 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script>
import { getOuterHeight } from '../../shared/dom';

export default {
  name: 'CollapsibleContainer',
  model: {
    prop: 'isCollapsed',
    event: 'change',
  },
  props: {
    isCollapsed: {
      type: Boolean,
      required: true,
    },
    collapsingClass: {
      type: String,
      required: false,
      default: 'sm-collapsing',
    },
    collapsedClass: {
      type: String,
      required: false,
      default: 'sm-collapsed',
    },
  },
  data() {
    return {
      isCollapsing: false,
      collapsingHeight: 0,
    };
  },
  computed: {
    styles() {
      if (this.isCollapsing) {
        return {
          height: `${this.collapsingHeight}px`,
        };
      }

      return {};
    },
    classes() {
      if (this.isCollapsing) {
        return this.collapsingClass;
      }
      if (this.isCollapsed) {
        return this.collapsedClass;
      }

      return '';
    },
  },
  methods: {
    collapse(shouldCollapse) {
      if (this.isCollapsing) {
        return;
      }
      // Right away let's flag that we're collapsing so we don't accept anymore updates
      this.isCollapsing = true;

      // Let's let our parent go ahead and treat us as collapsed.
      this.$emit('change', shouldCollapse);

      // Get start/stop height based on if we're collapsing or expanding
      const containerHeight = getOuterHeight(this.$el);
      const startHeight = shouldCollapse ? containerHeight : 0;
      const stopHeight = shouldCollapse ? 0 : containerHeight;

      // Kick off transition
      this.collapsingHeight = startHeight;
      setTimeout(() => {
        this.collapsingHeight = stopHeight;
      }, 50);

      setTimeout(() => {
        this.isCollapsing = false;
      }, 400);
    },
  },
};
</script>
<template>
  <div :class="classes" :style="styles">
    <slot></slot>
  </div>
</template>