summaryrefslogtreecommitdiff
path: root/src/components/Global/TableToolbar.vue
blob: d22b37fc47935252993c7fd57d388642c4ca5661 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
  <transition name="slide">
    <div v-if="isToolbarActive" class="toolbar-container">
      <div class="toolbar-content">
        <p class="toolbar-selected">
          {{ selectedItemsCount }} {{ $t('global.action.selected') }}
        </p>
        <div class="toolbar-actions d-flex">
          <b-button
            v-for="(action, index) in actions"
            :key="index"
            :data-test-id="`table-button-${action.value}Selected`"
            variant="primary"
            class="d-block"
            @click="$emit('batch-action', action.value)"
          >
            {{ action.label }}
          </b-button>
          <slot name="export"></slot>
          <b-button
            variant="secondary"
            class="d-block"
            @click="$emit('clear-selected')"
          >
            {{ $t('global.action.cancel') }}
          </b-button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'TableToolbar',
  props: {
    selectedItemsCount: {
      type: Number,
      required: true,
    },
    actions: {
      type: Array,
      default: () => [],
      validator: (prop) => {
        return prop.every((action) => {
          return (
            Object.prototype.hasOwnProperty.call(action, 'value') &&
            Object.prototype.hasOwnProperty.call(action, 'label')
          );
        });
      },
    },
  },
  data() {
    return {
      isToolbarActive: false,
    };
  },
  watch: {
    selectedItemsCount: function (selectedItemsCount) {
      if (selectedItemsCount > 0) {
        this.isToolbarActive = true;
      } else {
        this.isToolbarActive = false;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
$toolbar-height: 46px;

.toolbar-container {
  width: 100%;
  position: relative;
  z-index: 5;
}

.toolbar-content {
  height: $toolbar-height;
  z-index: $zindex-dropdown + 1;
  background-color: theme-color('primary');
  color: $white;
  position: absolute;
  left: 0;
  right: 0;
  top: -$toolbar-height;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.toolbar-selected {
  line-height: $toolbar-height;
  margin: 0;
  padding: 0 $spacer;
}

.slide-enter-active {
  transition: transform $duration--moderate-02 $entrance-easing--productive;
}
.slide-leave-active {
  transition: transform $duration--moderate-02 $exit-easing--productive;
}
.slide-enter,
.slide-leave-to {
  transform: translateY($toolbar-height);
}
</style>