Sidebar
A composable, themeable and customizable sidebar component.
Installation
npx nx g @spartan-ng/cli:ui sidebar
ng g @spartan-ng/cli:ui sidebar
Add the following colors to your CSS file
The command above should install the colors for you. If not, copy and paste the following in your CSS file.
We'll go over the colors later in the theming section.
@layer base {
:root {
--sidebar: 300 0% 98%;
--sidebar-foreground: 300 0% 4%;
--sidebar-primary: 330 0% 9%;
--sidebar-primary-foreground: 300 0% 98%;
--sidebar-accent: 300 0% 96%;
--sidebar-accent-foreground: 330 0% 9%;
--sidebar-border: 330 0% 90%;
--sidebar-ring: 0 0% 63%;
}
.dark {
--sidebar: 300 0% 98%;
--sidebar-foreground: 300 0% 4%;
--sidebar-primary: 330 0% 9%;
--sidebar-primary-foreground: 300 0% 98%;
--sidebar-accent: 300 0% 96%;
--sidebar-accent-foreground: 330 0% 9%;
--sidebar-border: 330 0% 90%;
--sidebar-ring: 0 0% 63%;
}
}
Structure
- HlmSidebarService - Handles collapsible state.
- HlmSidebar - The sidebar container.
- HlmSidebarHeader and HlmSidebarFooter - Sticky at the top and bottom of the sidebar.
- HlmSidebarContent - Scrollable content.
- HlmSidebarGroup - Section within the HlmSidebarContent .
- HlmSidebarTrigger - Trigger for the HlmSidebar .

Usage
import { Component } from '@angular/core';
import { AppSidebar } from './app-sidebar';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
imports: [AppSidebar, HlmSidebarImports],
selector: 'app-root',
template: `<app-sidebar>
<main>
<button hlmSidebarTrigger><span class="sr-only"></span></button>
</main>
</app-sidebar>`,
})
export class App {}
import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [
HlmSidebarImports,
],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarHeader></div>
<div hlmSidebarContent>
<div hlmSidebarGroup></div>
<div hlmSidebarGroup></div>
</div>
<div hlmSidebarFooter></div>
</hlm-sidebar>
<ng-content />
</div>
`,
})
export class AppSidebar {}
Your First Sidebar
Let's start with the most basic sidebar. A collapsible sidebar with a menu.
Add a HlmSidebarTrigger at the root of your application.
import { Component } from '@angular/core';
import { AppSidebar } from './app-sidebar';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { RouterOutlet } from '@angular/router';
@Component({
imports: [AppSidebar, HlmSidebarImports, RouterOutlet],
selector: 'app-root',
template: `<app-sidebar>
<main hlmSidebarInset>
<header class="flex h-12 items-center justify-between px-4">
<button hlmSidebarTrigger><span class="sr-only"></span></button>
<router-outlet/>
</header>
</main>
</app-sidebar>`,
})
export class App {}
Create a new sidebar component at src/app/app-sidebar.ts
import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent></div>
</hlm-sidebar>
<ng-content />
</div>
`,
})
export class AppSidebar {}
Now, let's add a HlmSidebarMenu to the sidebar.
We'll use the HlmSidebarMenu component in a HlmSidebarGroup .
import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { lucideCalendar, lucideHouse, lucideInbox, lucideSearch, lucideSettings } from '@ng-icons/lucide';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { HlmIcon } from '@spartan-ng/helm/icon';
@Component({
selector: 'app-sidebar',
imports: [
HlmSidebarImports,
NgIcon,
HlmIcon,
],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupLabel>Application</div>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
@for(item of _items; track item.title){
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton>
<ng-icon hlm [name]="item.icon" />
<span>{{ item.title }}</span>
</a>
</li>
}
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideHouse,
lucideInbox,
lucideCalendar,
lucideSearch,
lucideSettings,
}),
],
})
export class AppSidebar {
protected readonly _items = [
{
title: 'Home',
url: '#',
icon: 'lucideHouse',
},
{
title: 'Inbox',
url: '#',
icon: 'lucideInbox',
},
{
title: 'Calendar',
url: '#',
icon: 'lucideCalendar',
},
{
title: 'Search',
url: '#',
icon: 'lucideSearch',
},
{
title: 'Settings',
url: '#',
icon: 'lucideSettings',
},
];
}
You've created your first sidebar.
You should see something like this:

SidebarService
The HlmSidebarService manages the state, persistence, and responsive behavior of the sidebar. It ensures the sidebar works consistently across devices, remembers user preferences, and provides developer APIs for customization.
Core Responsibilities
- State Management – Tracks whether the sidebar is expanded or collapsed.
- Mobile Responsiveness – Detects screen size and manages a separate mobile overlay state.
- Persistence – Stores sidebar state in cookies for 7 days.
- Variants – Supports sidebar , floating , and inset display styles.
- Keyboard Shortcuts – Toggle with Ctrl / ⌘ + B .
- Cleanup – Removes event listeners on destroy.
Signals & Computed
- open – Whether the desktop sidebar is open.
- openMobile – Whether the mobile sidebar is open.
- isMobile – Whether the viewport is below 768px.
- variant – Current sidebar style ( sidebar , floating , or inset ).
- state – Computed: 'expanded' or 'collapsed' .
Public API
- setOpen(open: boolean) – Opens or closes the desktop sidebar (persists state in a cookie).
- setOpenMobile(open: boolean) – Opens/closes the mobile sidebar.
- setVariant(variant) – Sets the sidebar style.
- toggleSidebar() – Toggles the sidebar depending on desktop/mobile mode.
Keyboard Shortcut
The SIDEBAR_KEYBOARD_SHORTCUT variable defines the keyboard shortcut used to open and close the sidebar.
- On macOS, use ⌘ + B to toggle the sidebar.
- On Windows/Linux, use Ctrl + B to toggle the sidebar.
To change the shortcut, update the value of SIDEBAR_KEYBOARD_SHORTCUT in the HlmSidebarService source. By default it is set to 'b' .
Width
The HlmSidebarWrapper directive controls the width of the sidebar and its icon-only collapsed state . It applies styles, sets CSS variables, and ensures consistent layout across different sidebar variants.
Inputs
- [class] – Pass custom classes to extend styling.
- [sidebarWidth] – Override default sidebar width (e.g. 280px ).
- [sidebarWidthIcon] – Override collapsed width (e.g. 72px ).
Defaults
- sidebarWidth – 16rem
- sidebarWidthMobile – 18rem
- sidebarWidthIcon – 3rem
- sidebarCookieName – sidebar_state
- sidebarCookieMaxAge – 60 * 60 * 24 * 7
- sidebarKeyboardShortcut – b
- mobileBreakpoint – 768px
Config
To override defaults, provide a custom configuration in your application config using provideHlmSidebarConfig .
import { ApplicationConfig } from '@angular/core';
import { provideHlmSidebarConfig } from '@spartan-ng/helm/sidebar';
export const appConfig: ApplicationConfig = {
providers: [
provideHlmSidebarConfig({
...
sidebarWidth: '16rem',
sidebarWidthMobile: '18rem',
sidebarWidthIcon: '3rem',
sidebarCookieName: 'sidebar_state',
sidebarCookieMaxAge: 60 * 60 * 24 * 7,
sidebarKeyboardShortcut: 'b',
mobileBreakpoint: '768px',
}),
],
};
HlmSidebarHeader
Use the HlmSidebarHeader component to add a sticky header at the top of your sidebar. This is useful for branding, application titles, or quick-access navigation.

import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { HlmMenuImports } from '@spartan-ng/helm/menu';
import { BrnMenuImports } from '@spartan-ng/brain/menu';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { HlmIcon } from '@spartan-ng/helm/icon';
import { lucideChevronDown } from '@ng-icons/lucide';
@Component({
selector: 'app-sidebar',
imports: [
HlmSidebarImports,
HlmMenuImports,
BrnMenuImports,
NgIcon,
HlmIcon,
],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarHeader>
<ul hlmSidebarMenu>
<li hlmSidebarMenuItem>
<button hlmSidebarMenuButton [brnMenuTriggerFor]="menu">
Select Workspace
<ng-icon hlm name="lucideChevronDown" class="ml-auto" />
</button>
<ng-template #menu>
<hlm-menu class="w-60">
<hlm-menu-label>Acme Inc</hlm-menu-label>
<hlm-menu-label>Acme Corp.</hlm-menu-label>
</hlm-menu>
</ng-template>
</li>
</ul>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideChevronDown,
}),
],
})
export class AppSidebar {}
HlmSidebarFooter
Use the HlmSidebarFooter component to add a sticky footer at the bottom of your sidebar. This is useful for secondary actions, user profile information, or app settings.

import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronUp } from '@ng-icons/lucide';
import { BrnMenuImports } from '@spartan-ng/brain/menu';
import { HlmIcon } from '@spartan-ng/helm/icon';
import { HlmMenuImports } from '@spartan-ng/helm/menu';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, HlmMenuImports, BrnMenuImports, NgIcon, HlmIcon],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarHeader></div>
<div hlmSidebarContent></div>
<div hlmSidebarFooter>
<ul hlmSidebarMenu>
<li hlmSidebarMenuItem>
<button hlmSidebarMenuButton [brnMenuTriggerFor]="menu">
Select Workspace
<ng-icon hlm name="lucideChevronUp" class="ml-auto" />
</button>
<ng-template #menu>
<hlm-menu class="w-60">
<button hlmMenuItem>Account</button>
<button hlmMenuItem>Billing</button>
<button hlmMenuItem>Sign out</button>
</hlm-menu>
</ng-template>
</li>
</ul>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideChevronUp,
}),
],
})
export class AppSidebar {}
HlmSidebarContent
The HlmSidebarContent component is used to wrap the main content of the sidebar. This is where you add your HlmSidebarGroup components, navigation links, or menus. The content inside is scrollable , while the header and footer remain sticky.
import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup></div>
<div hlmSidebarGroup></div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
})
export class AppSidebar {}
HlmSidebarGroup
Use the HlmSidebarGroup component to create a section within the sidebar. A SidebarGroup is composed of:
- HlmSidebarGroupLabel – the section label or title.
- HlmSidebarGroupContent – the main body of the group, usually containing links or menu items.
- HlmSidebarGroupAction (optional) – a button or action element associated with the group, e.g. "Add" or "Settings".

import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideLifeBuoy, lucideSend } from '@ng-icons/lucide';
import { HlmIcon } from '@spartan-ng/helm/icon';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, NgIcon, HlmIcon],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupLabel>Help</div>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton>
<ng-icon hlm name="lucideLifeBuoy" />
<span>Support</span>
</a>
</li>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton>
<ng-icon hlm name="lucideSend" />
<span>Feedback</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideLifeBuoy,
lucideSend,
}),
],
})
export class AppSidebar {}
Collapsable HlmSidebarGroup
To make a HlmSidebarGroup collapsible, wrap it in a BrnCollapsible

import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { HlmIcon } from '@spartan-ng/helm/icon';
import {
lucideChevronDown,
lucideLifeBuoy,
lucideSend,
} from '@ng-icons/lucide';
import { BrnCollapsibleImports } from '@spartan-ng/brain/collapsible';
@Component({
selector: 'app-sidebar',
imports: [HlmIcon, NgIcon, BrnCollapsibleImports, HlmSidebarImports],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<brn-collapsible [expanded]="true" class="group/collapsible">
<div hlmSidebarGroup>
<button
brnCollapsibleTrigger
hlmSidebarGroupLabel
class="hover:bg-sidebar-accent hover:text-sidebar-accent-foreground text-sm"
>
Help
<ng-icon
hlm
name="lucideChevronDown"
class="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180"
/>
</button>
<brn-collapsible-content>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton>
<ng-icon hlm name="lucideLifeBuoy" />
<span>Support</span>
</a>
</li>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton>
<ng-icon hlm name="lucideSend" />
<span>Feedback</span>
</a>
</li>
</ul>
</div>
</brn-collapsible-content>
</div>
</brn-collapsible>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideLifeBuoy,
lucideSend,
lucideChevronDown,
}),
],
})
export class AppSidebar {}
HlmSidebarGroupAction
Use the HlmSidebarGroupAction component to add an action button to the HlmSidebarGroup .

import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { HlmIcon } from '@spartan-ng/helm/icon';
import {
lucideChartPie,
lucideFrame,
lucideMap,
lucidePlus,
} from '@ng-icons/lucide';
import { toast } from 'ngx-sonner';
import { HlmToasterImports } from '@spartan-ng/helm/sonner';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, NgIcon, HlmIcon, HlmToasterImports],
template: `
<hlm-toaster />
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupLabel>Projects</div>
<button
hlmSidebarGroupAction
title="Add Project"
(click)="_onAddProject()"
>
<ng-icon hlm name="lucidePlus" />
<span class="sr-only">Add Project</span>
</button>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#">
<ng-icon hlm name="lucideFrame" />
<span>Design Engineering</span>
</a>
</li>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#">
<ng-icon hlm name="lucideChartPie" />
<span>Sales & Marketing</span>
</a>
</li>
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#">
<ng-icon hlm name="lucideMap" />
<span>Travel</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideFrame,
lucideChartPie,
lucideMap,
lucidePlus,
}),
],
})
export class AppSidebar {
protected _onAddProject(): void {
toast.info('You clicked the group action!');
}
}
HlmSidebarMenu
The HlmSidebarMenu component is used for building a menu inside a HlmSidebarGroup . It is composed of the following parts:
- HlmSidebarMenuItem – A single menu entry within the menu.
- HlmSidebarMenuButton – A clickable button or link inside a menu item.
- HlmSidebarMenuAction – An optional action (e.g., context menu, settings) for the menu item.
- HlmSidebarMenuSub – A nested submenu within a menu item.

Here's an example of a HlmSidebarMenu component rendering a list of projects.

import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { HlmIcon } from '@spartan-ng/helm/icon';
import {
lucideChartPie,
lucideFrame,
lucideLifeBuoy,
lucideMap,
lucideSend,
} from '@ng-icons/lucide';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, NgIcon, HlmIcon],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupLabel>Projects</div>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
@for (project of _projects; track project){
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton [href]="project.url">
<ng-icon hlm [name]="project.icon" />
<span>{{ project.name }}</span>
</a>
</li>
}
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideFrame,
lucideChartPie,
lucideMap,
lucideLifeBuoy,
lucideSend,
}),
],
})
export class AppSidebar {
protected readonly _projects = [
{ name: 'Design Engineering', url: '#', icon: 'lucideFrame' },
{ name: 'Sales & Marketing', url: '#', icon: 'lucideChartPie' },
{ name: 'Travel', url: '#', icon: 'lucideMap' },
{ name: 'Support', url: '#', icon: 'lucideLifeBuoy' },
{ name: 'Feedback', url: '#', icon: 'lucideSend' },
];
}
HlmSidebarMenuButton
The HlmSidebarMenuButton component is used to render a menu button within a HlmSidebarMenuItem .
Link or Anchor
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#">
Home
</a>
</li>
Button
<li hlmSidebarMenuItem>
<button hlmSidebarMenuButton>
Send
</button>
</li>
Icon and Label
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#">
<ng-icon hlm name="lucideHouse" />
<span>Home</span>
</a>
</li>
You can render an icon and a truncated label inside the button. Remember to wrap the label in a .
isActive
Use the isActive prop to mark a menu item as active.
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#" isActive>
Home
</a>
</li>
HlmSidebarMenuAction
The HlmSidebarMenuAction component is used to render a menu action within a HlmSidebarMenuItem .
This button works independently of the HlmSidebarMenuButton . For example, you can have a SidebarMenuButton as a clickable link, while the SidebarMenuAction provides a secondary action, such as editing, deleting, or opening a context menu.
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton href="#">
<ng-icon hlm name="lucideHouse" />
<span>Home</span>
</a>
<button hlmSidebarMenuAction>
<ng-icon hlm name="lucidePlus" />
<span class="sr-only">Add Project</span>
</button>
</li>
DropdownMenu
Here's an example of a HlmSidebarMenuAction component rendering a HlmMenu .

import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
import { BrnMenuImports } from '@spartan-ng/brain/menu';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { HlmIcon } from '@spartan-ng/helm/icon';
import {
lucideChartPie,
lucideEllipsis,
lucideFrame,
lucideLifeBuoy,
lucideMap,
lucideSend,
} from '@ng-icons/lucide';
import { HlmMenuImports } from '@spartan-ng/helm/menu';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, BrnMenuImports, NgIcon, HlmIcon, HlmMenuImports],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupLabel>Projects</div>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
@for (project of projects; track project){
<li hlmSidebarMenuItem>
<a hlmSidebarMenuButton [href]="project.url">
<ng-icon hlm [name]="project.icon" />
<span>{{ project.name }}</span>
</a>
<button hlmSidebarMenuAction [brnMenuTriggerFor]="menu">
<ng-icon hlm name="lucideEllipsis" />
<span class="sr-only">More</span>
</button>
<ng-template #menu>
<hlm-menu>
<button hlmMenuItem>Edit Project</button>
<button hlmMenuItem>Delete Project</button>
</hlm-menu>
</ng-template>
</li>
}
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideFrame,
lucideChartPie,
lucideMap,
lucideLifeBuoy,
lucideSend,
lucideEllipsis,
}),
],
})
export class AppSidebar {
projects = [
{ name: 'Design Engineering', url: '#', icon: 'lucideFrame' },
{ name: 'Sales & Marketing', url: '#', icon: 'lucideChartPie' },
{ name: 'Travel', url: '#', icon: 'lucideMap' },
{ name: 'Support', url: '#', icon: 'lucideLifeBuoy' },
{ name: 'Feedback', url: '#', icon: 'lucideSend' },
];
}
HlmMenuSub
The HlmSidebarMenuSub component is used to render a submenu within a HlmSidebarMenu .
Use HlmSidebarMenuSubItem and HlmSidebarMenuSubButton to render a submenu item.

import { Component } from '@angular/core';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
@for (item of _items; track item.title) {
<li hlmSidebarMenuItem>
<button hlmSidebarMenuButton>
<span>{{ item.title }}</span>
</button>
<ul hlmSidebarMenuSub>
@for (subItem of item.items; track subItem.title) {
<li hlmSidebarMenuSubItem>
<button hlmSidebarMenuSubButton class="w-full">
<span>{{ subItem.title }}</span>
</button>
</li>
}
</ul>
</li>
}
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<main hlmSidebarInset>
<header class="flex h-12 items-center justify-between px-4">
<button hlmSidebarTrigger><span class="sr-only"></span></button>
</header>
</main>
</div>
`,
})
export default class AppSidebar {
protected readonly _items = [
{
title: 'Getting Started',
items: [{ title: 'Installation' }, { title: 'Project Structure' }],
},
{
title: 'Building Your Application',
items: [
{ title: 'Routing' },
{ title: 'Data Fetching', isActive: true },
{ title: 'Rendering' },
{ title: 'Caching' },
{ title: 'Styling' },
{ title: 'Optimizing' },
{ title: 'Configuring' },
{ title: 'Testing' },
{ title: 'Authentication' },
{ title: 'Deploying' },
{ title: 'Upgrading' },
{ title: 'Examples' },
],
},
{
title: 'API Reference',
items: [
{ title: 'Components' },
{ title: 'File Conventions' },
{ title: 'Functions' },
{ title: 'next.config.js Options' },
{ title: 'CLI' },
{ title: 'Edge Runtime' },
],
},
{
title: 'Architecture',
items: [
{ title: 'Accessibility' },
{ title: 'Fast Refresh' },
{ title: 'Next.js Compiler' },
{ title: 'Supported Browsers' },
{ title: 'Turbopack' },
],
},
];
}
Collapsable HlmSidebarSubMenu
To make a HlmSidebarMenu component collapsible, wrap it and the HlmSidebarMenuSub components in a BrnCollapsible .

import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronRight } from '@ng-icons/lucide';
import { BrnCollapsibleImports } from '@spartan-ng/brain/collapsible';
import { HlmIcon } from '@spartan-ng/helm/icon';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, BrnCollapsibleImports, NgIcon, HlmIcon],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
@for (item of _items; track item.title) {
<brn-collapsible [expanded]="item.defaultOpen" class="group/collapsible">
<li hlmSidebarMenuItem>
<button
brnCollapsibleTrigger
hlmSidebarMenuButton
class="flex w-full items-center justify-between"
>
<span>{{ item.title }}</span>
<ng-icon
name="lucideChevronRight"
class="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-90"
hlm
/>
</button>
<brn-collapsible-content>
<ul hlmSidebarMenuSub>
@for (subItem of item.items; track subItem.title) {
<li hlmSidebarMenuSubItem>
<button hlmSidebarMenuSubButton class="w-full">
<span>{{ subItem.title }}</span>
</button>
</li>
}
</ul>
</brn-collapsible-content>
</li>
</brn-collapsible>
}
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<main hlmSidebarInset>
<header class="flex h-12 items-center justify-between px-4">
<button hlmSidebarTrigger><span class="sr-only"></span></button>
</header>
</main>
</div>
`,
providers: [provideIcons({ lucideChevronRight })],
})
export default class AppSidebar {
protected readonly _items = [
{
title: 'Getting Started',
defaultOpen: true,
items: [{ title: 'Installation' }, { title: 'Project Structure' }],
},
{
title: 'Building Your Application',
defaultOpen: false,
items: [
{ title: 'Routing' },
{ title: 'Data Fetching', isActive: true },
{ title: 'Rendering' },
{ title: 'Caching' },
{ title: 'Styling' },
{ title: 'Optimizing' },
{ title: 'Configuring' },
{ title: 'Testing' },
{ title: 'Authentication' },
{ title: 'Deploying' },
{ title: 'Upgrading' },
{ title: 'Examples' },
],
},
{
title: 'API Reference',
defaultOpen: false,
items: [
{ title: 'Components' },
{ title: 'File Conventions' },
{ title: 'Functions' },
{ title: 'next.config.js Options' },
{ title: 'CLI' },
{ title: 'Edge Runtime' },
],
},
{
title: 'Architecture',
defaultOpen: false,
items: [
{ title: 'Accessibility' },
{ title: 'Fast Refresh' },
{ title: 'Next.js Compiler' },
{ title: 'Supported Browsers' },
{ title: 'Turbopack' },
],
},
];
}
HlmSidebarMenuBadge
The HlmSidebarMenuBadge component is used to render a badge within a HlmSidebarMenuItem .

import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChartPie, lucideFrame, lucideLifeBuoy, lucideMap, lucideSend } from '@ng-icons/lucide';
import { HlmIcon } from '@spartan-ng/helm/icon';
import { HlmSidebarImports } from '@spartan-ng/helm/sidebar';
@Component({
selector: 'app-sidebar',
imports: [HlmSidebarImports, NgIcon, HlmIcon],
template: `
<div hlmSidebarWrapper>
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup>
<div hlmSidebarGroupLabel>Projects</div>
<div hlmSidebarGroupContent>
<ul hlmSidebarMenu>
@for (project of _projects; track project) {
<li hlmSidebarMenuItem>
<button hlmSidebarMenuButton>
<ng-icon hlm [name]="project.icon" />
<span>{{ project.name }}</span>
</button>
<div hlmSidebarMenuBadge>{{ project.info }}</div>
</li>
}
</ul>
</div>
</div>
</div>
</hlm-sidebar>
<ng-content />
</div>
`,
providers: [
provideIcons({
lucideFrame,
lucideChartPie,
lucideMap,
lucideLifeBuoy,
lucideSend,
}),
],
})
export class AppSidebar {
protected readonly _projects = [
{ info: 24, name: 'Design Engineering', url: '#', icon: 'lucideFrame' },
{ info: 12, name: 'Sales & Marketing', url: '#', icon: 'lucideChartPie' },
{ info: 3, name: 'Travel', url: '#', icon: 'lucideMap' },
{ info: 21, name: 'Support', url: '#', icon: 'lucideLifeBuoy' },
{ info: 8, name: 'Feedback', url: '#', icon: 'lucideSend' },
];
}
HlmSidebarMenuSkeleton
The HlmSidebarMenuSkeleton component is used to render a skeleton for a SidebarMenu. You can use this to show a loading state while fetching data.
<ul hlmSidebarMenu>
@for (project of _projects; track project) {
<li hlmSidebarMenuItem>
<div hlmSidebarMenuSkeleton></div>
</li>
}
</ul>
HlmSidebarMenuSeparator
The HlmSidebarMenuSeparator component is used to render a separator within a Sidebar .
<hlm-sidebar>
<div hlmSidebarContent>
<div hlmSidebarGroup></div>
<div hlmSidebarSeparator></div>
<div hlmSidebarGroup></div>
</div>
</hlm-sidebar>
Theming
We use dedicated CSS variables for theming the sidebar, separate from the rest of the application.
@layer base {
:root {
--sidebar: 300 0% 98%;
--sidebar-foreground: 300 0% 4%;
--sidebar-primary: 330 0% 9%;
--sidebar-primary-foreground: 300 0% 98%;
--sidebar-accent: 300 0% 96%;
--sidebar-accent-foreground: 330 0% 9%;
--sidebar-border: 330 0% 90%;
--sidebar-ring: 0 0% 63%;
}
.dark {
--sidebar: 300 0% 98%;
--sidebar-foreground: 300 0% 4%;
--sidebar-primary: 330 0% 9%;
--sidebar-primary-foreground: 300 0% 98%;
--sidebar-accent: 300 0% 96%;
--sidebar-accent-foreground: 330 0% 9%;
--sidebar-border: 330 0% 90%;
--sidebar-ring: 0 0% 63%;
}
}
We intentionally use different variables for the sidebar and the rest of the application to make it easy to have a sidebar that is styled differently from the rest of the application. Think a sidebar with a darker shade from the main application.
Responsive behavior
The sidebar is responsive by default. It collapses to a minimal state on smaller screens and expands on larger screens. This behavior can be customized by overriding the default CSS variables or wrapping in media queries.
Accessibility
The sidebar and its components follow WAI-ARIA best practices. Ensure you provide appropriate labels for buttons and landmarks to improve screen reader support.