summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/resizable_panel.vue
blob: 5ea2a2f68258ed9dc5596db17041b42a3d08b3e9 (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
<script>
import { mapActions, mapState } from 'vuex';
import PanelResizer from '~/vue_shared/components/panel_resizer.vue';

export default {
  components: {
    PanelResizer,
  },
  props: {
    collapsible: {
      type: Boolean,
      required: true,
    },
    initialWidth: {
      type: Number,
      required: true,
    },
    minSize: {
      type: Number,
      required: false,
      default: 340,
    },
    side: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      width: this.initialWidth,
    };
  },
  computed: {
    ...mapState({
      collapsed(state) {
        return state[`${this.side}PanelCollapsed`];
      },
    }),
    panelStyle() {
      if (!this.collapsed) {
        return {
          width: `${this.width}px`,
        };
      }

      return {};
    },
  },
  methods: {
    ...mapActions(['setPanelCollapsedStatus', 'setResizingStatus']),
    toggleFullbarCollapsed() {
      if (this.collapsed && this.collapsible) {
        this.setPanelCollapsedStatus({
          side: this.side,
          collapsed: !this.collapsed,
        });
      }
    },
  },
  maxSize: window.innerWidth / 2,
};
</script>

<template>
  <div
    class="multi-file-commit-panel"
    :class="{
      'is-collapsed': collapsed && collapsible,
    }"
    :style="panelStyle"
    @click="toggleFullbarCollapsed"
  >
    <slot></slot>
    <panel-resizer
      :size.sync="width"
      :enabled="!collapsed"
      :start-size="initialWidth"
      :min-size="minSize"
      :max-size="$options.maxSize"
      @resize-start="setResizingStatus(true)"
      @resize-end="setResizingStatus(false)"
      :side="side === 'right' ? 'left' : 'right'"
    />
  </div>
</template>