Skip to content

Commit 48c5dc6

Browse files
committed
Make the demo page better.
Moved the item renderer into a snippet.
1 parent f8cf7d6 commit 48c5dc6

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/routes/+page.svelte

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
let dynamicList2: DynamicList;
2121
</script>
2222

23+
{#snippet itemRenderer(item: number | string)}
24+
{#if typeof item == 'number'}
25+
This is item #{item}
26+
{:else}
27+
<b>{item}</b>
28+
{/if}
29+
{/snippet}
30+
2331
<h1>Casterlabs UI Test Page</h1>
2432

2533
Page Zoom:
@@ -167,11 +175,9 @@ Is at bottom?
167175
<Box style="flex: 1; height: 100%; padding: 0;" sides={['top', 'bottom', 'left', 'right']}>
168176
<InvertedScroller bind:this={scroller} bind:isAtBottom={isScrollerAtBottom}>
169177
<ul>
170-
<li><b>(end of list)</b></li>
171-
{#each Array(SCROLL_ITEMS) as _, idx}
172-
<li>Item {idx + 1}</li>
178+
{#each ['(start of list)', ...Array(100).keys(), 'This is an InvertedScroller (in a Box)'] as item}
179+
<li>{@render itemRenderer(item)}</li>
173180
{/each}
174-
<li><b>This is an InvertedScroller (in a Box)</b></li>
175181
</ul>
176182
</InvertedScroller>
177183
</Box>
@@ -180,11 +186,9 @@ Is at bottom?
180186
sides={['top', 'bottom', 'right']}
181187
>
182188
<ul>
183-
<li><b>This is a regular scrollable div (in a Box)</b></li>
184-
{#each Array(SCROLL_ITEMS) as _, idx}
185-
<li>Item {idx + 1}</li>
189+
{#each ['This is a regular scrollable div (in a Box)', ...Array(100).keys(), '(end of list)'] as item}
190+
<li>{@render itemRenderer(item)}</li>
186191
{/each}
187-
<li><b>(end of list)</b></li>
188192
</ul>
189193
</Box>
190194
</div>
@@ -229,16 +233,20 @@ Is at bottom?
229233
<Box style="flex: 1; height: 100%; padding: 0;" sides={['top', 'bottom', 'left', 'right']}>
230234
<DynamicList
231235
bind:this={dynamicList1}
232-
startWith={['This is an regular DynamicList (in a Box)', ...Array(1_000).keys()]}
236+
startWith={[
237+
'This is an regular DynamicList (in a Box)',
238+
...Array(1_000).keys(),
239+
'(end of list)'
240+
]}
233241
bleed={dynamicListBleed / 100}
242+
{itemRenderer}
234243
>
235-
{#snippet itemRenderer(item: number | string)}
236-
{#if typeof item == 'number'}
237-
This is item #{item}
238-
{:else}
239-
<b>{item}</b>
240-
{/if}
241-
{/snippet}
244+
<!--
245+
You can also:
246+
{#snippet itemRenderer(item: any)}
247+
...
248+
{/snippet}
249+
-->
242250
</DynamicList>
243251
</Box>
244252
<Box
@@ -248,17 +256,14 @@ Is at bottom?
248256
<DynamicList
249257
bind:this={dynamicList2}
250258
inverted
251-
startWith={[...Array(1_000).keys(), 'This is an inverted DynamicList (in a Box)']}
259+
startWith={[
260+
'(start of list)',
261+
...Array(1_000).keys(),
262+
'This is an inverted DynamicList (in a Box)'
263+
]}
252264
bleed={dynamicListBleed / 100}
253-
>
254-
{#snippet itemRenderer(item: number | string)}
255-
{#if typeof item == 'number'}
256-
This is item #{item}
257-
{:else}
258-
<b>{item}</b>
259-
{/if}
260-
{/snippet}
261-
</DynamicList>
265+
{itemRenderer}
266+
/>
262267
</Box>
263268
{/key}
264269
</div>

0 commit comments

Comments
 (0)