nb-sidebar

This is a sidebar component for Vue.js 3+. It displays a slide-out sidebar panel that can be positioned on the left or right side of the screen with customizable themes, responsive breakpoints, and overlay backdrop.

Loading component...

Installation

Yarn
yarn add @vlalg-nimbus/nb-overlays
NPM
npm install @vlalg-nimbus/nb-overlays

Usage

Vue 3
import { createApp } from 'vue'
import App from './App.vue'

import NbOverlaysComponents from '@vlalg-nimbus/nb-overlays'
import "@vlalg-nimbus/nb-overlays/dist/style.css";

const app = createApp(App)
app.use(NbOverlaysComponents)
app.mount('#app')
Nuxt 3
import NbOverlaysComponents from '@vlalg-nimbus/nb-overlays'
import "@vlalg-nimbus/nb-overlays/dist/style.css";

export default defineNuxtPlugin(context => {
  context.vueApp.use(NbOverlaysComponents)
})

To use, simply call the component, in this case it will be NbSidebar or nb-sidebar.

Important: The NbSidebar component uses position: fixed and will overlay the page content. It automatically handles responsive visibility based on breakpoints (visibleOnMobile, visibleOnTablet, visibleOnDesktop). When the sidebar is open, it blocks body scroll by default (unless scrollableBody is true).

Mode 1
<template>
  <NbSidebar nb-id="sidebar-1" :show="isSidebarOpen" @close="isSidebarOpen = false">
    <template #content>
      <p>Sidebar content here</p>
    </template>
  </NbSidebar>
</template>
Mode 2
<template>
  <nb-sidebar nb-id="sidebar-1" :show="isSidebarOpen" @close="isSidebarOpen = false">
    <template #content>
      <p>Sidebar content here</p>
    </template>
  </nb-sidebar>
</template>
Mode 3
<template>
  <nb-sidebar nb-id="sidebar-1" :show="isSidebarOpen" @close="isSidebarOpen = false">
    <template #content>
      <p>Sidebar content here</p>
    </template>
  </nb-sidebar>
</template>

Preview & Playground

Select the component you want to edit/test

Loading Sandbox...

Props

Items with an (*) mean they are required

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
showBooleantrueDefines if the sidebar is visible
ariaLabelString'Alternate Text Button'Defines the aria-label attribute for screen readers
ariaAttrsObject{}Allows passing custom aria attributes as an object. Keys will automatically receive the aria- prefix
themeString'light'Defines the theme. Accepts light and dark
positionString'left'Defines the position of the sidebar. Accepts left and right
backdropRGBColorObject{ r: 0, g: 0, b: 0 }Defines the RGB color of the backdrop overlay. Must be an object with r, g, b properties (0-255)
backdropAlphaNumber0.6Defines the alpha/opacity of the backdrop overlay (0-1)
showBottomSectionBooleanfalseDefines if the bottom section should be displayed
showSectionBorderBooleanfalseDefines if the bottom section should have a border
showCloseButtonBooleantrueDefines if the close button should be displayed
closeButtonYNumber13Defines the top position of the close button in pixels
closeButtonXNumber32Defines the right position of the close button in pixels
closeOnOverlayClickBooleantrueDefines if clicking the overlay should close the sidebar
contentPaddingString'10px'Defines the padding of the content area
bottomSectionHeightNumber63Defines the height of the bottom section in pixels
disabledBooleanfalseDefines if the sidebar is disabled
visibleOnMobileBooleantrueDefines if the sidebar should be visible on mobile breakpoints
visibleOnTabletBooleantrueDefines if the sidebar should be visible on tablet breakpoints
visibleOnDesktopBooleantrueDefines if the sidebar should be visible on desktop breakpoints
scrollableBodyBooleanfalseDefines if the body should remain scrollable when sidebar is open
minWidthContentSizeNumber270Defines the minimum width of the sidebar content in pixels
maxWidthContentSizeNumber320Defines the maximum width of the sidebar content in pixels
mobileMinWidthNumber0Defines the minimum width for mobile breakpoint in pixels
mobileMaxWidthNumber767Defines the maximum width for mobile breakpoint in pixels
tabletMinWidthNumber768Defines the minimum width for tablet breakpoint in pixels
tabletMaxWidthNumber1023Defines the maximum width for tablet breakpoint in pixels
desktopMinWidthNumber1024Defines the minimum width for desktop breakpoint in pixels
desktopMaxWidthNumber1600Defines the maximum width for desktop breakpoint in pixels
zIndexNumber2147483640Defines the z-index for the backdrop overlay. The sidebar content will automatically receive zIndex + 2. Important: The maximum value is 2147483640 because the content always adds +2 to this value

Theme Colors (Light)

nameValue typeDefaultDescription
lightCloseButtonColorString'#333333'Defines the close button color for light theme
lightContentColorString'#333333'Defines the content text color for light theme
lightSectionColorString'#333333'Defines the bottom section text color for light theme
lightBackgroundColorString'#f5f5f5'Defines the background color for light theme
lightSectionBackgroundString'#eae4e4'Defines the bottom section background color for light theme
lightSectionBorderColorString'#cfc2c2'Defines the bottom section border color for light theme

Theme Colors (Dark)

nameValue typeDefaultDescription
darkCloseButtonColorString'#e0e0e0'Defines the close button color for dark theme
darkContentColorString'#333333'Defines the content text color for dark theme
darkSectionColorString'#333333'Defines the bottom section text color for dark theme
darkBackgroundColorString'#2d2d2d'Defines the background color for dark theme
darkSectionBackgroundString'#2d2d2d'Defines the bottom section background color for dark theme
darkSectionBorderColorString'#eee'Defines the bottom section border color for dark theme

Slots

nameDescription
contentMain content area of the sidebar
bottom-sectionOptional bottom section content (requires showBottomSection to be true)
close-buttonCustom close button content (replaces the default "✕")

Events

nameReturn typeDescription
closenothingFired when the sidebar is closed (via close button, overlay click, or programmatically)

Provide / Inject

The component provides showSidebar (a reactive ref) that can be injected by child components to access the sidebar's visibility state.

Usage in child components

Vue 3
<script setup>
import { inject } from 'vue'

const showSidebar = inject('showSidebar')

// Access the sidebar visibility state
console.log(showSidebar.value) // true or false
</script>
Nuxt 3
<script setup>
const showSidebar = inject('showSidebar')

// Access the sidebar visibility state
console.log(showSidebar.value) // true or false
</script>

This is useful when you need to conditionally render content or apply styles based on whether the sidebar is open or closed.