blob: bb18ceb5c7e62975c32df8350d7f19b8a450a744 [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
21 variant="primary"
22 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,
39 required: true
40 },
41 actions: {
42 type: Array,
Yoshie Muranakab1a71912020-04-29 10:52:39 -070043 default: () => [],
Yoshie Muranaka183c2752020-02-12 11:30:49 -080044 validator: prop => {
45 return prop.every(action => {
46 return (
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080047 action.hasOwnProperty('value') && action.hasOwnProperty('label')
Yoshie Muranaka183c2752020-02-12 11:30:49 -080048 );
49 });
50 }
51 }
52 },
53 data() {
54 return {
55 isToolbarActive: false
56 };
57 },
58 watch: {
59 selectedItemsCount: function(selectedItemsCount) {
60 if (selectedItemsCount > 0) {
61 this.isToolbarActive = true;
62 } else {
63 this.isToolbarActive = false;
64 }
65 }
66 }
67};
68</script>
69
70<style lang="scss" scoped>
Derick Montague40865722020-04-13 17:01:19 -050071@import 'src/assets/styles/helpers';
72
Yoshie Muranaka183c2752020-02-12 11:30:49 -080073$toolbar-height: 46px;
74
75.toolbar-container {
76 width: 100%;
77 position: relative;
SurenNeware5e25e282020-07-08 15:57:23 +053078 z-index: 5;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080079}
80
81.toolbar-content {
82 height: $toolbar-height;
Mateusz Gapski2a934972020-07-23 12:10:10 +020083 z-index: $zindex-dropdown + 1;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070084 background-color: theme-color('primary');
Yoshie Muranaka183c2752020-02-12 11:30:49 -080085 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-actions {
96 > :last-child {
97 position: relative;
98 &::before {
99 content: '';
100 position: absolute;
101 height: $toolbar-height / 2;
102 border-left: 2px solid $white;
103 left: -2px;
104 top: $toolbar-height / 4;
105 }
106 }
107}
108
109.toolbar-selected {
110 line-height: $toolbar-height;
111 margin: 0;
112 padding: 0 $spacer;
113}
114
115.slide-enter-active {
116 transition: transform $duration--moderate-02 $entrance-easing--productive;
117}
118.slide-leave-active {
119 transition: transform $duration--moderate-02 $exit-easing--productive;
120}
121.slide-enter,
122.slide-leave-to {
123 transform: translateY($toolbar-height);
124}
125</style>