AmAttachment.vue
316 lines
| 1 | <template> |
| 2 | <el-upload |
| 3 | ref="attachments" |
| 4 | v-model:file-list="model" |
| 5 | :class="['am-attachment', props.customClass]" |
| 6 | :action="props.action" |
| 7 | :multiple="props.multiple" |
| 8 | :data="props.data" |
| 9 | :name="props.name" |
| 10 | :with-credentials="props.withCredentials" |
| 11 | :show-file-list="props.showFileList" |
| 12 | :drag="props.drag" |
| 13 | :accept="props.accept" |
| 14 | :auto-upload="props.autoUpload" |
| 15 | :disabled="props.disabled" |
| 16 | :limit="props.limit" |
| 17 | :style="cssVars" |
| 18 | :on-change="onChange" |
| 19 | :on-remove="onRemove" |
| 20 | > |
| 21 | <AmButton |
| 22 | class="am-attachment__btn" |
| 23 | tabindex="-1" |
| 24 | :icon-only="props.iconOnly" |
| 25 | :size="props.btnSize" |
| 26 | :category="props.btnCategory" |
| 27 | :type="props.btnType" |
| 28 | :native-type="props.btnNativeType" |
| 29 | :round="props.btnRound" |
| 30 | :circle="props.btnCircle" |
| 31 | :loading="props.btnLoading" |
| 32 | :autofocus="props.btnAutofocus" |
| 33 | :prefix="props.btnPrefix" |
| 34 | :suffix="props.btnSuffix" |
| 35 | :icon="props.btnIcon" |
| 36 | :loading-icon="props.btnLoadingIcon" |
| 37 | :disabled="props.disabled" |
| 38 | > |
| 39 | <slot></slot> |
| 40 | </AmButton> |
| 41 | </el-upload> |
| 42 | </template> |
| 43 | |
| 44 | <script setup> |
| 45 | // * Components |
| 46 | import AmButton from '../button/AmButton.vue' |
| 47 | |
| 48 | // * Import from Vue |
| 49 | import { computed, ref } from 'vue' |
| 50 | |
| 51 | // * Composables |
| 52 | import { useColorTransparency } from '../../../assets/js/common/colorManipulation' |
| 53 | |
| 54 | /** |
| 55 | * Component Props |
| 56 | */ |
| 57 | const props = defineProps({ |
| 58 | id: { |
| 59 | type: [String, Number], |
| 60 | default: 0, |
| 61 | }, |
| 62 | modelValue: { |
| 63 | type: Array, |
| 64 | }, |
| 65 | action: { |
| 66 | type: String, |
| 67 | default: '', |
| 68 | }, |
| 69 | multiple: { |
| 70 | type: Boolean, |
| 71 | default: false, |
| 72 | }, |
| 73 | data: { |
| 74 | type: [String, Object, Array, Function, Number], |
| 75 | }, |
| 76 | name: { |
| 77 | type: String, |
| 78 | name: 'file', |
| 79 | }, |
| 80 | withCredentials: { |
| 81 | type: Boolean, |
| 82 | default: false, |
| 83 | }, |
| 84 | showFileList: { |
| 85 | type: Boolean, |
| 86 | default: true, |
| 87 | }, |
| 88 | drag: { |
| 89 | type: Boolean, |
| 90 | default: false, |
| 91 | }, |
| 92 | accept: String, |
| 93 | autoUpload: { |
| 94 | type: Boolean, |
| 95 | default: true, |
| 96 | }, |
| 97 | disabled: { |
| 98 | type: Boolean, |
| 99 | default: false, |
| 100 | }, |
| 101 | limit: Number, |
| 102 | customClass: { |
| 103 | type: String, |
| 104 | default: '', |
| 105 | }, |
| 106 | iconOnly: { |
| 107 | type: Boolean, |
| 108 | default: false, |
| 109 | }, |
| 110 | btnSize: { |
| 111 | // default / medium / small / mini / micro |
| 112 | type: String, |
| 113 | default: 'default', |
| 114 | validator(value) { |
| 115 | return ['default', 'medium', 'small', 'mini', 'micro'].includes(value) |
| 116 | }, |
| 117 | }, |
| 118 | btnCategory: { |
| 119 | // primary / secondary / success / warning / danger / error |
| 120 | type: String, |
| 121 | default: 'primary', |
| 122 | validator(value) { |
| 123 | return ['primary', 'secondary', 'success', 'warning', 'danger', 'error'].includes(value) |
| 124 | }, |
| 125 | }, |
| 126 | btnType: { |
| 127 | // filled / plain / text |
| 128 | type: String, |
| 129 | default: 'filled', |
| 130 | validator(value) { |
| 131 | return ['filled', 'plain', 'text'].includes(value) |
| 132 | }, |
| 133 | }, |
| 134 | btnNativeType: { |
| 135 | // button / submit / reset |
| 136 | type: String, |
| 137 | default: 'button', |
| 138 | validator(value) { |
| 139 | return ['button', 'submit', 'reset'].includes(value) |
| 140 | }, |
| 141 | }, |
| 142 | btnRound: { |
| 143 | type: Boolean, |
| 144 | default: false, |
| 145 | }, |
| 146 | btnCircle: { |
| 147 | type: Boolean, |
| 148 | default: false, |
| 149 | }, |
| 150 | btnLoading: { |
| 151 | type: Boolean, |
| 152 | default: false, |
| 153 | }, |
| 154 | btnAutofocus: { |
| 155 | type: Boolean, |
| 156 | default: false, |
| 157 | }, |
| 158 | btnPrefix: { |
| 159 | type: [String, Object, Function], |
| 160 | default: '', |
| 161 | }, |
| 162 | btnSuffix: { |
| 163 | type: [String, Object, Function], |
| 164 | default: '', |
| 165 | }, |
| 166 | btnIcon: { |
| 167 | type: [String, Object, Function], |
| 168 | default: '', |
| 169 | }, |
| 170 | btnLoadingIcon: { |
| 171 | type: [String, Object, Function], |
| 172 | default: '', |
| 173 | }, |
| 174 | }) |
| 175 | |
| 176 | /** |
| 177 | * Component Emits |
| 178 | * */ |
| 179 | const emits = defineEmits(['change', 'remove', 'update:modelValue']) |
| 180 | |
| 181 | // * Component model |
| 182 | let model = computed({ |
| 183 | get: () => props.modelValue, |
| 184 | set: (val) => { |
| 185 | emits('update:modelValue', val) |
| 186 | }, |
| 187 | }) |
| 188 | |
| 189 | const attachments = ref(null) |
| 190 | |
| 191 | /** |
| 192 | * Component Event Handlers |
| 193 | */ |
| 194 | function onChange(uploadFile, uploadFiles) { |
| 195 | let file = { |
| 196 | id: props.id, |
| 197 | raw: uploadFiles, |
| 198 | } |
| 199 | |
| 200 | emits('change', file) |
| 201 | } |
| 202 | |
| 203 | function onRemove(removedFile, arrayOfFiles) { |
| 204 | let file = { |
| 205 | id: props.id, |
| 206 | raw: arrayOfFiles, |
| 207 | } |
| 208 | |
| 209 | emits('remove', file) |
| 210 | } |
| 211 | |
| 212 | // * Colors |
| 213 | let amColors = inject( |
| 214 | 'amColors', |
| 215 | ref({ |
| 216 | colorPrimary: '#1246D6', |
| 217 | colorSuccess: '#019719', |
| 218 | colorError: '#B4190F', |
| 219 | colorWarning: '#CCA20C', |
| 220 | colorMainBgr: '#FFFFFF', |
| 221 | colorMainHeadingText: '#33434C', |
| 222 | colorMainText: '#1A2C37', |
| 223 | colorSbBgr: '#17295A', |
| 224 | colorSbText: '#FFFFFF', |
| 225 | colorInpBgr: '#FFFFFF', |
| 226 | colorInpBorder: '#D1D5D7', |
| 227 | colorInpText: '#1A2C37', |
| 228 | colorInpPlaceHolder: '#1A2C37', |
| 229 | colorDropBgr: '#FFFFFF', |
| 230 | colorDropBorder: '#D1D5D7', |
| 231 | colorDropText: '#0E1920', |
| 232 | colorBtnPrim: '#265CF2', |
| 233 | colorBtnPrimText: '#FFFFFF', |
| 234 | colorBtnSec: '#1A2C37', |
| 235 | colorBtnSecText: '#FFFFFF', |
| 236 | }), |
| 237 | ) |
| 238 | |
| 239 | let cssVars = computed(() => { |
| 240 | return { |
| 241 | '--am-c-btn-op30': useColorTransparency(amColors.value.colorBtnPrim, 0.3), |
| 242 | } |
| 243 | }) |
| 244 | </script> |
| 245 | |
| 246 | <style lang="scss"> |
| 247 | .amelia-v2-booking { |
| 248 | #amelia-container { |
| 249 | .am-attachment { |
| 250 | // -atf- attachment file |
| 251 | --am-c-atf-text: var(--am-c-main-text); |
| 252 | --am-c-atf-bgr: var(--am-c-main-bgr); |
| 253 | max-width: 100%; |
| 254 | width: 100%; |
| 255 | |
| 256 | &__btn { |
| 257 | width: 100%; |
| 258 | margin: 0; |
| 259 | |
| 260 | &.is-disabled { |
| 261 | cursor: not-allowed; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | .el-upload { |
| 266 | width: 100%; |
| 267 | |
| 268 | &:focus { |
| 269 | border-radius: 6px; |
| 270 | box-shadow: 0 0 0 3px var(--am-c-btn-op30); |
| 271 | } |
| 272 | |
| 273 | &-list { |
| 274 | &__item { |
| 275 | width: 100%; |
| 276 | margin: 4px 0; |
| 277 | background-color: var(--am-c-atf-bgr); |
| 278 | |
| 279 | &:hover { |
| 280 | --am-c-atf-bgr: var(--am-c-inp-bgr); |
| 281 | --am-c-atf-text: var(--am-c-inp-text); |
| 282 | } |
| 283 | |
| 284 | &-name { |
| 285 | max-width: 200px; |
| 286 | padding: 4px; |
| 287 | margin: 0 24px 0 0; |
| 288 | color: var(--am-c-atf-text); |
| 289 | |
| 290 | * { |
| 291 | color: var(--am-c-atf-text); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | &-status-label { |
| 296 | top: 7px; |
| 297 | i { |
| 298 | color: var(--am-c-primary); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | .el-icon--close { |
| 303 | color: var(--am-c-atf-text); |
| 304 | } |
| 305 | |
| 306 | .el-progress { |
| 307 | display: none; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | </style> |
| 316 |