blob: cb6fa240369618e4b875657f28660192b84b705a [file] [log] [blame]
Yoshie Muranaka183c2752020-02-12 11:30:49 -08001<template>
2 <transition name="slide">
3 <div v-if="isToolbarActive" class="toolbar-container">
4 <div class="toolbar-content">
5 <p class="toolbar-selected">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -08006 {{ selectedItemsCount }} {{ $t('global.action.selected') }}
Yoshie Muranaka183c2752020-02-12 11:30:49 -08007 </p>
8 <div class="toolbar-actions d-flex">
9 <b-button
10 v-for="(action, index) in actions"
11 :key="index"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070012 :data-test-id="`table-button-${action.value}Selected`"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080013 variant="primary"
14 class="d-block"
15 @click="$emit('batchAction', action.value)"
16 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080017 {{ action.label }}
Yoshie Muranaka183c2752020-02-12 11:30:49 -080018 </b-button>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070019 <slot name="export"></slot>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080020 <b-button
SurenNewaree409b732020-08-10 19:00:34 +053021 variant="secondary"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080022 class="d-block"
23 @click="$emit('clearSelected')"
24 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080025 {{ $t('global.action.cancel') }}
Yoshie Muranaka183c2752020-02-12 11:30:49 -080026 </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,
Derick Montague602e98a2020-10-21 16:20:00 -050039 required: true,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080040 },
41 actions: {
42 type: Array,
Yoshie Muranakab1a71912020-04-29 10:52:39 -070043 default: () => [],
Derick Montague602e98a2020-10-21 16:20:00 -050044 validator: (prop) => {
45 return prop.every((action) => {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080046 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070047 Object.prototype.hasOwnProperty.call(action, 'value') &&
48 Object.prototype.hasOwnProperty.call(action, 'label')
Yoshie Muranaka183c2752020-02-12 11:30:49 -080049 );
50 });
Derick Montague602e98a2020-10-21 16:20:00 -050051 },
52 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080053 },
54 data() {
55 return {
Derick Montague602e98a2020-10-21 16:20:00 -050056 isToolbarActive: false,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080057 };
58 },
59 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050060 selectedItemsCount: function (selectedItemsCount) {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080061 if (selectedItemsCount > 0) {
62 this.isToolbarActive = true;
63 } else {
64 this.isToolbarActive = false;
65 }
Derick Montague602e98a2020-10-21 16:20:00 -050066 },
67 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080068};
69</script>
70
71<style lang="scss" scoped>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080072$toolbar-height: 46px;
73
74.toolbar-container {
75 width: 100%;
76 position: relative;
SurenNeware5e25e282020-07-08 15:57:23 +053077 z-index: 5;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080078}
79
80.toolbar-content {
81 height: $toolbar-height;
Mateusz Gapski2a934972020-07-23 12:10:10 +020082 z-index: $zindex-dropdown + 1;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070083 background-color: theme-color('primary');
Yoshie Muranaka183c2752020-02-12 11:30:49 -080084 color: $white;
85 position: absolute;
86 left: 0;
87 right: 0;
88 top: -$toolbar-height;
89 display: flex;
90 flex-direction: row;
91 justify-content: space-between;
92}
93
Yoshie Muranaka183c2752020-02-12 11:30:49 -080094.toolbar-selected {
95 line-height: $toolbar-height;
96 margin: 0;
97 padding: 0 $spacer;
98}
99
100.slide-enter-active {
101 transition: transform $duration--moderate-02 $entrance-easing--productive;
102}
103.slide-leave-active {
104 transition: transform $duration--moderate-02 $exit-easing--productive;
105}
106.slide-enter,
107.slide-leave-to {
108 transform: translateY($toolbar-height);
109}
110</style>