| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 1 | <template> | 
|  | 2 | <transition name="slide"> | 
|  | 3 | <div v-if="isToolbarActive" class="toolbar-container"> | 
|  | 4 | <div class="toolbar-content"> | 
|  | 5 | <p class="toolbar-selected"> | 
| Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 6 | {{ selectedItemsCount }} {{ $t('global.action.selected') }} | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 7 | </p> | 
|  | 8 | <div class="toolbar-actions d-flex"> | 
| Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 9 | <slot name="toolbar-buttons"></slot> | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 10 | <b-button | 
|  | 11 | v-for="(action, index) in actions" | 
|  | 12 | :key="index" | 
| Yoshie Muranaka | ed06dc1 | 2020-06-16 12:12:27 -0700 | [diff] [blame] | 13 | :data-test-id="`table-button-${action.value}Selected`" | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 14 | variant="primary" | 
|  | 15 | class="d-block" | 
| Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 16 | @click="$emit('batch-action', action.value)" | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 17 | > | 
| Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 18 | {{ action.label }} | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 19 | </b-button> | 
|  | 20 | <b-button | 
| SurenNeware | e409b73 | 2020-08-10 19:00:34 +0530 | [diff] [blame] | 21 | variant="secondary" | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 22 | class="d-block" | 
| Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 23 | @click="$emit('clear-selected')" | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 24 | > | 
| Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 25 | {{ $t('global.action.cancel') }} | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 26 | </b-button> | 
|  | 27 | </div> | 
|  | 28 | </div> | 
|  | 29 | </div> | 
|  | 30 | </transition> | 
|  | 31 | </template> | 
|  | 32 |  | 
|  | 33 | <script> | 
|  | 34 | export default { | 
|  | 35 | name: 'TableToolbar', | 
|  | 36 | props: { | 
|  | 37 | selectedItemsCount: { | 
|  | 38 | type: Number, | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 39 | required: true, | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 40 | }, | 
|  | 41 | actions: { | 
|  | 42 | type: Array, | 
| Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 43 | default: () => [], | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 44 | validator: (prop) => { | 
|  | 45 | return prop.every((action) => { | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 46 | return ( | 
| Yoshie Muranaka | efd7c88 | 2020-10-30 09:32:06 -0700 | [diff] [blame] | 47 | Object.prototype.hasOwnProperty.call(action, 'value') && | 
|  | 48 | Object.prototype.hasOwnProperty.call(action, 'label') | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 49 | ); | 
|  | 50 | }); | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 51 | }, | 
|  | 52 | }, | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 53 | }, | 
|  | 54 | data() { | 
|  | 55 | return { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 56 | isToolbarActive: false, | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 57 | }; | 
|  | 58 | }, | 
|  | 59 | watch: { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 60 | selectedItemsCount: function (selectedItemsCount) { | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 61 | if (selectedItemsCount > 0) { | 
|  | 62 | this.isToolbarActive = true; | 
|  | 63 | } else { | 
|  | 64 | this.isToolbarActive = false; | 
|  | 65 | } | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 66 | }, | 
|  | 67 | }, | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 68 | }; | 
|  | 69 | </script> | 
|  | 70 |  | 
|  | 71 | <style lang="scss" scoped> | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 72 | $toolbar-height: 46px; | 
|  | 73 |  | 
|  | 74 | .toolbar-container { | 
|  | 75 | width: 100%; | 
|  | 76 | position: relative; | 
| Derick Montague | 9fc88d6 | 2021-01-06 11:25:39 -0600 | [diff] [blame] | 77 | z-index: $zindex-dropdown + 1; | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
|  | 80 | .toolbar-content { | 
|  | 81 | height: $toolbar-height; | 
| Yoshie Muranaka | 01da818 | 2020-07-08 15:46:43 -0700 | [diff] [blame] | 82 | background-color: theme-color('primary'); | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 83 | color: $white; | 
|  | 84 | position: absolute; | 
|  | 85 | left: 0; | 
|  | 86 | right: 0; | 
|  | 87 | top: -$toolbar-height; | 
|  | 88 | display: flex; | 
|  | 89 | flex-direction: row; | 
|  | 90 | justify-content: space-between; | 
|  | 91 | } | 
|  | 92 |  | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 93 | .toolbar-selected { | 
|  | 94 | line-height: $toolbar-height; | 
|  | 95 | margin: 0; | 
|  | 96 | padding: 0 $spacer; | 
|  | 97 | } | 
|  | 98 |  | 
| Sneha Patel | e516d4d | 2021-05-24 14:11:26 -0500 | [diff] [blame] | 99 | // Using v-deep to style export slot child-element | 
|  | 100 | // depricated and vue-js 3 | 
|  | 101 | .toolbar-actions ::v-deep .btn { | 
|  | 102 | position: relative; | 
|  | 103 | &:after { | 
|  | 104 | content: ''; | 
|  | 105 | position: absolute; | 
|  | 106 | left: 0; | 
|  | 107 | height: 1.5rem; | 
|  | 108 | width: 1px; | 
|  | 109 | background: rgba($white, 0.6); | 
|  | 110 | } | 
|  | 111 | &:last-child, | 
|  | 112 | &:first-child { | 
|  | 113 | &:after { | 
|  | 114 | width: 0; | 
|  | 115 | } | 
|  | 116 | } | 
|  | 117 | } | 
|  | 118 |  | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 119 | .slide-enter-active { | 
|  | 120 | transition: transform $duration--moderate-02 $entrance-easing--productive; | 
|  | 121 | } | 
|  | 122 | .slide-leave-active { | 
|  | 123 | transition: transform $duration--moderate-02 $exit-easing--productive; | 
|  | 124 | } | 
| SurenNeware | 151dd24 | 2020-11-10 20:15:05 +0530 | [diff] [blame] | 125 | .slide-enter, // Remove this vue2 based only class when switching to vue3 | 
|  | 126 | .slide-enter-from, // This is vue3 based only class modified from 'slide-enter' | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 127 | .slide-leave-to { | 
|  | 128 | transform: translateY($toolbar-height); | 
|  | 129 | } | 
|  | 130 | </style> |