blob: f8d8b88fbf3c6f3aaa76d6eaface0a9fd9166538 [file] [log] [blame]
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -06001<template>
2 <b-button
3 id="scrollToTopBtn"
4 class="btn-top btn-icon-only"
Derick Montague86e11ad2021-01-04 11:19:08 -06005 :class="{ 'show-btn': showButton }"
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -06006 variant="secondary"
7 :title="$t('global.ariaLabel.scrollToTop')"
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -06008 @click="scrollToTop"
9 >
10 <icon-up-to-top />
SurenNeware6e2cb972020-12-24 20:58:16 +053011 <span class="sr-only">{{ $t('global.ariaLabel.scrollToTop') }}</span>
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060012 </b-button>
13</template>
14
15<script>
16import UpToTop24 from '@carbon/icons-vue/es/up-to-top/24';
17
18import { debounce } from 'lodash';
Ed Tanousdbd37e02024-03-23 14:56:34 -070019import { useI18n } from 'vue-i18n';
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060020
21export default {
22 name: 'BackToTop',
23 components: { IconUpToTop: UpToTop24 },
24 data() {
25 return {
Ed Tanousdbd37e02024-03-23 14:56:34 -070026 $t: useI18n().t,
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060027 showButton: false,
28 };
29 },
30 created() {
31 window.addEventListener('scroll', debounce(this.handleScroll, 200));
32 },
33 methods: {
34 handleScroll() {
35 document.documentElement.scrollTop > 500
36 ? (this.showButton = true)
37 : (this.showButton = false);
38 },
39 scrollToTop() {
40 document.documentElement.scrollTo({
41 top: 0,
42 behavior: 'smooth',
43 });
44 },
45 },
46};
47</script>
48
49<style lang="scss" scoped>
Ed Tanous9c729792024-03-23 14:56:34 -070050@import '@/assets/styles/bmc/helpers/_index.scss';
51@import '@/assets/styles/bootstrap/_helpers.scss';
52
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060053.btn-top {
54 position: fixed;
55 bottom: 24px;
56 right: 24px;
Derick Montague86e11ad2021-01-04 11:19:08 -060057
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060058 box-shadow: $box-shadow;
Derick Montague86e11ad2021-01-04 11:19:08 -060059 visibility: hidden;
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060060 opacity: 0;
61 transition: $transition-base;
Derick Montague86e11ad2021-01-04 11:19:08 -060062 z-index: $zindex-fixed;
63
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060064 @media (min-width: 1600px) {
65 left: 1485px;
66 right: auto;
67 }
68}
Derick Montague86e11ad2021-01-04 11:19:08 -060069.show-btn {
70 visibility: visible;
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060071 opacity: 1;
Dixsie Wolmers970ea7d2020-11-16 16:46:01 -060072}
73</style>