blob: 6a856b44c58bf9a9bb89d1959f4b4d73fcaa0567 [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 Muranakaeaa04802020-02-28 13:21:27 -080047 action.hasOwnProperty('value') && action.hasOwnProperty('label')
Yoshie Muranaka183c2752020-02-12 11:30:49 -080048 );
49 });
Derick Montague602e98a2020-10-21 16:20:00 -050050 },
51 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080052 },
53 data() {
54 return {
Derick Montague602e98a2020-10-21 16:20:00 -050055 isToolbarActive: false,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080056 };
57 },
58 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050059 selectedItemsCount: function (selectedItemsCount) {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080060 if (selectedItemsCount > 0) {
61 this.isToolbarActive = true;
62 } else {
63 this.isToolbarActive = false;
64 }
Derick Montague602e98a2020-10-21 16:20:00 -050065 },
66 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080067};
68</script>
69
70<style lang="scss" scoped>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080071$toolbar-height: 46px;
72
73.toolbar-container {
74 width: 100%;
75 position: relative;
SurenNeware5e25e282020-07-08 15:57:23 +053076 z-index: 5;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080077}
78
79.toolbar-content {
80 height: $toolbar-height;
Mateusz Gapski2a934972020-07-23 12:10:10 +020081 z-index: $zindex-dropdown + 1;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070082 background-color: theme-color('primary');
Yoshie Muranaka183c2752020-02-12 11:30:49 -080083 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
Yoshie Muranaka183c2752020-02-12 11:30:49 -080093.toolbar-selected {
94 line-height: $toolbar-height;
95 margin: 0;
96 padding: 0 $spacer;
97}
98
99.slide-enter-active {
100 transition: transform $duration--moderate-02 $entrance-easing--productive;
101}
102.slide-leave-active {
103 transition: transform $duration--moderate-02 $exit-easing--productive;
104}
105.slide-enter,
106.slide-leave-to {
107 transform: translateY($toolbar-height);
108}
109</style>