This is definitely not perfect, but it's what I've been using in my svelte kit project, I thought it'd be nice to add something like it to the recipes.
// SideNavLinks.svelte
<script context="module" lang="ts">
export type SideNavLinkType = {
icon?: any
href?: string
text?: string
links?: SideNavLinkType[]
isDivider?: boolean
}
</script>
<script lang="ts">
import { SideNavDivider, SideNavLink, SideNavMenu } from 'carbon-components-svelte'
export let links: SideNavLinkType[]
export let currentPage: string
</script>
{#each links as link}
{#if link.isDivider}
<SideNavDivider />
{:else if link.links}
<SideNavMenu text={link.text}>
<svelte:self {...link} {currentPage} />
</SideNavMenu>
{:else}
<SideNavLink {...link} isSelected={currentPage === link.href} />
{/if}
{/each}
This is definitely not perfect, but it's what I've been using in my svelte kit project, I thought it'd be nice to add something like it to the recipes.
Example with Svelte Kit