<!--
@component
Renders `items` as a list, each through the `item` snippet, with an
optional fallback when the list is empty.
-->
<script lang="ts" generics="T">
// the `generics` attribute surfaces as the component's `genericParams`
import type { Snippet } from 'svelte';
const {
items,
item,
empty
}: {
/** Items to render, in order. */
items: ReadonlyArray<T>;
/** Renders one item, receiving it and its index. */
item: Snippet<[item: T, index: number]>;
/** Rendered in place of the list when `items` is empty. */
empty?: Snippet;
} = $props();
</script>
{#if items.length}
<ul>
{#each items as value, index}
<li>{@render item(value, index)}</li>
{/each}
</ul>
{:else}
{@render empty?.()}
{/if}
{
"path": "List.svelte",
"declarations": [
{
"name": "List",
"kind": "component",
"docComment": "Renders `items` as a list, each through the `item` snippet, with an\noptional fallback when the list is empty.",
"sourceLine": 7,
"genericParams": [
{
"name": "T"
}
],
"props": [
{
"name": "items",
"type": "readonly T[]",
"description": "Items to render, in order."
},
{
"name": "item",
"type": "Snippet<[item: T, index: number]>",
"typeInfo": {
"kind": "reference",
"name": "Snippet",
"typeArgs": [
{
"kind": "tuple",
"elements": [
{
"name": "item",
"type": {
"kind": "other",
"text": "T"
}
},
{
"name": "index",
"type": {
"kind": "intrinsic",
"text": "number"
}
}
]
}
]
},
"description": "Renders one item, receiving it and its index.",
"parameters": [
{
"name": "item",
"type": "T"
},
{
"name": "index",
"type": "number"
}
]
},
{
"name": "empty",
"type": "Snippet<[]>",
"optional": true,
"description": "Rendered in place of the list when `items` is empty."
}
]
}
],
"dependents": [
"index.ts"
]
}