A flexible navigation component for creating horizontal or vertical navigation menus. Supports active states, badges, disabled items, and different emphasis styles for various layout needs.
The primary navigation style with prominent active state indicators and full-width styling.
<script lang="ts">
import Navigation, { type NavigationItem } from "@pindoba/svelte-navigation";
import { stack } from "@pindoba/styled-system/patterns";
import { createRawSnippet } from "svelte";
const customSnippet = createRawSnippet(() => ({
render: () => "🔥 Hot",
setup: () => {},
}));
const items: NavigationItem[] = [
{
label: "Home",
href: "#",
},
{
label: "Products",
href: "#",
badge: {
label: "Hot", // String label
emphasis: "primary",
children: "New",
},
},
{
label: "Special",
href: "#",
badge: {
label: customSnippet, // Custom snippet
emphasis: "secondary",
feedback: "success",
},
},
{
label: "Disabled",
href: "#",
disabled: true,
},
{
label: "logout",
href: "#",
},
];
</script>
<div
class={stack({
gap: "md",
direction: "column",
justify: "center",
flexWrap: "wrap",
})}
>
<Navigation {items} activeItem="Home" />
<Navigation {items} activeItem="Home" bordered />
<Navigation {items} direction="vertical" activeItem="Home" />
</div>The neutral navigation style with subtle styling, perfect for secondary navigation or sidebar menus.
<script lang="ts">
import Navigation, { type NavigationItem } from "@pindoba/svelte-navigation";
import { stack } from "@pindoba/styled-system/patterns";
import { createRawSnippet } from "svelte";
// Create a snippet for a custom badge label
const customSnippet = createRawSnippet(() => ({
render: () => "🔥 Hot",
setup: () => {},
}));
const items: NavigationItem[] = [
{
label: "Home",
href: "#",
},
{
label: "Products",
href: "#",
badge: {
label: "Hot", // String label
children: "New",
emphasis: "primary",
},
},
{
label: "Special",
href: "#",
badge: {
label: customSnippet, // Custom snippet
emphasis: "secondary",
feedback: "success",
},
},
{
label: "Disabled",
href: "#",
disabled: true,
},
{
label: "logout",
href: "#",
},
];
</script>
<div
class={stack({
gap: "md",
direction: "column",
justify: "center",
flexWrap: "wrap",
})}
>
<Navigation {items} emphasis="neutral" activeItem="Home" />
<Navigation {items} emphasis="neutral" activeItem="Home" bordered />
<Navigation
{items}
direction="vertical"
emphasis="neutral"
activeItem="Special"
/>
</div>Badges scale with the navigation size — each size maps to a smaller badge font-size token.
<script lang="ts">
import Navigation, { type NavigationItem } from "@pindoba/svelte-navigation";
import { stack } from "@pindoba/styled-system/patterns";
const items: NavigationItem[] = [
{ label: "Home", href: "#" },
{
label: "Inbox",
href: "#",
badge: { children: "12", emphasis: "primary", feedback: "primary" },
},
{
label: "Drafts",
href: "#",
badge: { children: "3", emphasis: "secondary", feedback: "neutral" },
},
{ label: "Sent", href: "#" },
];
</script>
<div class={stack({ gap: "xl", direction: "column" })}>
<div>
<h3>xs</h3>
<Navigation {items} activeItem="Inbox" size="xs" />
</div>
<div>
<h3>sm</h3>
<Navigation {items} activeItem="Inbox" size="sm" />
</div>
<div>
<h3>md</h3>
<Navigation {items} activeItem="Inbox" size="md" />
</div>
<div>
<h3>lg</h3>
<Navigation {items} activeItem="Inbox" size="lg" />
</div>
</div>| Prop | |
|---|---|
items | items Array of navigation items to display Type Default Required |
emphasis | emphasis Visual emphasis level for the navigation Type Default Required |
direction | direction Layout direction for the navigation Type Default Required |
activeItem | activeItem ID or label of the currently active navigation item Type Default Required |
bordered | bordered Whether to show borders around the navigation Type Default Required |
passThrough | passThrough Custom styling and props for navigation elements Type Default Required |
...rest | ...rest Standard HTML nav element attributes Type Default Required |
| Prop | |
|---|---|
label | label Display text for the navigation item Type Default Required |
id | id Unique identifier for the navigation item Type Default Required |
href | href URL for the navigation link Type Default Required |
onClick | onClick Click handler function for the navigation item Type Default Required |
badge | badge Badge configuration or simple string to display next to the item Type Default Required |
disabled | disabled Whether the navigation item is disabled Type Default Required |