blob: 8b630934c45ec10ddfd929aa49305022418073af [file] [log] [blame]
Yoshie Muranaka3be801a2020-04-21 11:34:56 -07001<template>
2 <transition name="fade">
Dixsie Wolmers61c65ef2020-10-06 14:43:49 -05003 <b-progress v-if="!isLoadingComplete">
Derick Montaguede87f672020-06-27 11:59:17 -05004 <b-progress-bar
Dixsie Wolmers35593042020-07-17 09:38:12 -05005 striped
6 animated
Derick Montaguede87f672020-06-27 11:59:17 -05007 :value="loadingIndicatorValue"
8 :aria-label="$t('global.ariaLabel.progressBar')"
9 />
10 </b-progress>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070011 </transition>
12</template>
13
14<script>
Ed Tanous883a0d52024-03-23 14:56:34 -070015import { useI18n } from 'vue-i18n';
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070016export default {
17 data() {
18 return {
Ed Tanous883a0d52024-03-23 14:56:34 -070019 $t: useI18n().t,
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070020 loadingIndicatorValue: 0,
21 isLoadingComplete: false,
22 loadingIntervalId: null,
Derick Montague602e98a2020-10-21 16:20:00 -050023 timeoutId: null,
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070024 };
25 },
26 created() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053027 this.$root.$on('loader-start', () => {
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070028 this.startLoadingInterval();
29 });
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053030 this.$root.$on('loader-end', () => {
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070031 this.endLoadingInterval();
32 });
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053033 this.$root.$on('loader-hide', () => {
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070034 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 Montague602e98a2020-10-21 16:20:00 -050071 },
72 },
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070073};
74</script>
75
76<style lang="scss" scoped>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070077.progress {
78 position: absolute;
79 left: 0;
80 right: 0;
81 bottom: -0.4rem;
82 opacity: 1;
83 transition: opacity $duration--moderate-01 $standard-easing--productive;
Dixsie Wolmers61c65ef2020-10-06 14:43:49 -050084 height: 0.4rem;
SurenNeware151dd242020-11-10 20:15:05 +053085
86 &.fade-enter, // Remove this vue2 based only class when switching to vue3
87 &.fade-enter-from, // This is vue3 based only class modified from 'fade-enter'
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070088 &.fade-leave-to {
89 opacity: 0;
90 }
91}
Mateusz Gapski21d6de02020-07-29 14:28:23 +020092.progress-bar {
93 background-color: $loading-color;
94}
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070095</style>