Vue playground

Nova v3.37.0

Preview

Vue

Sidebar

Framework reference for the sidebar and every part.

← nv-sidebar

NvSidebar Component Guide for Vue.js

Introduction

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

Key Features:

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

Installation

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

Basic Usage

Static Sidebar

vue<template>
  <NvSidebar type="static">
    <NvSidebarlogo label="My App" />
    <NvSidebarcontent>
      <NvSidebargroup label="Navigation">
        <NvSidebarnavitem icon="home">
          <router-link to="/dashboard">Dashboard</router-link>
        </NvSidebarnavitem>
        <NvSidebarnavitem icon="user">
          <router-link to="/profile">Profile</router-link>
        </NvSidebarnavitem>
      </NvSidebargroup>
    </NvSidebarcontent>
  </NvSidebar>
</template>

<script setup lang="ts">
import {
  NvSidebar,
  NvSidebarlogo,
  NvSidebarcontent,
  NvSidebargroup,
  NvSidebarnavitem
} from '@nova-design-system/nova-vue';
</script>

Collapsible Sidebar

vue<template>
  <NvSidebar
    type="collapsible"
    :open="isOpen"
    @open-changed="handleOpenChanged"
  >
    <NvSidebarlogo label="My App" />
    <NvSidebarcontent>
      <NvSidebargroup label="Main">
        <NvSidebarnavitem icon="home">
          <router-link to="/dashboard">Dashboard</router-link>
        </NvSidebarnavitem>
      </NvSidebargroup>
    </NvSidebarcontent>
  </NvSidebar>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import {
  NvSidebar,
  NvSidebarlogo,
  NvSidebarcontent,
  NvSidebargroup,
  NvSidebarnavitem
} from '@nova-design-system/nova-vue';

const isOpen = ref(true);

const handleOpenChanged = (event: CustomEvent<boolean>) => {
  isOpen.value = event.detail;
};
</script>

Vue Router Integration

Complete Example

vue<template>
  <NvSidebar
    type="collapsible"
    :open="isOpen"
    @open-changed="handleOpenChanged"
    :active-path="currentPath"
    notification-intention="brand"
    notification-emphasis="high"
  >
    <NvSidebarlogo label="nova Vue" />

    <NvSidebarcontent>
      <NvSidebargroup label="Main">
        <NvSidebarnavitem icon="home">
          <router-link
            to="/dashboard"
            :class="{ active: $route.path === '/dashboard' }"
          >
            Dashboard
          </router-link>
        </NvSidebarnavitem>

        <NvSidebarnavitem icon="chart-bar" :collapsible="true">
          <span>Analytics</span>
          <NvSidebarnavsubitem>
            <router-link
              to="/analytics/reports"
              :class="{ active: $route.path === '/analytics/reports' }"
            >
              Reports
            </router-link>
          </NvSidebarnavsubitem>
          <NvSidebarnavsubitem>
            <router-link
              to="/analytics/metrics"
              :class="{ active: $route.path === '/analytics/metrics' }"
            >
              Metrics
            </router-link>
          </NvSidebarnavsubitem>
        </NvSidebarnavitem>

        <NvSidebarnavitem icon="settings" :collapsible="true" :notification-count="5">
          <span>Settings</span>
          <NvSidebarnavsubitem>
            <router-link
              to="/settings/profile"
              :class="{ active: $route.path === '/settings/profile' }"
            >
              Profile
            </router-link>
          </NvSidebarnavsubitem>
          <NvSidebarnavsubitem>
            <router-link
              to="/settings/security"
              :class="{ active: $route.path === '/settings/security' }"
            >
              Security
            </router-link>
          </NvSidebarnavsubitem>
        </NvSidebarnavitem>
      </NvSidebargroup>

      <NvSidebardivider />

      <NvSidebargroup label="Other">
        <NvSidebarnavitem icon="user" :notification-count="12">
          <router-link
            to="/users"
            :class="{ active: $route.path === '/users' }"
          >
            Users
          </router-link>
        </NvSidebarnavitem>
      </NvSidebargroup>
    </NvSidebarcontent>

    <NvSidebarfooter>
      <NvSidebarnavitem icon="bell" :notification-count="170">
        <router-link
          to="/notifications"
          :class="{ active: $route.path === '/notifications' }"
        >
          Notifications
        </router-link>
      </NvSidebarnavitem>
    </NvSidebarfooter>
  </NvSidebar>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import {
  NvSidebar,
  NvSidebarlogo,
  NvSidebarcontent,
  NvSidebargroup,
  NvSidebarnavitem,
  NvSidebarnavsubitem,
  NvSidebardivider,
  NvSidebarfooter,
} from '@nova-design-system/nova-vue';

const route = useRoute();
const isOpen = ref(true);
const currentPath = computed(() => route.path);

const handleOpenChanged = (event: CustomEvent<boolean>) => {
  isOpen.value = event.detail;
};
</script>

Component Structure

NvSidebar

The main container component with the following props:

PropTypeDefaultDescription
type'static' | 'collapsible''static'Sidebar behavior type
openbooleantrueControls open/closed state (collapsible only)
active-pathstringundefinedCurrent active path for automatic highlighting
notification-intentionstring'brand'Default notification badge intention
notification-emphasisstring'high'Default notification badge emphasis

Events:

  • open-changed: Fired when sidebar open state changes

NvSidebarlogo

Displays the application logo/brand.

PropTypeDefaultDescription
labelstringundefinedLogo text label

NvSidebarcontent

Container for navigation groups and dividers.

NvSidebargroup

Groups related navigation items.

PropTypeDefaultDescription
labelstringundefinedGroup title

NvSidebarnavitem

Individual navigation item with optional sub-items.

PropTypeDefaultDescription
iconstringundefinedIcon name from Nova icon set
collapsiblebooleanfalseMakes item expandable with sub-items
notification-countnumberundefinedNumber 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

Composition API with Reactive Data

vue<template>
  <NvSidebar :active-path="currentPath">
    <NvSidebarcontent>
      <NvSidebargroup
        v-for="group in navigationGroups"
        :key="group.id"
        :label="group.label"
      >
        <NvSidebarnavitem
          v-for="item in group.items"
          :key="item.id"
          :icon="item.icon"
          :notification-count="item.notifications"
          :collapsible="item.children?.length > 0"
        >
          <span v-if="item.children">{{ item.label }}</span>
          <router-link
            v-else
            :to="item.path"
            :class="{ active: isActive(item.path) }"
          >
            {{ item.label }}
          </router-link>

          <NvSidebarnavsubitem
            v-for="child in item.children"
            :key="child.id"
          >
            <router-link
              :to="child.path"
              :class="{ active: isActive(child.path) }"
            >
              {{ child.label }}
            </router-link>
          </NvSidebarnavsubitem>
        </NvSidebarnavitem>
      </NvSidebargroup>
    </NvSidebarcontent>
  </NvSidebar>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { useRoute } from 'vue-router';

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

const route = useRoute();
const navigationGroups = ref<{ id: string; label: string; items: NavItem[] }[]>([]);

const currentPath = computed(() => route.path);

const isActive = (path: string) => {
  return route.path === path;
};

onMounted(async () => {
  // Fetch navigation from API
  const response = await fetch('/api/navigation');
  navigationGroups.value = await response.json();
});
</script>

Custom Active State Logic

vue<template>
  <NvSidebar :active-path="currentPath">
    <NvSidebarcontent>
      <NvSidebargroup>
        <NvSidebarnavitem
          icon="folder"
          :active="isProjectsActive"
        >
          <router-link to="/projects">Projects</router-link>
        </NvSidebarnavitem>
      </NvSidebargroup>
    </NvSidebarcontent>
  </NvSidebar>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();

const currentPath = computed(() => route.path);
const isProjectsActive = computed(() => {
  return route.path.startsWith('/projects');
});
</script>

Vue-Specific Notes

Reactive Props

Use v-bind (:) for boolean and numeric props:

vue<NvSidebarnavitem
  icon="settings"
  :collapsible="true"
  :notification-count="notificationCount"
/>

Event Handling

Use @event-name for event listeners:

vue<NvSidebar
  type="collapsible"
  :open="isOpen"
  @open-changed="handleOpenChanged"
/>

Active Link Styling

Use $route.path for active state checking:

vue<router-link
  to="/dashboard"
  :class="{ active: $route.path === '/dashboard' }"
>
  Dashboard
</router-link>

Parent Items with Sub-items

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

vue<NvSidebarnavitem icon="settings" :collapsible="true">
  <span>Settings</span> <!-- Not a router-link -->
  <NvSidebarnavsubitem>
    <router-link to="/settings/profile">Profile</router-link>
  </NvSidebarnavsubitem>
</NvSidebarnavitem>

Composition vs Options API

Composition API (Recommended)

vue<script setup lang="ts">
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();
const isOpen = ref(true);
const currentPath = computed(() => route.path);

const handleOpenChanged = (event: CustomEvent<boolean>) => {
  isOpen.value = event.detail;
};
</script>

Options API

vue<script lang="ts">
import { useRoute } from 'vue-router';

export default {
  data() {
    return {
      isOpen: true
    };
  },
  computed: {
    currentPath() {
      return this.$route.path;
    }
  },
  methods: {
    handleOpenChanged(event: CustomEvent<boolean>) {
      this.isOpen = event.detail;
    }
  }
};
</script>

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

vue<template>
  <div class="admin-layout">
    <NvSidebar
      type="collapsible"
      :open="sidebarOpen"
      @open-changed="sidebarOpen = $event.detail"
    >
      <!-- Sidebar content -->
    </NvSidebar>

    <main class="main-content">
      <slot />
    </main>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const sidebarOpen = ref(true);
</script>

Responsive Design

Note: Responsive design features are not currently implemented in the NvSidebar 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 Vue's reactivity system.