Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 1 | <template> |
| 2 | <transition name="fade"> |
Dixsie Wolmers | 61c65ef | 2020-10-06 14:43:49 -0500 | [diff] [blame] | 3 | <b-progress v-if="!isLoadingComplete"> |
Derick Montague | de87f67 | 2020-06-27 11:59:17 -0500 | [diff] [blame] | 4 | <b-progress-bar |
Dixsie Wolmers | 3559304 | 2020-07-17 09:38:12 -0500 | [diff] [blame] | 5 | striped |
| 6 | animated |
Derick Montague | de87f67 | 2020-06-27 11:59:17 -0500 | [diff] [blame] | 7 | :value="loadingIndicatorValue" |
| 8 | :aria-label="$t('global.ariaLabel.progressBar')" |
| 9 | /> |
| 10 | </b-progress> |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 11 | </transition> |
| 12 | </template> |
| 13 | |
| 14 | <script> |
Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 15 | import { useI18n } from 'vue-i18n'; |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 16 | export default { |
| 17 | data() { |
| 18 | return { |
Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 19 | $t: useI18n().t, |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 20 | loadingIndicatorValue: 0, |
| 21 | isLoadingComplete: false, |
| 22 | loadingIntervalId: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 23 | timeoutId: null, |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 24 | }; |
| 25 | }, |
| 26 | created() { |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 27 | this.$root.$on('loader-start', () => { |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 28 | this.startLoadingInterval(); |
| 29 | }); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 30 | this.$root.$on('loader-end', () => { |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 31 | this.endLoadingInterval(); |
| 32 | }); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 33 | this.$root.$on('loader-hide', () => { |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 34 | this.hideLoadingBar(); |
| 35 | }); |
| 36 | }, |
| 37 | methods: { |
| 38 | startLoadingInterval() { |
| 39 | this.clearLoadingInterval(); |
| 40 | this.clearTimeout(); |
| 41 | this.loadingIndicatorValue = 0; |
| 42 | this.isLoadingComplete = false; |
| 43 | this.loadingIntervalId = setInterval(() => { |
| 44 | this.loadingIndicatorValue += 1; |
| 45 | if (this.loadingIndicatorValue > 100) this.clearLoadingInterval(); |
| 46 | }, 100); |
| 47 | }, |
| 48 | endLoadingInterval() { |
| 49 | this.clearLoadingInterval(); |
| 50 | this.clearTimeout(); |
| 51 | this.loadingIndicatorValue = 100; |
| 52 | this.timeoutId = setTimeout(() => { |
| 53 | // Let animation complete before hiding |
| 54 | // the loading bar |
| 55 | this.isLoadingComplete = true; |
| 56 | }, 1000); |
| 57 | }, |
| 58 | hideLoadingBar() { |
| 59 | this.clearLoadingInterval(); |
| 60 | this.clearTimeout(); |
| 61 | this.loadingIndicatorValue = 0; |
| 62 | this.isLoadingComplete = true; |
| 63 | }, |
| 64 | clearLoadingInterval() { |
| 65 | if (this.loadingIntervalId) clearInterval(this.loadingIntervalId); |
| 66 | this.loadingIntervalId = null; |
| 67 | }, |
| 68 | clearTimeout() { |
| 69 | if (this.timeoutId) clearTimeout(this.timeoutId); |
| 70 | this.timeoutId = null; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 71 | }, |
| 72 | }, |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 73 | }; |
| 74 | </script> |
| 75 | |
| 76 | <style lang="scss" scoped> |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 77 | @import '@/assets/styles/bmc/helpers/_index.scss'; |
| 78 | @import '@/assets/styles/bootstrap/_helpers.scss'; |
| 79 | |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 80 | .progress { |
| 81 | position: absolute; |
| 82 | left: 0; |
| 83 | right: 0; |
| 84 | bottom: -0.4rem; |
| 85 | opacity: 1; |
| 86 | transition: opacity $duration--moderate-01 $standard-easing--productive; |
Dixsie Wolmers | 61c65ef | 2020-10-06 14:43:49 -0500 | [diff] [blame] | 87 | height: 0.4rem; |
SurenNeware | 151dd24 | 2020-11-10 20:15:05 +0530 | [diff] [blame] | 88 | |
| 89 | &.fade-enter, // Remove this vue2 based only class when switching to vue3 |
| 90 | &.fade-enter-from, // This is vue3 based only class modified from 'fade-enter' |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 91 | &.fade-leave-to { |
| 92 | opacity: 0; |
| 93 | } |
| 94 | } |
Mateusz Gapski | 21d6de0 | 2020-07-29 14:28:23 +0200 | [diff] [blame] | 95 | .progress-bar { |
| 96 | background-color: $loading-color; |
| 97 | } |
Yoshie Muranaka | 3be801a | 2020-04-21 11:34:56 -0700 | [diff] [blame] | 98 | </style> |