Skip to content

Commit

Permalink
feat(list): adds custom empty snippet support for sections
Browse files Browse the repository at this point in the history
  • Loading branch information
dvcol committed Feb 11, 2025
1 parent a3ec707 commit d60fe7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lib/list/NeoList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
type NeoListMethods,
type NeoListProps,
type NeoListRenderContext,
type NeoListSection,
type NeoListSelectedItem,
type NeoListSelectEvent,
showDivider,
Expand Down Expand Up @@ -297,9 +298,9 @@
</li>
{/snippet}

{#snippet emptyItem()}
{#if customEmpty}
{@render customEmpty(context)}
{#snippet emptyItem(itemEmpty: NeoListSection['empty'] = customEmpty)}
{#if itemEmpty}
{@render itemEmpty(context)}
{:else}
<div class="neo-list-empty-content">
<IconList size="3rem" stroke="1" />
Expand All @@ -314,7 +315,7 @@
.filter(({ item }) => filter(item))
.sort((a, b) => sort(a.item, b.item))}
{#if !visible?.length}
{@render emptyItem()}
{@render emptyItem(section?.empty)}
{:else}
<!-- Items -->
{#each visible as { item, index } (item.id ?? index)}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/list/neo-list.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export type NeoListSection<Value = unknown, Tag extends keyof HTMLElementTagName
* @param context - The list section context.
*/
render?: NeoListSectionRender<Value>;
/**
* Optional snippet to display when the section is empty.
*/
empty?: Snippet<[NeoListContext]>;
/**
* Optional props to pass to the section container.
*/
Expand Down

0 comments on commit d60fe7b

Please sign in to comment.