Composite
NavigationTree
Recursive navigation component with collapsible tree structure.
Basic navigation
A flat list with no nesting.
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
},
{
label: 'Components',
href: '/documentation/components',
},
{
label: 'About',
href: '/about',
},
];
---
<div class="max-w-xs">
<NavigationTreeBlock items={items} />
</div>Expansion strategies
Always expanded
All children visible at all times.
Documentation
Base
Resources
Community
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock items={items} expansionStrategy="always" />
</div>Active only (default)
Only shows children of active items.
Documentation
Base
Resources
Community
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock
items={items}
expansionStrategy="active-only"
currentPath="/documentation/composite/Content"
/>
</div>First level only
Shows only root-level items, no children.
Documentation
Base
Resources
Community
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock items={items} expansionStrategy="first-level" />
</div>Depth limited (maxDepth={1})
Expands children up to the specified depth.
Documentation
Base
Resources
Community
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock items={items} expansionStrategy="depth" maxDepth={1} />
</div>Toggleable (interactive)
Click parent items to expand or collapse children. The active path is expanded automatically.
Documentation
Base
Resources
Community
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock
items={items}
expansionStrategy="toggleable"
currentPath="/documentation/composite/NavigationTree"
/>
</div>Toggle modes
Button toggle (default, mobile-friendly)
The entire button toggles children. Good for touch devices with larger tap targets.
Documentation
Base
Resources
Community
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock
items={items}
expansionStrategy="toggleable"
toggleMode="button"
currentPath="/documentation/composite/ItemsGrid"
/>
</div>Icon toggle only
Only the icon toggles children; the button navigates to its href. This provides separate controls for navigation and expansion.
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Documentation',
href: '/documentation',
children: [
{
label: 'Base',
href: '/documentation/base',
children: [
{ label: 'Colors', href: '/documentation/base/Colors' },
{ label: 'Typography', href: '/documentation/base/Typography' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [
{ label: 'CallToAction', href: '/documentation/composite/CallToAction' },
{ label: 'Content', href: '/documentation/composite/Content' },
{ label: 'ItemsContent', href: '/documentation/composite/ItemsContent' },
{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' },
],
},
{
label: 'Primitives',
href: '/documentation/primitives',
children: [
{ label: 'Button', href: '/documentation/primitives/Button' },
{ label: 'Headline', href: '/documentation/primitives/Headline' },
{ label: 'Image', href: '/documentation/primitives/Image' },
],
},
],
},
{
label: 'Resources',
href: '/resources',
children: [
{
label: 'Guides',
href: '/resources/guides',
children: [
{ label: 'Quick Start', href: '/resources/guides/quick-start' },
{ label: 'Best Practices', href: '/resources/guides/best-practices' },
{ label: 'Migration Guide', href: '/resources/guides/migration' },
],
},
{
label: 'Examples',
href: '/resources/examples',
children: [
{ label: 'Dashboard', href: '/resources/examples/dashboard' },
{ label: 'Landing Page', href: '/resources/examples/landing' },
{ label: 'Blog', href: '/resources/examples/blog' },
],
},
],
},
{
label: 'Community',
href: '/community',
children: [
{
label: 'Forum',
href: '/community/forum',
children: [
{ label: 'General Discussion', href: '/community/forum/general' },
{ label: 'Help & Support', href: '/community/forum/support' },
{ label: 'Showcase', href: '/community/forum/showcase' },
],
},
{ label: 'GitHub', href: 'https://github.com' },
{ label: 'Discord', href: 'https://discord.com' },
],
},
{
label: 'About',
href: '/about',
children: [
{ label: 'Team', href: '/about/team' },
{ label: 'Changelog', href: '/about/changelog' },
{ label: 'License', href: '/about/license' },
],
},
];
---
<div class="max-w-md">
<NavigationTreeBlock
items={items}
expansionStrategy="toggleable"
toggleMode="icon"
currentPath="/documentation/composite/ItemsGrid"
/>
</div>Custom configuration
Custom icons
Getting Started
Composite
Layout
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
children: [
{ label: 'Installation', href: '/documentation/installation' },
{ label: 'Configuration', href: '/documentation/configuration' },
{ label: 'Quick Start', href: '/documentation/quick-start' },
],
},
{
label: 'Components',
href: '/documentation/components',
children: [
{ label: 'Buttons', href: '/documentation/components/buttons' },
{ label: 'Forms', href: '/documentation/components/forms' },
{ label: 'Cards', href: '/documentation/components/cards' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' }],
},
{
label: 'Layout',
href: '/documentation/layout',
children: [
{ label: 'Grid System', href: '/documentation/layout/grid' },
{ label: 'Containers', href: '/documentation/layout/containers' },
],
},
];
---
<div class="max-w-xs">
<NavigationTreeBlock
items={items}
expansionStrategy="always"
iconName="heroicons:chevron-right"
rotateIconOnExpand={true}
/>
</div>Custom button styling
Getting Started
Composite
Layout
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
children: [
{ label: 'Installation', href: '/documentation/installation' },
{ label: 'Configuration', href: '/documentation/configuration' },
{ label: 'Quick Start', href: '/documentation/quick-start' },
],
},
{
label: 'Components',
href: '/documentation/components',
children: [
{ label: 'Buttons', href: '/documentation/components/buttons' },
{ label: 'Forms', href: '/documentation/components/forms' },
{ label: 'Cards', href: '/documentation/components/cards' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' }],
},
{
label: 'Layout',
href: '/documentation/layout',
children: [
{ label: 'Grid System', href: '/documentation/layout/grid' },
{ label: 'Containers', href: '/documentation/layout/containers' },
],
},
];
---
<div class="max-w-xs">
<NavigationTreeBlock
items={items}
expansionStrategy="always"
inactiveItemConfig={{
variant: 'outline',
intent: 'tertiary',
size: 'sm',
width: 'full',
}}
activeItemConfig={{
variant: 'solid',
intent: 'accent',
size: 'sm',
width: 'full',
}}
/>
</div>Default item styling
Default-config class and icon reach every item.
defaultItemConfig reaches every item; inactiveItemConfig / activeItemConfig layer on top.
Parents keep the iconName chevron over the default icon.
Getting Started
Composite
Layout
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
children: [
{ label: 'Installation', href: '/documentation/installation' },
{ label: 'Configuration', href: '/documentation/configuration' },
{ label: 'Quick Start', href: '/documentation/quick-start' },
],
},
{
label: 'Components',
href: '/documentation/components',
children: [
{ label: 'Buttons', href: '/documentation/components/buttons' },
{ label: 'Forms', href: '/documentation/components/forms' },
{ label: 'Cards', href: '/documentation/components/cards' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' }],
},
{
label: 'Layout',
href: '/documentation/layout',
children: [
{ label: 'Grid System', href: '/documentation/layout/grid' },
{ label: 'Containers', href: '/documentation/layout/containers' },
],
},
];
---
<div class="max-w-xs">
<NavigationTreeBlock
items={items}
currentPath="/documentation/composite/NavigationTree"
expansionStrategy="always"
defaultItemConfig={{ class: 'tracking-wide', icon: { name: 'mdi:circle-small' } }}
activeItemConfig={{ class: 'underline' }}
/>
</div>Active item weight
The active item is semi-bold by default. activeItemConfig.class can change its weight.
Getting Started
Composite
Layout
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
children: [
{ label: 'Installation', href: '/documentation/installation' },
{ label: 'Configuration', href: '/documentation/configuration' },
{ label: 'Quick Start', href: '/documentation/quick-start' },
],
},
{
label: 'Components',
href: '/documentation/components',
children: [
{ label: 'Buttons', href: '/documentation/components/buttons' },
{ label: 'Forms', href: '/documentation/components/forms' },
{ label: 'Cards', href: '/documentation/components/cards' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' }],
},
{
label: 'Layout',
href: '/documentation/layout',
children: [
{ label: 'Grid System', href: '/documentation/layout/grid' },
{ label: 'Containers', href: '/documentation/layout/containers' },
],
},
];
---
<div class="max-w-xs">
<NavigationTreeBlock
items={items}
currentPath="/documentation/composite/NavigationTree"
expansionStrategy="always"
activeItemConfig={{ class: 'font-normal' }}
/>
</div>Children wrapper
childrenClass styles the wrapper around every level of children, here a guide line as in a docs sidebar.
Getting Started
Composite
Layout
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
children: [
{ label: 'Installation', href: '/documentation/installation' },
{ label: 'Configuration', href: '/documentation/configuration' },
{ label: 'Quick Start', href: '/documentation/quick-start' },
],
},
{
label: 'Components',
href: '/documentation/components',
children: [
{ label: 'Buttons', href: '/documentation/components/buttons' },
{ label: 'Forms', href: '/documentation/components/forms' },
{ label: 'Cards', href: '/documentation/components/cards' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' }],
},
{
label: 'Layout',
href: '/documentation/layout',
children: [
{ label: 'Grid System', href: '/documentation/layout/grid' },
{ label: 'Containers', href: '/documentation/layout/containers' },
],
},
];
---
<div class="max-w-xs">
<NavigationTreeBlock
items={items}
currentPath="/documentation/composite/NavigationTree"
expansionStrategy="always"
childrenClass="ml-3 pl-2 border-l border-border"
defaultItemConfig={{ size: 'sm' }}
/>
</div>Current path detection
Without currentPath, the tree matches against the page URL.
Current path: /documentation/composite/NavigationTree
Getting Started
Composite
Layout
---
import NavigationTreeBlock from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const items: NavigationTreeItem[] = [
{
label: 'Getting Started',
href: '/documentation',
children: [
{ label: 'Installation', href: '/documentation/installation' },
{ label: 'Configuration', href: '/documentation/configuration' },
{ label: 'Quick Start', href: '/documentation/quick-start' },
],
},
{
label: 'Components',
href: '/documentation/components',
children: [
{ label: 'Buttons', href: '/documentation/components/buttons' },
{ label: 'Forms', href: '/documentation/components/forms' },
{ label: 'Cards', href: '/documentation/components/cards' },
],
},
{
label: 'Composite',
href: '/documentation/composite',
children: [{ label: 'NavigationTree', href: '/documentation/composite/NavigationTree' }],
},
{
label: 'Layout',
href: '/documentation/layout',
children: [
{ label: 'Grid System', href: '/documentation/layout/grid' },
{ label: 'Containers', href: '/documentation/layout/containers' },
],
},
];
---
<div class="max-w-xs space-y-4">
<p>
Current path: <code>{Astro.url.pathname}</code>
</p>
<NavigationTreeBlock items={items} expansionStrategy="active-only" />
</div>The active link carries aria-current="page"; a parent rendered as a <summary> toggle keeps the active look without it.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| items | NavigationTreeItem[] | — | The list of navigation items to render, each a ButtonProps optionally with nested `children` for sub-trees. |
| currentPath | string | Astro.url.pathname | The path used to determine which item is active (default: `Astro.url.pathname`). |
| level | number | 0 | The current nesting depth, compared against `maxDepth` and passed down to sub-trees (default: `0`). |
| class | string | '' | Additional CSS class(es) applied to the root `<nav>` element (default: `''`). |
| childrenClass | string | — | Classes merged onto the wrapper around each item's children, at every depth (default: `'pl-4'`). |
| iconName | string | 'mdi:chevron-right' | The icon name shown on items that have children (default: `'mdi:chevron-right'`). |
| rotateIconOnExpand | boolean | true | Whether the expand icon rotates when its item is expanded (default: `true`). |
| toggleMode | ToggleMode | 'button' | Whether clicking the whole button or only the icon toggles children; in 'button' mode a parent renders as the `<summary>` of a native `<details>` and its `href` is ignored (default: `'button'`). |
| defaultItemConfig | LayerConfig<Omit<ButtonProps, 'as'>> | — | Button config merged into every item, in every state, under the state layers. |
| inactiveItemConfig | LayerConfig<Omit<ButtonProps, 'as'>> | — | Button config merged over `defaultItemConfig` on non-active items. |
| activeItemConfig | LayerConfig<Omit<ButtonProps, 'as'>> | — | Button config merged over `defaultItemConfig` on the active item; the active item also gets `aria-current="page"` when it renders as a link, which this layer or the item can override. |
| expansionStrategy | ExpansionStrategy | 'active-only' | The strategy that decides whether an item's children are shown (default: `'active-only'`). |
| maxDepth | number | Infinity | The maximum depth expanded when `expansionStrategy` is `'depth'` (default: `Infinity`). |