xref: /openbmc/webui-vue/src/components/Global/TableToolbar.vue (revision 24b377db47a05f742b1f3db77606f6bae845f637)
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>
34import { useI18n } from 'vue-i18n';
35export default {
36  name: 'TableToolbar',
37  props: {
38    selectedItemsCount: {
39      type: Number,
40      required: true,
41    },
42    actions: {
43      type: Array,
44      default: () => [],
45      validator: (prop) => {
46        return prop.every((action) => {
47          return (
48            Object.prototype.hasOwnProperty.call(action, 'value') &&
49            Object.prototype.hasOwnProperty.call(action, 'label')
50          );
51        });
52      },
53    },
54  },
55  data() {
56    return {
57      $t: useI18n().t,
58      isToolbarActive: false,
59    };
60  },
61  watch: {
62    selectedItemsCount: function (selectedItemsCount) {
63      if (selectedItemsCount > 0) {
64        this.isToolbarActive = true;
65      } else {
66        this.isToolbarActive = false;
67      }
68    },
69  },
70};
71</script>
72
73<style lang="scss" scoped>
74$toolbar-height: 46px;
75
76.toolbar-container {
77  width: 100%;
78  position: relative;
79  z-index: $zindex-dropdown + 1;
80}
81
82.toolbar-content {
83  height: $toolbar-height;
84  background-color: theme-color('primary');
85  color: $white;
86  position: absolute;
87  left: 0;
88  right: 0;
89  top: -$toolbar-height;
90  display: flex;
91  flex-direction: row;
92  justify-content: space-between;
93}
94
95.toolbar-selected {
96  line-height: $toolbar-height;
97  margin: 0;
98  padding: 0 $spacer;
99}
100
101// Using v-deep to style export slot child-element
102// depricated and vue-js 3
103.toolbar-actions ::v-deep .btn {
104  position: relative;
105  &:after {
106    content: '';
107    position: absolute;
108    left: 0;
109    height: 1.5rem;
110    width: 1px;
111    background: rgba($white, 0.6);
112  }
113  &:last-child,
114  &:first-child {
115    &:after {
116      width: 0;
117    }
118  }
119}
120
121.slide-enter-active {
122  transition: transform $duration--moderate-02 $entrance-easing--productive;
123}
124.slide-leave-active {
125  transition: transform $duration--moderate-02 $exit-easing--productive;
126}
127.slide-enter, // Remove this vue2 based only class when switching to vue3
128.slide-enter-from, // This is vue3 based only class modified from 'slide-enter'
129.slide-leave-to {
130  transform: translateY($toolbar-height);
131}
132</style>
133