Skip to content

Commit efdf247

Browse files
authored
Merge pull request #49 from oumoussa98/demo
update(demo): add multiple components on the same page example
2 parents a2d5b7d + 5bae5b6 commit efdf247

File tree

2 files changed

+103
-7
lines changed

2 files changed

+103
-7
lines changed

demo/src/App.vue

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { ref, nextTick } from "vue";
33
import Top from "./components/Top.vue";
44
import Bottom from "./components/Bottom.vue";
55
import Checkbox from "./components/Checkbox.vue";
6+
import ScopedLoader from "./components/ScopedLoader.vue";
7+
8+
const counts = [20, 50, 100, 120, 150, 200, 250, 300, 350, 400, 450, 500];
9+
const showLoaders = ref(false);
10+
const displayMessage = ref("Display");
611
let page = 0;
712
let mount = ref(true);
813
let resetData = ref(false);
@@ -11,6 +16,11 @@ let distance = ref(0);
1116
let top = ref(false);
1217
let comments = ref([]);
1318
let mountname = ref("Unmount");
19+
20+
const displayMultipleLoader = () => {
21+
showLoaders.value = !showLoaders.value;
22+
displayMessage.value = showLoaders.value ? "Hide" : "Display";
23+
};
1424
const refresh = () => {
1525
page = 0;
1626
comments.value.length = 0;
@@ -113,15 +123,15 @@ const load = async $state => {
113123
</span>
114124
<span class="buttons">
115125
<button
116-
class="btn-mount"
126+
class="btn btn-mount"
117127
@click="mountToggler"
118128
>{{ mountname }}</button>
119129
<button
120130
class="btn-refresh"
121131
@click="refresh"
122132
>Refresh</button>
123133
<button
124-
class="btn-reset"
134+
class="btn btn-reset"
125135
@click="reset"
126136
>Reset</button>
127137
</span>
@@ -144,18 +154,38 @@ const load = async $state => {
144154
@infinite="load"
145155
/>
146156
</div>
157+
<button
158+
class="btn btn-show-loaders"
159+
@click="displayMultipleLoader"
160+
>
161+
{{ displayMessage }} multiple infinites
162+
</button>
163+
<div
164+
v-if="showLoaders"
165+
class="loaders"
166+
>
167+
<ScopedLoader
168+
v-for="i in counts"
169+
:key="i"
170+
:count="i"
171+
class="results"
172+
/>
173+
</div>
147174
</template>
148175

149176
<style>
150177
* {
151178
box-sizing: border-box;
152179
}
180+
153181
body {
154182
background-color: #272727;
155183
font-family: system-ui, -apple-system;
156184
font-weight: 400;
157185
font-size: 15px;
186+
overflow-y: scroll;
158187
}
188+
159189
#app {
160190
color: #e9e9e9;
161191
max-width: 1500px;
@@ -168,6 +198,7 @@ body {
168198
gap: 10px;
169199
text-align: center;
170200
}
201+
171202
.settings {
172203
position: relative;
173204
display: flex;
@@ -184,16 +215,19 @@ body {
184215
border-radius: 10px;
185216
padding: 10px;
186217
}
218+
187219
.settings a {
188220
position: absolute;
189221
top: 4px;
190222
right: 5px;
191223
}
224+
192225
.props {
193226
display: flex;
194227
gap: 20px;
195228
flex-wrap: wrap;
196229
}
230+
197231
.distance {
198232
width: 50px;
199233
border-radius: 5px;
@@ -203,11 +237,13 @@ body {
203237
background: #6a6c6d;
204238
color: inherit;
205239
}
240+
206241
.buttons {
207242
display: flex;
208243
gap: 20px;
209244
flex-wrap: wrap;
210245
}
246+
211247
.btn-refresh {
212248
width: 100px;
213249
font-family: inherit;
@@ -220,8 +256,8 @@ body {
220256
text-decoration: none;
221257
outline: none;
222258
}
223-
.btn-reset,
224-
.btn-mount {
259+
260+
.btn {
225261
width: 90px;
226262
font-family: inherit;
227263
color: white;
@@ -232,12 +268,21 @@ body {
232268
text-decoration: none;
233269
outline: none;
234270
}
271+
235272
.btn-reset {
236273
background: #e45252;
237274
}
275+
238276
.btn-mount {
239277
background: #5268e4;
240278
}
279+
280+
.btn-show-loaders {
281+
background: #5268e4;
282+
width: 180px;
283+
height: 30px;
284+
}
285+
241286
.result {
242287
display: flex;
243288
flex-direction: column;
@@ -252,19 +297,37 @@ body {
252297
background: #101011;
253298
border-radius: 10px;
254299
}
300+
255301
.loader {
256302
padding: 10px;
257303
}
258-
.results::-webkit-scrollbar-track {
304+
305+
.loaders {
306+
display: flex;
307+
flex-wrap: wrap;
308+
justify-content: center;
309+
gap: 1rem;
310+
}
311+
312+
.loaders > .results {
313+
width: 300px;
314+
height: 300px;
315+
background: #333536;
316+
overflow-y: scroll;
317+
}
318+
319+
::-webkit-scrollbar-track {
259320
border-radius: 4px;
260321
background: #333536;
261322
}
262-
.results::-webkit-scrollbar {
323+
324+
::-webkit-scrollbar {
263325
border-radius: 4px;
264326
width: 8px;
265327
background: #7e7e7e;
266328
}
267-
.results::-webkit-scrollbar-thumb {
329+
330+
::-webkit-scrollbar-thumb {
268331
border-radius: 4px;
269332
background: #7e7e7e;
270333
}

demo/src/components/ScopedLoader.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<script setup>
2+
import { ref } from "vue";
3+
import Bottom from "./Bottom.vue";
4+
5+
let { count } = defineProps({ count: { type: Number, default: 20 } })
6+
const comments = ref([]);
7+
let page = 0;
8+
9+
const load = async $state => {
10+
page++;
11+
try {
12+
const response = await fetch(
13+
"https://jsonplaceholder.typicode.com/comments?_limit=5&_page=" + page
14+
);
15+
const json = await response.json();
16+
if (json.length < 5 || comments.value.length > count) $state.complete();
17+
else {
18+
comments.value.push(...json);
19+
$state.loaded();
20+
}
21+
} catch (error) {
22+
$state.error();
23+
}
24+
};
25+
</script>
26+
27+
<template>
28+
<Bottom
29+
:comments="comments"
30+
class="scoped-loader"
31+
@infinite="load"
32+
/>
33+
</template>

0 commit comments

Comments
 (0)