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"> |
| 9 | <b-button |
| 10 | v-for="(action, index) in actions" |
| 11 | :key="index" |
Yoshie Muranaka | ed06dc1 | 2020-06-16 12:12:27 -0700 | [diff] [blame] | 12 | :data-test-id="`table-button-${action.value}Selected`" |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 13 | variant="primary" |
| 14 | class="d-block" |
| 15 | @click="$emit('batchAction', action.value)" |
| 16 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 17 | {{ action.label }} |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 18 | </b-button> |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 19 | <slot name="export"></slot> |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 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" |
| 23 | @click="$emit('clearSelected')" |
| 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 | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 47 | action.hasOwnProperty('value') && action.hasOwnProperty('label') |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 48 | ); |
| 49 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 50 | }, |
| 51 | }, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 52 | }, |
| 53 | data() { |
| 54 | return { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 55 | isToolbarActive: false, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 56 | }; |
| 57 | }, |
| 58 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 59 | selectedItemsCount: function (selectedItemsCount) { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 60 | if (selectedItemsCount > 0) { |
| 61 | this.isToolbarActive = true; |
| 62 | } else { |
| 63 | this.isToolbarActive = false; |
| 64 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 65 | }, |
| 66 | }, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 67 | }; |
| 68 | </script> |
| 69 | |
| 70 | <style lang="scss" scoped> |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 71 | $toolbar-height: 46px; |
| 72 | |
| 73 | .toolbar-container { |
| 74 | width: 100%; |
| 75 | position: relative; |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 76 | z-index: 5; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | .toolbar-content { |
| 80 | height: $toolbar-height; |
Mateusz Gapski | 2a93497 | 2020-07-23 12:10:10 +0200 | [diff] [blame] | 81 | z-index: $zindex-dropdown + 1; |
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 | |
| 99 | .slide-enter-active { |
| 100 | transition: transform $duration--moderate-02 $entrance-easing--productive; |
| 101 | } |
| 102 | .slide-leave-active { |
| 103 | transition: transform $duration--moderate-02 $exit-easing--productive; |
| 104 | } |
| 105 | .slide-enter, |
| 106 | .slide-leave-to { |
| 107 | transform: translateY($toolbar-height); |
| 108 | } |
| 109 | </style> |