blob: 85d7c9ca8f90d164a018c6eb429333c1769658e2 [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 Tanousdbd37e02024-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 Tanousdbd37e02024-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>
Ed Tanous9c729792024-03-23 14:56:34 -070074@import '@/assets/styles/bmc/helpers/_index.scss';
75@import '@/assets/styles/bootstrap/_helpers.scss';
76
77@import 'bootstrap/dist/css/bootstrap.css';
78
Yoshie Muranaka183c2752020-02-12 11:30:49 -080079$toolbar-height: 46px;
80
81.toolbar-container {
82 width: 100%;
83 position: relative;
Ed Tanous9c729792024-03-23 14:56:34 -070084 //z-index: $zindex-dropdown + 1;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080085}
86
87.toolbar-content {
88 height: $toolbar-height;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070089 background-color: theme-color('primary');
Yoshie Muranaka183c2752020-02-12 11:30:49 -080090 color: $white;
91 position: absolute;
92 left: 0;
93 right: 0;
94 top: -$toolbar-height;
95 display: flex;
96 flex-direction: row;
97 justify-content: space-between;
98}
99
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800100.toolbar-selected {
101 line-height: $toolbar-height;
102 margin: 0;
103 padding: 0 $spacer;
104}
105
Sneha Patele516d4d2021-05-24 14:11:26 -0500106// Using v-deep to style export slot child-element
107// depricated and vue-js 3
108.toolbar-actions ::v-deep .btn {
109 position: relative;
110 &:after {
111 content: '';
112 position: absolute;
113 left: 0;
114 height: 1.5rem;
115 width: 1px;
116 background: rgba($white, 0.6);
117 }
118 &:last-child,
119 &:first-child {
120 &:after {
121 width: 0;
122 }
123 }
124}
125
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800126.slide-enter-active {
127 transition: transform $duration--moderate-02 $entrance-easing--productive;
128}
129.slide-leave-active {
130 transition: transform $duration--moderate-02 $exit-easing--productive;
131}
SurenNeware151dd242020-11-10 20:15:05 +0530132.slide-enter, // Remove this vue2 based only class when switching to vue3
133.slide-enter-from, // This is vue3 based only class modified from 'slide-enter'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800134.slide-leave-to {
135 transform: translateY($toolbar-height);
136}
137</style>