Skip to content

Commit bf5d460

Browse files
author
abdelouahed oumoussa
committed
update(demo): add multiple components on the same page example
1 parent a2d5b7d commit bf5d460

File tree

2 files changed

+102
-7
lines changed

2 files changed

+102
-7
lines changed

demo/src/App.vue

Lines changed: 69 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,37 @@ 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;
158186
}
187+
159188
#app {
160189
color: #e9e9e9;
161190
max-width: 1500px;
@@ -168,6 +197,7 @@ body {
168197
gap: 10px;
169198
text-align: center;
170199
}
200+
171201
.settings {
172202
position: relative;
173203
display: flex;
@@ -184,16 +214,19 @@ body {
184214
border-radius: 10px;
185215
padding: 10px;
186216
}
217+
187218
.settings a {
188219
position: absolute;
189220
top: 4px;
190221
right: 5px;
191222
}
223+
192224
.props {
193225
display: flex;
194226
gap: 20px;
195227
flex-wrap: wrap;
196228
}
229+
197230
.distance {
198231
width: 50px;
199232
border-radius: 5px;
@@ -203,11 +236,13 @@ body {
203236
background: #6a6c6d;
204237
color: inherit;
205238
}
239+
206240
.buttons {
207241
display: flex;
208242
gap: 20px;
209243
flex-wrap: wrap;
210244
}
245+
211246
.btn-refresh {
212247
width: 100px;
213248
font-family: inherit;
@@ -220,8 +255,8 @@ body {
220255
text-decoration: none;
221256
outline: none;
222257
}
223-
.btn-reset,
224-
.btn-mount {
258+
259+
.btn {
225260
width: 90px;
226261
font-family: inherit;
227262
color: white;
@@ -232,12 +267,21 @@ body {
232267
text-decoration: none;
233268
outline: none;
234269
}
270+
235271
.btn-reset {
236272
background: #e45252;
237273
}
274+
238275
.btn-mount {
239276
background: #5268e4;
240277
}
278+
279+
.btn-show-loaders {
280+
background: #5268e4;
281+
width: 180px;
282+
height: 30px;
283+
}
284+
241285
.result {
242286
display: flex;
243287
flex-direction: column;
@@ -252,19 +296,37 @@ body {
252296
background: #101011;
253297
border-radius: 10px;
254298
}
299+
255300
.loader {
256301
padding: 10px;
257302
}
258-
.results::-webkit-scrollbar-track {
303+
304+
.loaders {
305+
display: flex;
306+
flex-wrap: wrap;
307+
justify-content: center;
308+
gap: 1rem;
309+
}
310+
311+
.loaders > .results {
312+
width: 300px;
313+
height: 300px;
314+
background: #333536;
315+
overflow-y: scroll;
316+
}
317+
318+
::-webkit-scrollbar-track {
259319
border-radius: 4px;
260320
background: #333536;
261321
}
262-
.results::-webkit-scrollbar {
322+
323+
::-webkit-scrollbar {
263324
border-radius: 4px;
264325
width: 8px;
265326
background: #7e7e7e;
266327
}
267-
.results::-webkit-scrollbar-thumb {
328+
329+
::-webkit-scrollbar-thumb {
268330
border-radius: 4px;
269331
background: #7e7e7e;
270332
}
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)