| 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" | 
 | 12 |             variant="primary" | 
 | 13 |             class="d-block" | 
 | 14 |             @click="$emit('batchAction', action.value)" | 
 | 15 |           > | 
| Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 16 |             {{ action.label }} | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 17 |           </b-button> | 
| Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame^] | 18 |           <slot name="export"></slot> | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 19 |           <b-button | 
 | 20 |             variant="primary" | 
 | 21 |             class="d-block" | 
 | 22 |             @click="$emit('clearSelected')" | 
 | 23 |           > | 
| Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 24 |             {{ $t('global.action.cancel') }} | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 25 |           </b-button> | 
 | 26 |         </div> | 
 | 27 |       </div> | 
 | 28 |     </div> | 
 | 29 |   </transition> | 
 | 30 | </template> | 
 | 31 |  | 
 | 32 | <script> | 
 | 33 | export default { | 
 | 34 |   name: 'TableToolbar', | 
 | 35 |   props: { | 
 | 36 |     selectedItemsCount: { | 
 | 37 |       type: Number, | 
 | 38 |       required: true | 
 | 39 |     }, | 
 | 40 |     actions: { | 
 | 41 |       type: Array, | 
| Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame^] | 42 |       default: () => [], | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 43 |       validator: prop => { | 
 | 44 |         return prop.every(action => { | 
 | 45 |           return ( | 
| Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 46 |             action.hasOwnProperty('value') && action.hasOwnProperty('label') | 
| Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 47 |           ); | 
 | 48 |         }); | 
 | 49 |       } | 
 | 50 |     } | 
 | 51 |   }, | 
 | 52 |   data() { | 
 | 53 |     return { | 
 | 54 |       isToolbarActive: false | 
 | 55 |     }; | 
 | 56 |   }, | 
 | 57 |   watch: { | 
 | 58 |     selectedItemsCount: function(selectedItemsCount) { | 
 | 59 |       if (selectedItemsCount > 0) { | 
 | 60 |         this.isToolbarActive = true; | 
 | 61 |       } else { | 
 | 62 |         this.isToolbarActive = false; | 
 | 63 |       } | 
 | 64 |     } | 
 | 65 |   } | 
 | 66 | }; | 
 | 67 | </script> | 
 | 68 |  | 
 | 69 | <style lang="scss" scoped> | 
 | 70 | $toolbar-height: 46px; | 
 | 71 |  | 
 | 72 | .toolbar-container { | 
 | 73 |   width: 100%; | 
 | 74 |   position: relative; | 
 | 75 | } | 
 | 76 |  | 
 | 77 | .toolbar-content { | 
 | 78 |   height: $toolbar-height; | 
 | 79 |   background-color: $primary; | 
 | 80 |   color: $white; | 
 | 81 |   position: absolute; | 
 | 82 |   left: 0; | 
 | 83 |   right: 0; | 
 | 84 |   top: -$toolbar-height; | 
 | 85 |   display: flex; | 
 | 86 |   flex-direction: row; | 
 | 87 |   justify-content: space-between; | 
 | 88 | } | 
 | 89 |  | 
 | 90 | .toolbar-actions { | 
 | 91 |   > :last-child { | 
 | 92 |     position: relative; | 
 | 93 |     &::before { | 
 | 94 |       content: ''; | 
 | 95 |       position: absolute; | 
 | 96 |       height: $toolbar-height / 2; | 
 | 97 |       border-left: 2px solid $white; | 
 | 98 |       left: -2px; | 
 | 99 |       top: $toolbar-height / 4; | 
 | 100 |     } | 
 | 101 |   } | 
 | 102 | } | 
 | 103 |  | 
 | 104 | .toolbar-selected { | 
 | 105 |   line-height: $toolbar-height; | 
 | 106 |   margin: 0; | 
 | 107 |   padding: 0 $spacer; | 
 | 108 | } | 
 | 109 |  | 
 | 110 | .slide-enter-active { | 
 | 111 |   transition: transform $duration--moderate-02 $entrance-easing--productive; | 
 | 112 | } | 
 | 113 | .slide-leave-active { | 
 | 114 |   transition: transform $duration--moderate-02 $exit-easing--productive; | 
 | 115 | } | 
 | 116 | .slide-enter, | 
 | 117 | .slide-leave-to { | 
 | 118 |   transform: translateY($toolbar-height); | 
 | 119 | } | 
 | 120 | </style> |