1<template>
2  <transition name="slide">
3    <div v-if="isToolbarActive" class="toolbar-container">
4      <div class="toolbar-content">
5        <p class="toolbar-selected">
6          {{ selectedItemsCount }} {{ $t('global.action.selected') }}
7        </p>
8        <div class="toolbar-actions d-flex">
9          <slot name="toolbar-buttons"></slot>
10          <b-button
11            v-for="(action, index) in actions"
12            :key="index"
13            :data-test-id="`table-button-${action.value}Selected`"
14            variant="primary"
15            class="d-block"
16            @click="$emit('batch-action', action.value)"
17          >
18            {{ action.label }}
19          </b-button>
20          <b-button
21            variant="secondary"
22            class="d-block"
23            @click="$emit('clear-selected')"
24          >
25            {{ $t('global.action.cancel') }}
26          </b-button>
27        </div>
28      </div>
29    </div>
30  </transition>
31</template>
32
33<script>
34export default {
35  name: 'TableToolbar',
36  props: {
37    selectedItemsCount: {
38      type: Number,
39      required: true,
40    },
41    actions: {
42      type: Array,
43      default: () => [],
44      validator: (prop) => {
45        return prop.every((action) => {
46          return (
47            Object.prototype.hasOwnProperty.call(action, 'value') &&
48            Object.prototype.hasOwnProperty.call(action, 'label')
49          );
50        });
51      },
52    },
53  },
54  data() {
55    return {
56      isToolbarActive: false,
57    };
58  },
59  watch: {
60    selectedItemsCount: function (selectedItemsCount) {
61      if (selectedItemsCount > 0) {
62        this.isToolbarActive = true;
63      } else {
64        this.isToolbarActive = false;
65      }
66    },
67  },
68};
69</script>
70
71<style lang="scss" scoped>
72$toolbar-height: 46px;
73
74.toolbar-container {
75  width: 100%;
76  position: relative;
77  z-index: $zindex-dropdown + 1;
78}
79
80.toolbar-content {
81  height: $toolbar-height;
82  background-color: theme-color('primary');
83  color: $white;
84  position: absolute;
85  left: 0;
86  right: 0;
87  top: -$toolbar-height;
88  display: flex;
89  flex-direction: row;
90  justify-content: space-between;
91}
92
93.toolbar-selected {
94  line-height: $toolbar-height;
95  margin: 0;
96  padding: 0 $spacer;
97}
98
99// Using v-deep to style export slot child-element
100// depricated and vue-js 3
101.toolbar-actions ::v-deep .btn {
102  position: relative;
103  &:after {
104    content: '';
105    position: absolute;
106    left: 0;
107    height: 1.5rem;
108    width: 1px;
109    background: rgba($white, 0.6);
110  }
111  &:last-child,
112  &:first-child {
113    &:after {
114      width: 0;
115    }
116  }
117}
118
119.slide-enter-active {
120  transition: transform $duration--moderate-02 $entrance-easing--productive;
121}
122.slide-leave-active {
123  transition: transform $duration--moderate-02 $exit-easing--productive;
124}
125.slide-enter, // Remove this vue2 based only class when switching to vue3
126.slide-enter-from, // This is vue3 based only class modified from 'slide-enter'
127.slide-leave-to {
128  transform: translateY($toolbar-height);
129}
130</style>
131