blob: 7c0f49068cc504baa910bf2f086d9788ce08378b [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>
34export default {
35 name: 'TableToolbar',
36 props: {
37 selectedItemsCount: {
38 type: Number,
Derick Montague602e98a2020-10-21 16:20:00 -050039 required: true,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080040 },
41 actions: {
42 type: Array,
Yoshie Muranakab1a71912020-04-29 10:52:39 -070043 default: () => [],
Derick Montague602e98a2020-10-21 16:20:00 -050044 validator: (prop) => {
45 return prop.every((action) => {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080046 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070047 Object.prototype.hasOwnProperty.call(action, 'value') &&
48 Object.prototype.hasOwnProperty.call(action, 'label')
Yoshie Muranaka183c2752020-02-12 11:30:49 -080049 );
50 });
Derick Montague602e98a2020-10-21 16:20:00 -050051 },
52 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080053 },
54 data() {
55 return {
Derick Montague602e98a2020-10-21 16:20:00 -050056 isToolbarActive: false,
Yoshie Muranaka183c2752020-02-12 11:30:49 -080057 };
58 },
59 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -050060 selectedItemsCount: function (selectedItemsCount) {
Yoshie Muranaka183c2752020-02-12 11:30:49 -080061 if (selectedItemsCount > 0) {
62 this.isToolbarActive = true;
63 } else {
64 this.isToolbarActive = false;
65 }
Derick Montague602e98a2020-10-21 16:20:00 -050066 },
67 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080068};
69</script>
70
71<style lang="scss" scoped>
Ed Tanous9c729792024-03-23 14:56:34 -070072@import '@/assets/styles/bmc/helpers/_index.scss';
73@import '@/assets/styles/bootstrap/_helpers.scss';
74
75@import 'bootstrap/dist/css/bootstrap.css';
76
Yoshie Muranaka183c2752020-02-12 11:30:49 -080077$toolbar-height: 46px;
78
79.toolbar-container {
80 width: 100%;
81 position: relative;
Ed Tanous9c729792024-03-23 14:56:34 -070082 //z-index: $zindex-dropdown + 1;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080083}
84
85.toolbar-content {
86 height: $toolbar-height;
Yoshie Muranaka01da8182020-07-08 15:46:43 -070087 background-color: theme-color('primary');
Yoshie Muranaka183c2752020-02-12 11:30:49 -080088 color: $white;
89 position: absolute;
90 left: 0;
91 right: 0;
92 top: -$toolbar-height;
93 display: flex;
94 flex-direction: row;
95 justify-content: space-between;
96}
97
Yoshie Muranaka183c2752020-02-12 11:30:49 -080098.toolbar-selected {
99 line-height: $toolbar-height;
100 margin: 0;
101 padding: 0 $spacer;
102}
103
Sneha Patele516d4d2021-05-24 14:11:26 -0500104// Using v-deep to style export slot child-element
105// depricated and vue-js 3
106.toolbar-actions ::v-deep .btn {
107 position: relative;
108 &:after {
109 content: '';
110 position: absolute;
111 left: 0;
112 height: 1.5rem;
113 width: 1px;
114 background: rgba($white, 0.6);
115 }
116 &:last-child,
117 &:first-child {
118 &:after {
119 width: 0;
120 }
121 }
122}
123
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800124.slide-enter-active {
125 transition: transform $duration--moderate-02 $entrance-easing--productive;
126}
127.slide-leave-active {
128 transition: transform $duration--moderate-02 $exit-easing--productive;
129}
SurenNeware151dd242020-11-10 20:15:05 +0530130.slide-enter, // Remove this vue2 based only class when switching to vue3
131.slide-enter-from, // This is vue3 based only class modified from 'slide-enter'
Yoshie Muranaka183c2752020-02-12 11:30:49 -0800132.slide-leave-to {
133 transform: translateY($toolbar-height);
134}
135</style>