Skip to content

Commit 1a00a39

Browse files
bartoszherbaFrodigo
authored andcommitted
feat(theme): add LoadWhenVisible component and lazyload footer
- update social icons to reduce weight and increase quality - load footer only when visible
1 parent ac62c4a commit 1a00a39

File tree

8 files changed

+76
-43
lines changed

8 files changed

+76
-43
lines changed

packages/theme/components/AppFooter.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ export default {
120120
}
121121
&__social-image {
122122
margin: 0 var(--spacer-2xs) 0 0;
123+
background-color: #fff;
124+
border-radius: 100%;
123125
}
124126
}
125127
.sf-footer {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<div ref="root">
3+
<slot v-if="isVisible" />
4+
</div>
5+
</template>
6+
<script>
7+
import {
8+
defineComponent, onMounted, onUnmounted, ref,
9+
} from '@nuxtjs/composition-api';
10+
11+
export default defineComponent({
12+
name: 'LoadWhenVisible',
13+
props: {
14+
options: {
15+
type: Object,
16+
default: () => ({
17+
rootMargin: '0px 0px 200px 0px',
18+
}),
19+
},
20+
21+
},
22+
setup({ options }) {
23+
const isVisible = ref(false);
24+
const root = ref(null);
25+
26+
let observer = null;
27+
if (process.browser && ('IntersectionObserver' in window)) {
28+
observer = new IntersectionObserver((entries) => {
29+
if (entries[0].intersectionRatio <= 0) return;
30+
observer.unobserve(root.value);
31+
isVisible.value = true;
32+
}, options);
33+
}
34+
35+
onMounted(() => {
36+
if (observer) {
37+
observer.observe(root.value);
38+
}
39+
});
40+
41+
onUnmounted(() => {
42+
if (observer) {
43+
observer.unobserve(root.value);
44+
}
45+
});
46+
47+
return {
48+
root,
49+
isVisible,
50+
};
51+
},
52+
});
53+
</script>

packages/theme/layouts/default.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
<nuxt :key="route.fullPath" />
1313
</div>
1414
<BottomNavigation />
15-
<AppFooter />
15+
<LoadWhenVisible>
16+
<AppFooter />
17+
</LoadWhenVisible>
1618
</div>
1719
</template>
1820

@@ -25,6 +27,7 @@ import {
2527
useUser,
2628
} from '@vue-storefront/magento';
2729
import useUiState from '~/composables/useUiState.ts';
30+
import LoadWhenVisible from '~/components/utils/LoadWhenVisible';
2831
2932
import { useMagentoConfiguration } from '~/composables/useMagentoConfiguration';
3033
import AppHeader from '~/components/AppHeader.vue';
@@ -35,6 +38,7 @@ export default defineComponent({
3538
name: 'DefaultLayout',
3639
3740
components: {
41+
LoadWhenVisible,
3842
LazyHydrate,
3943
AppHeader,
4044
TopBar,
Lines changed: 1 addition & 4 deletions
Loading

packages/theme/static/icons/google.svg

Lines changed: 1 addition & 10 deletions
Loading

packages/theme/static/icons/pinterest.svg

Lines changed: 5 additions & 9 deletions
Loading

packages/theme/static/icons/twitter.svg

Lines changed: 1 addition & 10 deletions
Loading

packages/theme/static/icons/youtube.svg

Lines changed: 8 additions & 9 deletions
Loading

0 commit comments

Comments
 (0)