blob: 929769061ad991265cb7b7c1f602cdc430c1d747 [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() {
jason westoverd36ac8a2025-11-03 20:58:59 -060027 this.$eventBus.on('loader-start', () => {
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070028 this.startLoadingInterval();
29 });
jason westoverd36ac8a2025-11-03 20:58:59 -060030 this.$eventBus.on('loader-end', () => {
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070031 this.endLoadingInterval();
32 });
jason westoverd36ac8a2025-11-03 20:58:59 -060033 this.$eventBus.on('loader-hide', () => {
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070034 this.hideLoadingBar();
35 });
36 },
jason westoverd36ac8a2025-11-03 20:58:59 -060037 beforeUnmount() {
38 this.$eventBus.off('loader-start', this.handleLoaderStart);
39 this.$eventBus.off('loader-end', this.handleLoaderEnd);
40 this.$eventBus.off('loader-hide', this.handleLoaderHide);
41 },
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070042 methods: {
43 startLoadingInterval() {
44 this.clearLoadingInterval();
45 this.clearTimeout();
46 this.loadingIndicatorValue = 0;
47 this.isLoadingComplete = false;
48 this.loadingIntervalId = setInterval(() => {
49 this.loadingIndicatorValue += 1;
50 if (this.loadingIndicatorValue > 100) this.clearLoadingInterval();
51 }, 100);
52 },
53 endLoadingInterval() {
54 this.clearLoadingInterval();
55 this.clearTimeout();
56 this.loadingIndicatorValue = 100;
57 this.timeoutId = setTimeout(() => {
58 // Let animation complete before hiding
59 // the loading bar
60 this.isLoadingComplete = true;
61 }, 1000);
62 },
63 hideLoadingBar() {
64 this.clearLoadingInterval();
65 this.clearTimeout();
66 this.loadingIndicatorValue = 0;
67 this.isLoadingComplete = true;
68 },
69 clearLoadingInterval() {
70 if (this.loadingIntervalId) clearInterval(this.loadingIntervalId);
71 this.loadingIntervalId = null;
72 },
73 clearTimeout() {
74 if (this.timeoutId) clearTimeout(this.timeoutId);
75 this.timeoutId = null;
Derick Montague602e98a2020-10-21 16:20:00 -050076 },
77 },
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070078};
79</script>
80
81<style lang="scss" scoped>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070082.progress {
83 position: absolute;
84 left: 0;
85 right: 0;
86 bottom: -0.4rem;
87 opacity: 1;
88 transition: opacity $duration--moderate-01 $standard-easing--productive;
Dixsie Wolmers61c65ef2020-10-06 14:43:49 -050089 height: 0.4rem;
SurenNeware151dd242020-11-10 20:15:05 +053090
91 &.fade-enter, // Remove this vue2 based only class when switching to vue3
92 &.fade-enter-from, // This is vue3 based only class modified from 'fade-enter'
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070093 &.fade-leave-to {
94 opacity: 0;
95 }
96}
Mateusz Gapski21d6de02020-07-29 14:28:23 +020097.progress-bar {
98 background-color: $loading-color;
99}
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700100</style>