Angular playground

Nova v3.37.0

Preview

Angular

Sidebar

Framework reference for the sidebar and every part.

← nv-sidebar

nv-sidebar Component Guide for Angular

Introduction

The nv-sidebar component provides a flexible and responsive navigation sidebar for Angular applications. Built on top of Nova's design tokens, it offers collapsible navigation with support for nested items, notifications, and seamless integration with Angular Router.

Key Features:

  • Collapsible and static sidebar types
  • Nested navigation with sub-items
  • Notification badges following Nova's design tokens
  • Active state management
  • Angular Router integration
  • Responsive design

Installation

bashnpm install @nova-design-system/nova-angular

Configuration

In your app.config.ts or app.module.ts, import the Nova module:

typescriptimport { NovaComponentsModule } from '@nova-design-system/nova-angular';

// For standalone components
@Component({
  standalone: true,
  imports: [CommonModule, RouterModule, NovaComponentsModule],
  // ...
})

// Or in app.module.ts
@NgModule({
  imports: [NovaComponentsModule],
  // ...
})

Basic Usage

Static Sidebar

typescriptimport { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { NovaComponentsModule } from '@nova-design-system/nova-angular';

@Component({
  selector: 'app-static-sidebar',
  standalone: true,
  imports: [CommonModule, RouterModule, NovaComponentsModule],
  template: `
    <nv-sidebar type="static">
      <nv-sidebarlogo label="My App"></nv-sidebarlogo>
      <nv-sidebarcontent>
        <nv-sidebargroup label="Navigation">
          <nv-sidebarnavitem icon="home">
            <a routerLink="/dashboard">Dashboard</a>
          </nv-sidebarnavitem>
          <nv-sidebarnavitem icon="user">
            <a routerLink="/profile">Profile</a>
          </nv-sidebarnavitem>
        </nv-sidebargroup>
      </nv-sidebarcontent>
    </nv-sidebar>
  `
})
export class StaticSidebarComponent {}

Collapsible Sidebar

typescriptimport { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { NovaComponentsModule } from '@nova-design-system/nova-angular';

@Component({
  selector: 'app-collapsible-sidebar',
  standalone: true,
  imports: [CommonModule, RouterModule, NovaComponentsModule],
  template: `
    <nv-sidebar
      type="collapsible"
      [open]="isOpen"
      (openChanged)="handleOpenChanged($event)"
    >
      <nv-sidebarlogo label="My App"></nv-sidebarlogo>
      <nv-sidebarcontent>
        <nv-sidebargroup label="Main">
          <nv-sidebarnavitem icon="home">
            <a routerLink="/dashboard">Dashboard</a>
          </nv-sidebarnavitem>
        </nv-sidebargroup>
      </nv-sidebarcontent>
    </nv-sidebar>
  `
})
export class CollapsibleSidebarComponent {
  isOpen = true;

  handleOpenChanged(event: CustomEvent<boolean>) {
    this.isOpen = event.detail;
  }
}

Angular Router Integration

Complete Example with Router State

typescriptimport { Component, OnInit, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
import { Subscription } from 'rxjs';
import { NovaComponentsModule } from '@nova-design-system/nova-angular';

@Component({
  selector: 'app-main-sidebar',
  standalone: true,
  imports: [CommonModule, RouterModule, NovaComponentsModule],
  template: `
    <nv-sidebar
      [type]="'collapsible'"
      [open]="isOpen"
      (openChanged)="handleOpenChanged($event)"
      [activePath]="currentPath"
      notificationIntention="brand"
      notificationEmphasis="high"
    >
      <nv-sidebarlogo label="nova Angular"></nv-sidebarlogo>

      <nv-sidebarcontent>
        <nv-sidebargroup label="Main">
          <nv-sidebarnavitem icon="home">
            <a routerLink="/dashboard" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
              Dashboard
            </a>
          </nv-sidebarnavitem>

          <nv-sidebarnavitem icon="chart-bar" [collapsible]="true">
            <span>Analytics</span>
            <nv-sidebarnavsubitem>
              <a
                routerLink="/analytics/reports"
                routerLinkActive="active"
                [routerLinkActiveOptions]="{exact: true}"
              >
                Reports
              </a>
            </nv-sidebarnavsubitem>
            <nv-sidebarnavsubitem>
              <a
                routerLink="/analytics/metrics"
                routerLinkActive="active"
                [routerLinkActiveOptions]="{exact: true}"
              >
                Metrics
              </a>
            </nv-sidebarnavsubitem>
          </nv-sidebarnavitem>

          <nv-sidebarnavitem icon="settings" [collapsible]="true" [notificationCount]="5">
            <span>Settings</span>
            <nv-sidebarnavsubitem>
              <a
                routerLink="/settings/profile"
                routerLinkActive="active"
                [routerLinkActiveOptions]="{exact: true}"
              >
                Profile
              </a>
            </nv-sidebarnavsubitem>
            <nv-sidebarnavsubitem>
              <a
                routerLink="/settings/security"
                routerLinkActive="active"
                [routerLinkActiveOptions]="{exact: true}"
              >
                Security
              </a>
            </nv-sidebarnavsubitem>
          </nv-sidebarnavitem>
        </nv-sidebargroup>

        <nv-sidebardivider></nv-sidebardivider>

        <nv-sidebargroup label="Other">
          <nv-sidebarnavitem icon="user" [notificationCount]="12">
            <a routerLink="/users" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
              Users
            </a>
          </nv-sidebarnavitem>
        </nv-sidebargroup>
      </nv-sidebarcontent>

      <nv-sidebarfooter>
        <nv-sidebarnavitem icon="bell" [notificationCount]="170">
          <a
            routerLink="/notifications"
            routerLinkActive="active"
            [routerLinkActiveOptions]="{exact: true}"
          >
            Notifications
          </a>
        </nv-sidebarnavitem>
      </nv-sidebarfooter>
    </nv-sidebar>
  `
})
export class MainSidebarComponent implements OnInit, OnDestroy {
  isOpen = true;
  currentPath = '';
  private routerSubscription?: Subscription;

  constructor(private router: Router) {}

  ngOnInit() {
    // Listen to route changes to update currentPath
    this.routerSubscription = this.router.events
      .pipe(filter((event) => event instanceof NavigationEnd))
      .subscribe((event: NavigationEnd) => {
        this.currentPath = event.url;
      });

    // Initialize with current route
    this.currentPath = this.router.url;
  }

  ngOnDestroy() {
    this.routerSubscription?.unsubscribe();
  }

  handleOpenChanged(event: CustomEvent<boolean>) {
    this.isOpen = event.detail;
  }
}

Component Structure

NvSidebar

The main container component with the following inputs:

InputTypeDefaultDescription
type'static' | 'collapsible''static'Sidebar behavior type
openbooleantrueControls open/closed state (collapsible only)
activePathstringundefinedCurrent active path for automatic highlighting
notificationIntentionstring'brand'Default notification badge intention
notificationEmphasisstring'high'Default notification badge emphasis

Outputs:

  • openChanged: Emitted when sidebar open state changes

NvSidebarlogo

Displays the application logo/brand.

InputTypeDefaultDescription
labelstringundefinedLogo text label

NvSidebarcontent

Container for navigation groups and dividers.

NvSidebargroup

Groups related navigation items.

InputTypeDefaultDescription
labelstringundefinedGroup title

NvSidebarnavitem

Individual navigation item with optional sub-items.

InputTypeDefaultDescription
iconstringundefinedIcon name from Nova icon set
collapsiblebooleanfalseMakes item expandable with sub-items
notificationCountnumberundefinedNumber to display in notification badge
activebooleanfalseForces active state

NvSidebarnavsubitem

Sub-navigation item (child of NvSidebarnavitem).

NvSidebardivider

Visual separator between groups.

NvSidebarfooter

Container for footer navigation items.

Advanced Usage

Dynamic Navigation with Services

typescriptimport { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { Observable } from 'rxjs';
import { NovaComponentsModule } from '@nova-design-system/nova-angular';

interface NavItem {
  id: string;
  label: string;
  path?: string;
  icon: string;
  notifications?: number;
  children?: NavItem[];
}

interface NavGroup {
  id: string;
  label: string;
  items: NavItem[];
}

@Component({
  selector: 'app-dynamic-sidebar',
  standalone: true,
  imports: [CommonModule, RouterModule, NovaComponentsModule],
  template: `
    <nv-sidebar [activePath]="currentPath">
      <nv-sidebarcontent>
        <nv-sidebargroup
          *ngFor="let group of navigationGroups$ | async"
          [label]="group.label"
        >
          <nv-sidebarnavitem
            *ngFor="let item of group.items"
            [icon]="item.icon"
            [notificationCount]="item.notifications"
            [collapsible]="item.children && item.children.length > 0"
          >
            <span *ngIf="item.children">{{ item.label }}</span>
            <a
              *ngIf="!item.children"
              [routerLink]="item.path"
              routerLinkActive="active"
              [routerLinkActiveOptions]="{exact: true}"
            >
              {{ item.label }}
            </a>

            <nv-sidebarnavsubitem *ngFor="let child of item.children">
              <a
                [routerLink]="child.path"
                routerLinkActive="active"
                [routerLinkActiveOptions]="{exact: true}"
              >
                {{ child.label }}
              </a>
            </nv-sidebarnavsubitem>
          </nv-sidebarnavitem>
        </nv-sidebargroup>
      </nv-sidebarcontent>
    </nv-sidebar>
  `
})
export class DynamicSidebarComponent implements OnInit {
  navigationGroups$!: Observable<NavGroup[]>;
  currentPath = '';

  constructor(
    private router: Router,
    private navigationService: NavigationService
  ) {}

  ngOnInit() {
    this.navigationGroups$ = this.navigationService.getNavigation();
    this.currentPath = this.router.url;
  }
}

Custom Active State with Route Matching

typescriptimport { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Router } from '@angular/router';
import { NovaComponentsModule } from '@nova-design-system/nova-angular';

@Component({
  selector: 'app-custom-active-sidebar',
  standalone: true,
  imports: [CommonModule, RouterModule, NovaComponentsModule],
  template: `
    <nv-sidebar [activePath]="currentPath">
      <nv-sidebarcontent>
        <nv-sidebargroup>
          <nv-sidebarnavitem
            icon="folder"
            [active]="isProjectsActive()"
          >
            <a routerLink="/projects">Projects</a>
          </nv-sidebarnavitem>
          <nv-sidebarnavitem
            icon="users"
            [active]="isUsersActive()"
          >
            <a routerLink="/users">Users</a>
          </nv-sidebarnavitem>
        </nv-sidebargroup>
      </nv-sidebarcontent>
    </nv-sidebar>
  `
})
export class CustomActiveSidebarComponent {
  currentPath = '';

  constructor(private router: Router) {
    this.currentPath = this.router.url;
  }

  isProjectsActive(): boolean {
    return this.router.url.startsWith('/projects');
  }

  isUsersActive(): boolean {
    return this.router.url.startsWith('/users');
  }
}

Angular-Specific Notes

Property Binding

Use [property] for input binding:

html<nv-sidebar
  [type]="'collapsible'"
  [open]="isOpen"
  [activePath]="currentPath"
  [notificationCount]="notificationCount"
>

Event Binding

Use (event) for output binding:

html<nv-sidebar
  (openChanged)="handleOpenChanged($event)"
>

RouterLink Active

Use routerLinkActive with routerLinkActiveOptions for exact path matching:

html<a
  routerLink="/dashboard"
  routerLinkActive="active"
  [routerLinkActiveOptions]="{exact: true}"
>
  Dashboard
</a>

Parent Items with Sub-items

When a navigation item has sub-items, use a <span> as the label instead of a <a routerLink>:

html<nv-sidebarnavitem icon="settings" [collapsible]="true">
  <span>Settings</span> <!-- Not a routerLink -->
  <nv-sidebarnavsubitem>
    <a routerLink="/settings/profile">Profile</a>
  </nv-sidebarnavsubitem>
</nv-sidebarnavitem>

Lifecycle Management

Route Change Subscription

typescriptimport { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
import { Subscription } from 'rxjs';

@Component({...})
export class SidebarComponent implements OnInit, OnDestroy {
  private routerSubscription?: Subscription;

  constructor(private router: Router) {}

  ngOnInit() {
    this.routerSubscription = this.router.events
      .pipe(filter(event => event instanceof NavigationEnd))
      .subscribe((event: NavigationEnd) => {
        // Update active path
        this.currentPath = event.url;
      });
  }

  ngOnDestroy() {
    this.routerSubscription?.unsubscribe();
  }
}

Reactive Forms Integration

typescriptimport { Component } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { NovaComponentsModule } from '@nova-design-system/nova-angular';

@Component({
  selector: 'app-settings-sidebar',
  template: `
    <nv-sidebar [open]="settingsForm.get('sidebarOpen')?.value">
      <nv-sidebarcontent>
        <nv-sidebargroup label="Settings">
          <nv-sidebarnavitem
            *ngFor="let setting of settings"
            [icon]="setting.icon"
            [notificationCount]="setting.notifications"
          >
            <a [routerLink]="setting.path">{{ setting.label }}</a>
          </nv-sidebarnavitem>
        </nv-sidebargroup>
      </nv-sidebarcontent>
    </nv-sidebar>
  `
})
export class SettingsSidebarComponent {
  settingsForm: FormGroup;

  constructor(private fb: FormBuilder) {
    this.settingsForm = this.fb.group({
      sidebarOpen: [true]
    });
  }
}

Styling

The sidebar follows Nova's design system and uses CSS variables for consistent theming. To maintain design consistency, override these variables only when integrating with your established design system:

css:root {
  --nv-sidebar-width: 280px;
  --nv-sidebar-bg: var(--nv-color-surface-primary);
  --nv-sidebar-border: var(--nv-color-border-primary);
}

Accessibility

  • Keyboard navigation support
  • ARIA labels and roles
  • Focus management for collapsible items
  • Screen reader friendly notification counts

Common Patterns

Admin Dashboard Layout

typescriptimport { Component } from '@angular/core';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-admin-layout',
  standalone: true,
  imports: [CommonModule],
  template: `
    <div class="admin-layout">
      <app-sidebar
        [open]="sidebarOpen"
        (openChanged)="sidebarOpen = $event.detail"
      ></app-sidebar>
      <main class="main-content">
        <router-outlet></router-outlet>
      </main>
    </div>
  `
})
export class AdminLayoutComponent {
  sidebarOpen = true;
}

Responsive Design

Note: Responsive design features are not currently implemented in the nv-sidebar component. Mobile-first responsive behavior will be considered for inclusion in a future v2 release, potentially including:

  • Automatic mobile/desktop mode switching
  • Touch-friendly interactions
  • Collapsible behavior based on screen size
  • Overlay modes for mobile devices

For now, implement responsive behavior at the application level using CSS media queries and Angular's change detection.