nb-modal

This is a modal component for Vue.js 3+. It displays a centered modal dialog with customizable themes, responsive breakpoints, backdrop blur, and overlay effects.

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 NbModal or nb-modal.

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

Mode 1
<template>
  <NbModal nb-id="modal-1" :show="isModalOpen" @close="isModalOpen = false">
    <template #content="{ closeModal }">
      <p>Modal content here</p>
      <button @click="closeModal">Close</button>
    </template>
  </NbModal>
</template>
Mode 2
<template>
  <nb-modal nb-id="modal-1" :show="isModalOpen" @close="isModalOpen = false">
    <template #content="{ closeModal }">
      <p>Modal content here</p>
      <button @click="closeModal">Close</button>
    </template>
  </nb-modal>
</template>
Mode 3
<template>
  <nb-modal nb-id="modal-1" :show="isModalOpen" @close="isModalOpen = false">
    <template #content="{ closeModal }">
      <p>Modal content here</p>
      <button @click="closeModal">Close</button>
    </template>
  </nb-modal>
</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 modal 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
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)
hasBackdropBlurBooleantrueDefines if the backdrop should have a blur effect
backdropBlurNumber5Defines the blur intensity in pixels for the backdrop
overlayClickEffectBooleantrueDefines if clicking the overlay should trigger a zoom effect on the modal
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
closeOnOverlayClickBooleanfalseDefines if clicking the overlay should close the modal
contentPaddingString'10px'Defines the padding of the content area
disabledBooleanfalseDefines if the modal is disabled
visibleOnMobileBooleantrueDefines if the modal should be visible on mobile breakpoints
visibleOnTabletBooleantrueDefines if the modal should be visible on tablet breakpoints
visibleOnDesktopBooleantrueDefines if the modal should be visible on desktop breakpoints
scrollableBodyBooleanfalseDefines if the body should remain scrollable when modal is open
minWidthContentSizeNumber225Defines the minimum width of the modal content in pixels
maxWidthContentSizeNumber800Defines the maximum width of the modal content in pixels
minHeightContentSizeNumber100Defines the minimum height of the modal content in pixels
maxHeightContentSizeNumber300Defines the maximum height of the modal 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
fontFamilyString'Lato, sans-serif'Defines the font family for the modal
fontSizeString'1.6em'Defines the font size for the modal
fontWeightNumber400Defines the font weight for the modal
dropdownScrollClassString''Defines a custom CSS class for the scrollable content area (useful for custom scrollbar styling)
borderRadiusNumber0Defines the border radius of the modal in rem units (0-2)
zIndexNumber2147483640Defines the z-index for the backdrop overlay. The modal 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
lightBackgroundColorString'#f5f5f5'Defines the background 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
darkBackgroundColorString'#2d2d2d'Defines the background color for dark theme

Slots

nameDescription
contentMain content area of the modal. Receives closeModal function as a slot prop to programmatically close the modal
close-buttonCustom close button content (replaces the default "✕")

Events

nameReturn typeDescription
closenothingFired when the modal 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 modal's visibility state.

Usage in child components

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

const showSidebar = inject('showSidebar')

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

// Access the modal 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 modal is open or closed.