blob: 331f0076ac753a56dc46e77501596e7095b9e1b2 [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"
12 variant="primary"
13 class="d-block"
14 @click="$emit('batchAction', action.value)"
15 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080016 {{ action.label }}
Yoshie Muranaka183c2752020-02-12 11:30:49 -080017 </b-button>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070018 <slot name="export"></slot>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080019 <b-button
20 variant="primary"
21 class="d-block"
22 @click="$emit('clearSelected')"
23 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080024 {{ $t('global.action.cancel') }}
Yoshie Muranaka183c2752020-02-12 11:30:49 -080025 </b-button>
26 </div>
27 </div>
28 </div>
29 </transition>
30</template>
31
32<script>
33export default {
34 name: 'TableToolbar',
35 props: {
36 selectedItemsCount: {
37 type: Number,
38 required: true
39 },
40 actions: {
41 type: Array,
Yoshie Muranakab1a71912020-04-29 10:52:39 -070042 default: () => [],
Yoshie Muranaka183c2752020-02-12 11:30:49 -080043 validator: prop => {
44 return prop.every(action => {
45 return (
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080046 action.hasOwnProperty('value') && action.hasOwnProperty('label')
Yoshie Muranaka183c2752020-02-12 11:30:49 -080047 );
48 });
49 }
50 }
51 },
52 data() {
53 return {
54 isToolbarActive: false
55 };
56 },
57 watch: {
58 selectedItemsCount: function(selectedItemsCount) {
59 if (selectedItemsCount > 0) {
60 this.isToolbarActive = true;
61 } else {
62 this.isToolbarActive = false;
63 }
64 }
65 }
66};
67</script>
68
69<style lang="scss" scoped>
70$toolbar-height: 46px;
71
72.toolbar-container {
73 width: 100%;
74 position: relative;
75}
76
77.toolbar-content {
78 height: $toolbar-height;
79 background-color: $primary;
80 color: $white;
81 position: absolute;
82 left: 0;
83 right: 0;
84 top: -$toolbar-height;
85 display: flex;
86 flex-direction: row;
87 justify-content: space-between;
88}
89
90.toolbar-actions {
91 > :last-child {
92 position: relative;
93 &::before {
94 content: '';
95 position: absolute;
96 height: $toolbar-height / 2;
97 border-left: 2px solid $white;
98 left: -2px;
99 top: $toolbar-height / 4;
100 }
101 }
102}
103
104.toolbar-selected {
105 line-height: $toolbar-height;
106 margin: 0;
107 padding: 0 $spacer;
108}
109
110.slide-enter-active {
111 transition: transform $duration--moderate-02 $entrance-easing--productive;
112}
113.slide-leave-active {
114 transition: transform $duration--moderate-02 $exit-easing--productive;
115}
116.slide-enter,
117.slide-leave-to {
118 transform: translateY($toolbar-height);
119}
120</style>