Skip to content

Commit 19b8919

Browse files
authored
Rewrite LoadingOverlay in Vue3 script setup syntax (#825)
We expose the methods hide() and show() as well because they are used by the Results page Bug: T354345
1 parent 960988d commit 19b8919

File tree

1 file changed

+36
-48
lines changed

1 file changed

+36
-48
lines changed

resources/js/Components/LoadingOverlay.vue

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,46 @@
66
</div>
77
</template>
88

9-
<script lang="ts">
10-
import { defineComponent } from 'vue';
9+
<script setup lang="ts">
10+
import { ref } from 'vue';
1111
import { CdxProgressBar } from "@wikimedia/codex";
1212
13-
export default defineComponent({
14-
name: 'LoadingOverlay',
15-
props: {
16-
delay: {
17-
type: Number,
18-
default: 250,
19-
},
20-
visible: {
21-
type: Boolean,
22-
default: false,
23-
}
24-
},
25-
components: {
26-
CdxProgressBar
27-
},
28-
data() {
29-
return {
30-
shown: this.visible,
31-
cachedStyles: {
32-
overflow: 'auto'
33-
}
34-
};
35-
},
36-
methods: {
37-
show(): void {
38-
if (this.shown) {
39-
return;
40-
}
13+
const props = withDefaults(defineProps<{
14+
delay: number
15+
visible: boolean
16+
}>(), {
17+
delay: 250,
18+
visible: false
19+
});
4120
42-
// Determine the current styles for body, in order to cache the overflow
43-
const bodyStyles = window.getComputedStyle(document.body);
44-
this.shown = true;
21+
const shown = ref(props.visible);
22+
const cachedStyles = ref({ overflow: 'auto' });
4523
46-
this.cachedStyles.overflow = bodyStyles.overflow;
47-
document.body.style.overflow = 'hidden';
48-
},
49-
hide(): Promise<void> {
50-
return new Promise((resolve) => {
51-
setTimeout(() => {
52-
this.shown = false;
53-
// Restore previous overflow value
54-
document.body.style.overflow = this.cachedStyles.overflow;
55-
resolve();
56-
}, this.delay);
57-
});
58-
},
59-
},
60-
});
24+
function show(){
25+
if (shown.value) {
26+
return;
27+
}
28+
29+
// Determine the current styles for body, in order to cache the overflow
30+
const bodyStyles = window.getComputedStyle(document.body);
31+
shown.value = true;
32+
33+
cachedStyles.value.overflow = bodyStyles.overflow;
34+
document.body.style.overflow = 'hidden';
35+
}
36+
37+
function hide(): Promise<void> {
38+
return new Promise((resolve) => {
39+
setTimeout(() => {
40+
shown.value = false;
41+
// Restore previous overflow value
42+
document.body.style.overflow = cachedStyles.value.overflow;
43+
resolve();
44+
}, props.delay);
45+
});
46+
}
47+
48+
defineExpose({show, hide});
6149
</script>
6250

6351
<style lang="scss">

0 commit comments

Comments
 (0)