DXDashboard

DXDashboard

Complete dashboard layout component that combines sidebar navigation, top navbar, and content area. Handles all state management and provides extensive customisation through slots.

Live Examples

Props

Name Click to sort ascendingType Required Click to sort ascendingDefault Description
navigationNavigationNorequiredNavigation structure with groups and items
currentUrlstringNorequiredCurrent URL path for active state detection
titlestringNo'Dashboard'Dashboard title shown in sidebar brand
pageTitlestringNo''Page title shown in navbar
fluidbooleanNofalseRender page content full-width and left-aligned instead of the default centred, reading-width column. For wide tables / admin pages
contentMaxWidthstringNo'1140px'Max width of the centred content column (any CSS length) — a genuine cap so pages don’t stretch to ~2000px on a wide display. Ignored when fluid
contentClassstringNo-Extra class(es) applied to the content container/column
user{ name: string; email: string } | nullNonullUser object for navbar dropdown
searchAlign'start' | 'center'No'start'Horizontal alignment of the navbar search slot content (start = flush left, center = centred), forwarded to DXDashboardNavbar
actionsOnMobile'wrap' | 'hide'No'wrap'What the navbar actions slot does below md: wrap moves it to its own full-width row, hide removes it (relocate actions into the page on phones). Forwarded to DXDashboardNavbar
sidebarVariant'light' | 'dark'No'light'Sidebar colour scheme, forwarded to DXDashboardSidebar as variant. light: white pane, tinted group-header pills, green active item, Poppins. dark: the navy rail. Rebrand either through the --dx-sidebar-* custom properties (theming guide)
storageKeystringNo'dashboard-sidebar-hidden'LocalStorage key for sidebar state persistence. Desktop only: below 576px the menu always starts closed and its toggles are not saved

Slots

Name Click to sort ascendingDescription Scoped Props
defaultMain page content rendered in the content area-
sidebar-brandCustom brand/logo content for sidebar header-
sidebar-linkCustom link rendering in sidebar navigation-
sidebar-footerUtility links pinned to the bottom of the sidebar (help, changelog, sign-out, …)-
navbar-menu-iconCustom hamburger menu icon for navbar-
navbar-searchCustom search component for navbar-
navbar-actionsPage-level primary actions (e.g. a Create button). Right-aligned next to the user menu from md up; below, wraps to its own full-width row or is hidden entirely per actionsOnMobile-
navbar-user-iconCustom user icon/avatar in navbar dropdown (defaults to DXUserAvatar)-
navbar-user-menuReplaces the whole user menu (the default avatar dropdown)-
navbar-user-menu-itemsItems for the default user dropdown menu-

Every forwarded sidebar-* and navbar-* slot also receives toggleSidebar and sidebarHidden on top of the underlying slot’s own bindings — see Controlling the sidebar.

The slots are typed (DashboardSlots, exported from the package), so your editor completes the slot names and their props, and vue-tsc checks how you use the props. Only the prefixed names are forwarded. A slot named after the child’s own slot goes nowhere: nothing renders, and vue-tsc does not report it either (Vue allows any slot name on any component), so the editor’s completion list is the place to check.

<DXDashboard :navigation="navigation" current-url="/orders">
  <!-- Wrong: DXDashboard has no `search` slot, so this renders nothing -->
  <template #search>
    <OrderSearch />
  </template>

  <!-- Right: `navbar-search` is forwarded to the navbar's `search` slot -->
  <template #navbar-search>
    <OrderSearch />
  </template>
</DXDashboard>

Your own navigation item type

sidebar-link’s item has the type of the items you pass in navigation, so keys your backend adds to each item (a permission, a route name) are typed in the slot, and a misspelt key is still an error. Type the navigation with Navigation<YourItem>, or let TypeScript infer it from a literal:

<script setup lang="ts">
import { DXDashboard } from '@omnitend/dashboard-for-laravel';
import type { Navigation, NavigationItem } from '@omnitend/dashboard-for-laravel';

interface AppNavigationItem extends NavigationItem {
  permission: string;
}

const navigation: Navigation<AppNavigationItem> = [
  { label: 'Admin', items: [{ label: 'Users', url: '/users', permission: 'users.view' }] },
];

// Your app's permission check (from page props, a store, ...).
const userPermissions: string[] = ['users.view'];
const can = (permission: string): boolean => userPermissions.includes(permission);
</script>

<template>
  <DXDashboard :navigation="navigation" current-url="/users">
    <template #sidebar-link="{ item }">
      <!-- item is an AppNavigationItem: item.permission is a string -->
      <a v-if="can(item.permission)" :href="item.url">{{ item.label }}</a>
    </template>
  </DXDashboard>
</template>

A plain Navigation (or []) gives a NavigationItem. Navigation typed any (page props you have not typed) gives an any item, so nothing is checked. DXDashboardSidebar’s link slot works the same way.

The user may be null

navbar-user-menu replaces the whole user menu, so it also renders for a guest: its user is DashboardUser | null, and vue-tsc asks you to handle the null case (user?.name, or a v-if). navbar-user-icon and navbar-user-menu-items only render for a signed-in user, so their user is never null.

Features

  • Combined Layout - Integrates DXDashboardSidebar and DXDashboardNavbar
  • State Management - Handles sidebar toggle and localStorage persistence
  • Responsive - A rail beside the page from 576px up; a full-screen menu on phones (see On phones)
  • Customisable - Extensive slot system for customisation
  • Type-Safe - Full TypeScript support with proper types

Usage Example

Basic Usage

<template>
  <DXDashboard
    :navigation="navigation"
    :current-url="route.path"
    title="My Application"
    :page-title="pageTitle"
    :user="authUser"
  >
    <!-- Your page content here -->
    <h1>Welcome to the Dashboard</h1>
  </DXDashboard>
</template>

<script setup lang="ts">
import { DXDashboard } from '@omnitend/dashboard-for-laravel';

const navigation = [
  {
    label: 'Main',
    items: [
      { label: 'Dashboard', url: '/dashboard' },
      { label: 'Customers', url: '/customers' },
    ],
  },
];

const authUser = { name: 'John Doe', email: 'john@example.com' };
const pageTitle = 'Dashboard';
</script>

With Icons

Navigation items can include icons using unplugin-icons or any Vue component:

<script setup lang="ts">
import { DXDashboard } from '@omnitend/dashboard-for-laravel';
import IconHome from '~icons/lucide/home';
import IconUsers from '~icons/lucide/users';
import IconSettings from '~icons/lucide/settings';

const navigation = [
  {
    items: [
      { label: 'Dashboard', url: '/dashboard', icon: IconHome },
      { label: 'Customers', url: '/customers', icon: IconUsers },
    ],
  },
  {
    label: 'Settings',
    items: [
      { label: 'Preferences', url: '/settings', icon: IconSettings },
    ],
  },
];
</script>

Icon Setup (unplugin-icons):

Install packages:

npm install --save-dev unplugin-icons @iconify-json/lucide

Configure in vite.config.ts:

import Icons from 'unplugin-icons/vite';

export default defineConfig({
  plugins: [
    Icons({
      compiler: 'vue3',
    }),
  ],
});

Then import icons using the ~icons/ prefix:

import IconName from '~icons/lucide/icon-name';

Custom Branding

<DXDashboard :navigation="navigation" current-url="/dashboard">
  <template #sidebar-brand="{ collapsed }">
    <div class="d-flex align-items-center">
      <img v-if="!collapsed" src="/logo.svg" alt="Logo" />
      <span v-else>L</span>
    </div>
  </template>

  <!-- content -->
</DXDashboard>

Controlling the sidebar

DXDashboard owns the sidebar’s visibility state (and persists it to localStorage), so it exposes that state rather than leaving you to click the navbar’s hamburger from script.

Every forwarded sidebar-* and navbar-* slot receives two extra bindings:

  • toggleSidebar — shows/hides the sidebar (the same action as the navbar’s hamburger).
  • sidebarHidden — whether the sidebar is currently hidden.

Use them to put a close affordance in the sidebar itself, or a toggle among the navbar actions:

<DXDashboard :navigation="navigation" current-url="/dashboard">
  <template #sidebar-brand="{ collapsed, toggleSidebar }">
    <div class="d-flex align-items-center justify-content-between w-100">
      <img v-if="!collapsed" src="/logo.svg" alt="Logo" />
      <DButton
        variant="link"
        aria-label="Close sidebar"
        @click="toggleSidebar"
      >
        &times;
      </DButton>
    </div>
  </template>

  <template #navbar-actions="{ toggleSidebar, sidebarHidden }">
    <DButton size="sm" variant="outline-secondary" @click="toggleSidebar">
      {{ sidebarHidden ? 'Show menu' : 'Hide menu' }}
    </DButton>
  </template>
</DXDashboard>

The same API is available on a template ref, for page content or a keyboard shortcut that sits outside those slots. useTemplateRef('name') types it from the component with nothing extra to install:

<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { DButton, DXDashboard } from '@omnitend/dashboard-for-laravel';
import type { Navigation } from '@omnitend/dashboard-for-laravel';

const navigation: Navigation = [
  { items: [{ label: 'Dashboard', url: '/dashboard' }] },
];

// Typed from the component: toggleSidebar(), sidebarHidden and el.
const dashboard = useTemplateRef('dashboardRef');

const toggle = () => dashboard.value?.toggleSidebar();

// The root DOM element (`HTMLElement | null`) is the exposed `el`.
const layoutElement = () => dashboard.value?.el ?? null;
</script>

<template>
  <DXDashboard ref="dashboardRef" :navigation="navigation" current-url="/dashboard">
    <DButton @click="toggle">
      {{ dashboard?.sidebarHidden ? 'Show menu' : 'Hide menu' }}
    </DButton>
  </DXDashboard>
</template>

DXDashboard is a generic component (over its navigation type), so a ref to it carries only what it exposes: toggleSidebar, sidebarHidden and el. There is no $el or $props; read the root element through el, which is null before mount. InstanceType<typeof DXDashboard> does not compile. If you need the ref’s type by name (a prop, a ref<...>()), the optional alternative is ComponentExposed<typeof DXDashboard> from the vue-component-type-helpers package, which you have to install yourself.

On phones

Below Bootstrap’s sm breakpoint (576px) the open sidebar covers the whole screen instead of squeezing the page beside it, and it behaves as a menu:

  • It always starts closed. The visibility saved under storageKey is a desktop preference, so it is neither applied nor overwritten on a phone. An app that navigates with full page loads would otherwise reopen the menu over every page the user tapped through to.
  • Following a link in it closes it (including links in the sidebar-link, sidebar-brand and sidebar-footer slots, and client-side router links that cancel the click), as do Escape and the close button in its header, which shows only at this width because the menu covers the navbar’s toggle.
  • Opening it moves keyboard focus into it and makes the navbar and page behind it inert, so, as with a native modal <dialog>, Tab moves between the menu’s controls and the browser’s own and never reaches what the menu covers. A modal opened from the menu keeps its own Tab order. Closing it returns focus to the navbar toggle, whose aria-expanded follows the sidebar.
  • While it is open, <html> carries dx-dashboard-menu-open and the page behind it does not scroll. Several dashboards on one page each hold their own share of that lock, and a dashboard cached by <KeepAlive> closes its menu and releases the lock when deactivated.
  • A server-rendered dashboard hydrates with the menu closed and never paints it open before hydration.

From 576px up nothing changes: the sidebar is a rail beside the page and its state is remembered. Crossing the breakpoint (rotating a tablet, resizing a window) closes the menu on the way down and restores the remembered state on the way up. The theme publishes the breakpoint as --dx-dashboard-phone-max-width (from $grid-breakpoints) and DXDashboard reads it whenever it decides (so also when the stylesheet loads after the dashboard), so a theme compiled with its own sm moves the behaviour and the full-screen styles together (575.98px if the theme’s CSS is not loaded).

These are DXDashboard’s: a DXDashboardSidebar used on its own keeps its rail on phones unless given phone-menu, whose owner must then close it.

Notes

This component requires CSS for sidebar visibility control. Add this to your global styles or layout:

.dashboard-sidebar {
  display: none !important;
}

html.sidebar-visible .dashboard-sidebar {
  display: block !important;
}

For Astro projects with SSR, add an inline script to prevent flicker. It reads the phone width from the theme’s --dx-dashboard-phone-max-width, as DXDashboard does, so a theme with its own sm breakpoint keeps the two in step. That only works once the theme’s stylesheet has loaded: put the script after the stylesheet’s <link> (an inline script waits for the stylesheets above it). Astro emits its stylesheet links after the layout’s own <head> content, so put it at the start of <body>. Anywhere earlier, the property reads as empty and the script falls back to 575.98px, the default theme’s value, so with a custom breakpoint the first paint can be wrong (DXDashboard corrects it when it mounts).

<script is:inline>
  (function() {
    try {
      const hidden = localStorage.getItem('dashboard-sidebar-hidden');
      // Phones always start with the menu closed (see "On phones").
      const phoneMaxWidth = getComputedStyle(document.documentElement)
        .getPropertyValue('--dx-dashboard-phone-max-width')
        .trim() || '575.98px';
      const isPhone = window.matchMedia('(max-width: ' + phoneMaxWidth + ')').matches;
      if (hidden === 'false' && !isPhone) {
        document.documentElement.classList.add('sidebar-visible');
      }
    } catch (e) {}
  })();
</script>