@namelivia/vue-components 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +328 -259
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +357 -287
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/InfiniteScroll/InfiniteScroll.cy.js +7 -0
- package/src/InfiniteScroll/InfiniteScroll.stories.js +38 -0
- package/src/InfiniteScroll/InfiniteScroll.vue +59 -0
- package/src/index.js +1 -0
- package/styles/index.css +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import InfiniteScroll from './InfiniteScroll.vue';
|
|
2
|
+
import Card from '../Card/Card.vue';
|
|
3
|
+
import { ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Components/InfiniteScroll',
|
|
7
|
+
component: InfiniteScroll,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const Default = {
|
|
11
|
+
render: (args) => ({
|
|
12
|
+
components: { InfiniteScroll, Card },
|
|
13
|
+
setup() {
|
|
14
|
+
const items = ref([1, 2, 3, 4, 5]);
|
|
15
|
+
const loadMore = () => {
|
|
16
|
+
const last = items.value[items.value.length - 1];
|
|
17
|
+
// Simulate API delay
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
for (let i = 1; i <= 5; i++) {
|
|
20
|
+
items.value.push(last + i);
|
|
21
|
+
}
|
|
22
|
+
}, 500);
|
|
23
|
+
};
|
|
24
|
+
return { args, items, loadMore };
|
|
25
|
+
},
|
|
26
|
+
template: `
|
|
27
|
+
<div style="height: 400px; overflow-y: auto; border: 1px solid #ccc;">
|
|
28
|
+
<InfiniteScroll v-bind="args" @load-more="loadMore">
|
|
29
|
+
<div v-for="item in items" :key="item" style="padding: 20px; border-bottom: 1px solid #eee;">
|
|
30
|
+
<Card :title="'Item ' + item">
|
|
31
|
+
<p>Scroll down to load more content...</p>
|
|
32
|
+
</Card>
|
|
33
|
+
</div>
|
|
34
|
+
</InfiniteScroll>
|
|
35
|
+
</div>
|
|
36
|
+
`,
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<template lang="pug">
|
|
2
|
+
div(class="infinite-scroll-container")
|
|
3
|
+
slot
|
|
4
|
+
div(ref="sentinel" class="sentinel")
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup>
|
|
8
|
+
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
|
9
|
+
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
threshold: {
|
|
12
|
+
type: Number,
|
|
13
|
+
default: 0.1
|
|
14
|
+
},
|
|
15
|
+
rootMargin: {
|
|
16
|
+
type: String,
|
|
17
|
+
default: '0px'
|
|
18
|
+
},
|
|
19
|
+
disabled: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
default: false
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits(['load-more']);
|
|
26
|
+
const sentinel = ref(null);
|
|
27
|
+
let observer = null;
|
|
28
|
+
|
|
29
|
+
onMounted(() => {
|
|
30
|
+
observer = new IntersectionObserver(([entry]) => {
|
|
31
|
+
if (entry.isIntersecting && !props.disabled) {
|
|
32
|
+
emit('load-more');
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
rootMargin: props.rootMargin,
|
|
36
|
+
threshold: props.threshold
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (sentinel.value) {
|
|
40
|
+
observer.observe(sentinel.value);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
onBeforeUnmount(() => {
|
|
45
|
+
if (observer) {
|
|
46
|
+
observer.disconnect();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<style scoped>
|
|
52
|
+
.infinite-scroll-container {
|
|
53
|
+
width: 100%;
|
|
54
|
+
}
|
|
55
|
+
.sentinel {
|
|
56
|
+
height: var(--infinite-scroll-sentinel-height, 1px);
|
|
57
|
+
width: 100%;
|
|
58
|
+
}
|
|
59
|
+
</style>
|
package/src/index.js
CHANGED
|
@@ -29,3 +29,4 @@ export { default as SkullIcon } from './Icons/SkullIcon/SkullIcon.vue'
|
|
|
29
29
|
export { default as CalendarIcon } from './Icons/CalendarIcon/CalendarIcon.vue'
|
|
30
30
|
export { default as SaveIcon } from './Icons/SaveIcon/SaveIcon.vue'
|
|
31
31
|
export { default as CreateIcon } from './Icons/CreateIcon/CreateIcon.vue'
|
|
32
|
+
export { default as InfiniteScroll } from './InfiniteScroll/InfiniteScroll.vue'
|
package/styles/index.css
CHANGED