| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 1 | <template> | 
 | 2 |   <div class="custom-form-file-container"> | 
 | 3 |     <label> | 
 | 4 |       <b-form-file | 
 | 5 |         :id="id" | 
 | 6 |         v-model="file" | 
 | 7 |         :accept="accept" | 
 | 8 |         :disabled="disabled" | 
 | 9 |         :state="state" | 
 | 10 |         plain | 
 | 11 |         @input="$emit('input', file)" | 
 | 12 |       > | 
 | 13 |       </b-form-file> | 
| Yoshie Muranaka | 391f949 | 2021-02-08 10:50:53 -0800 | [diff] [blame] | 14 |       <span | 
 | 15 |         class="add-file-btn btn" | 
 | 16 |         :class="{ | 
 | 17 |           disabled, | 
 | 18 |           'btn-secondary': isSecondary, | 
 | 19 |           'btn-primary': !isSecondary, | 
 | 20 |         }" | 
 | 21 |       > | 
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 22 |         {{ $t('global.fileUpload.browseText') }} | 
 | 23 |       </span> | 
 | 24 |       <slot name="invalid"></slot> | 
 | 25 |     </label> | 
 | 26 |     <div v-if="file" class="clear-selected-file px-3 py-2 mt-2"> | 
 | 27 |       {{ file ? file.name : '' }} | 
| Yoshie Muranaka | 2ec04fb | 2021-01-20 12:19:16 -0800 | [diff] [blame] | 28 |       <b-button | 
 | 29 |         variant="light" | 
 | 30 |         class="px-2 ml-auto" | 
 | 31 |         :disabled="disabled" | 
 | 32 |         @click="file = null" | 
| SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 33 |         ><icon-close :title="$t('global.fileUpload.clearSelectedFile')" /><span | 
 | 34 |           class="sr-only" | 
 | 35 |           >{{ $t('global.fileUpload.clearSelectedFile') }}</span | 
 | 36 |         > | 
 | 37 |       </b-button> | 
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 38 |     </div> | 
 | 39 |   </div> | 
 | 40 | </template> | 
 | 41 |  | 
 | 42 | <script> | 
 | 43 | import { BFormFile } from 'bootstrap-vue'; | 
 | 44 | import IconClose from '@carbon/icons-vue/es/close/20'; | 
 | 45 |  | 
 | 46 | export default { | 
 | 47 |   name: 'FormFile', | 
 | 48 |   components: { BFormFile, IconClose }, | 
 | 49 |   props: { | 
 | 50 |     id: { | 
 | 51 |       type: String, | 
 | 52 |       default: '', | 
 | 53 |     }, | 
 | 54 |     disabled: { | 
 | 55 |       type: Boolean, | 
 | 56 |       default: false, | 
 | 57 |     }, | 
 | 58 |     accept: { | 
 | 59 |       type: String, | 
 | 60 |       default: '', | 
 | 61 |     }, | 
 | 62 |     state: { | 
 | 63 |       type: Boolean, | 
 | 64 |       default: true, | 
 | 65 |     }, | 
| Yoshie Muranaka | 391f949 | 2021-02-08 10:50:53 -0800 | [diff] [blame] | 66 |     variant: { | 
 | 67 |       type: String, | 
 | 68 |       default: 'secondary', | 
 | 69 |     }, | 
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 70 |   }, | 
 | 71 |   data() { | 
 | 72 |     return { | 
 | 73 |       file: null, | 
 | 74 |     }; | 
 | 75 |   }, | 
| Yoshie Muranaka | 391f949 | 2021-02-08 10:50:53 -0800 | [diff] [blame] | 76 |   computed: { | 
 | 77 |     isSecondary() { | 
 | 78 |       return this.variant === 'secondary'; | 
 | 79 |     }, | 
 | 80 |   }, | 
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 81 | }; | 
 | 82 | </script> | 
 | 83 |  | 
 | 84 | <style lang="scss" scoped> | 
 | 85 | .form-control-file { | 
 | 86 |   opacity: 0; | 
 | 87 |   height: 0; | 
 | 88 |   &:focus + span { | 
| Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 89 |     box-shadow: | 
 | 90 |       inset 0 0 0 3px theme-color('primary'), | 
 | 91 |       inset 0 0 0 5px $white; | 
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 92 |   } | 
 | 93 | } | 
 | 94 |  | 
 | 95 | // Get mouse pointer on complete element | 
 | 96 | .add-file-btn { | 
 | 97 |   position: relative; | 
| Yoshie Muranaka | 391f949 | 2021-02-08 10:50:53 -0800 | [diff] [blame] | 98 |   &.disabled { | 
 | 99 |     border-color: gray('400'); | 
 | 100 |     background-color: gray('400'); | 
 | 101 |     color: gray('600'); | 
 | 102 |     box-shadow: none !important; | 
 | 103 |   } | 
| SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 104 | } | 
 | 105 |  | 
 | 106 | .clear-selected-file { | 
 | 107 |   display: flex; | 
 | 108 |   align-items: center; | 
 | 109 |   background-color: theme-color('light'); | 
 | 110 |   .btn { | 
 | 111 |     width: 36px; | 
 | 112 |     height: 36px; | 
 | 113 |     display: flex; | 
 | 114 |     align-items: center; | 
 | 115 |  | 
 | 116 |     &:focus { | 
 | 117 |       box-shadow: inset 0 0 0 2px theme-color('primary'); | 
 | 118 |     } | 
 | 119 |   } | 
 | 120 | } | 
 | 121 | </style> |