blob: 0bdb87b1fd71b00efd9dc8d8ab50921ec409ff2d [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">
Dixsie Wolmers27d68af2021-05-02 18:20:27 -05009 <slot name="toolbar-buttons"></slot>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080010 <b-button
11 v-for="(action, index) in actions"
12 :key="index"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070013 :data-test-id="`table-button-${action.value}Selected`"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080014 variant="primary"
15 class="d-block"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053016 @click="$emit('batch-action', action.value)"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080017 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080018 {{ action.label }}
Yoshie Muranaka183c2752020-02-12 11:30:49 -080019 </b-button>
20 <b-button
SurenNewaree409b732020-08-10 19:00:34 +053021 variant="secondary"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080022 class="d-block"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053023 @click="$emit('clear-selected')"
Yoshie Muranaka183c2752020-02-12 11:30:49 -080024 >
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>
Ed Tanous883a0d52024-03-23 14:56:34 -070034import { useI18n } from 'vue-i18n';
Yoshie Muranaka183c2752020-02-12 11:30:49 -080035export default {
36 name: 'TableToolbar',
37 props: {
38 selectedItemsCount: {
39 type: Number,
Derick Montague602e98a2020-10-21 16:20:00 -050040 required: true,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080041 },
42 actions: {
43 type: Array,
Yoshie Muranakab1a71912020-04-29 10:52:39 -070044 default: () => [],
Derick Montague602e98a2020-10-21 16:20:00 -050045 validator: (prop) => {
46 return prop.every((action) => {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080047 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070048 Object.prototype.hasOwnProperty.call(action, 'value') &&
49 Object.prototype.hasOwnProperty.call(action, 'label')
Yoshie Muranaka183c2752020-02-12 11:30:49 -080050 );
51 });
Derick Montague602e98a2020-10-21 16:20:00 -050052 },
53 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080054 },
55 data() {
56 return {
Ed Tanous883a0d52024-03-23 14:56:34 -070057 $t: useI18n().t,
Derick Montague602e98a2020-10-21 16:20:00 -050058 isToolbarActive: false,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080059 };
60 },
61 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050062 selectedItemsCount: function (selectedItemsCount) {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080063 if (selectedItemsCount > 0) {
64 this.isToolbarActive = true;
65 } else {
66 this.isToolbarActive = false;
67 }
Derick Montague602e98a2020-10-21 16:20:00 -050068 },
69 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080070};
71</script>
72
73<style lang="scss" scoped>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080074$toolbar-height: 46px;
75
76.toolbar-container {
77 width: 100%;
78 position: relative;
suryav972424b377d2025-01-24 15:06:35 +053079 z-index: $zindex-dropdown + 1;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080080}
81
82.toolbar-content {
83 height: $toolbar-height;
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
Yoshie Muranaka183c2752020-02-12 11:30:49 -080095.toolbar-selected {
96 line-height: $toolbar-height;
97 margin: 0;
98 padding: 0 $spacer;
99}
100
Sneha Patele516d4d2021-05-24 14:11:26 -0500101// 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
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800121.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}
SurenNeware151dd242020-11-10 20:15:05 +0530127.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'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800129.slide-leave-to {
130 transform: translateY($toolbar-height);
131}
132</style>