blob: 373b90a0c68a9ac68d0f580a98aef898e4584cf8 [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 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053055 emits: ['batch-action', 'clear-selected'],
Yoshie Muranaka183c2752020-02-12 11:30:49 -080056 data() {
57 return {
Ed Tanous883a0d52024-03-23 14:56:34 -070058 $t: useI18n().t,
Derick Montague602e98a2020-10-21 16:20:00 -050059 isToolbarActive: false,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080060 };
61 },
62 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050063 selectedItemsCount: function (selectedItemsCount) {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080064 if (selectedItemsCount > 0) {
65 this.isToolbarActive = true;
66 } else {
67 this.isToolbarActive = false;
68 }
Derick Montague602e98a2020-10-21 16:20:00 -050069 },
70 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080071};
72</script>
73
74<style lang="scss" scoped>
Yoshie Muranaka183c2752020-02-12 11:30:49 -080075$toolbar-height: 46px;
76
77.toolbar-container {
78 width: 100%;
79 position: relative;
suryav972424b377d2025-01-24 15:06:35 +053080 z-index: $zindex-dropdown + 1;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080081}
82
83.toolbar-content {
84 height: $toolbar-height;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070085 background-color: theme-color('primary');
Yoshie Muranaka183c2752020-02-12 11:30:49 -080086 color: $white;
87 position: absolute;
88 left: 0;
89 right: 0;
90 top: -$toolbar-height;
91 display: flex;
92 flex-direction: row;
93 justify-content: space-between;
94}
95
Yoshie Muranaka183c2752020-02-12 11:30:49 -080096.toolbar-selected {
97 line-height: $toolbar-height;
98 margin: 0;
99 padding: 0 $spacer;
100}
101
Sneha Patele516d4d2021-05-24 14:11:26 -0500102// Using v-deep to style export slot child-element
103// depricated and vue-js 3
104.toolbar-actions ::v-deep .btn {
105 position: relative;
106 &:after {
107 content: '';
108 position: absolute;
109 left: 0;
110 height: 1.5rem;
111 width: 1px;
112 background: rgba($white, 0.6);
113 }
114 &:last-child,
115 &:first-child {
116 &:after {
117 width: 0;
118 }
119 }
120}
121
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800122.slide-enter-active {
123 transition: transform $duration--moderate-02 $entrance-easing--productive;
124}
125.slide-leave-active {
126 transition: transform $duration--moderate-02 $exit-easing--productive;
127}
SurenNeware151dd242020-11-10 20:15:05 +0530128.slide-enter, // Remove this vue2 based only class when switching to vue3
129.slide-enter-from, // This is vue3 based only class modified from 'slide-enter'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800130.slide-leave-to {
131 transform: translateY($toolbar-height);
132}
133</style>