Nuxt UI Dashboard Template

repository·main·Indexed 40 days ago

https://github.com/nuxt-ui-templates/dashboard-vue

A professional Vite + Vue dashboard template powered by Nuxt UI. It provides a foundation for admin interfaces featuring a command palette, collapsible sidebar, dark mode support, and a useDashboard composable for global state management.

Tokens
1.8K
Snippets
10
Records
10
Agent score
51%

What's inside Nuxt UI Dashboard Template

  1. Quick Start with the Vue Dashboard Template

    main

    You can scaffold a new project using this dashboard template by running the Nuxt creation command with the specific template flag. This will set up a Vite + Vue dashboard featuring multiple pages, a collapsible sidebar, keyboard shortcuts, light/dark mode, and a command palette, all powered by Nuxt UI.

    npm create nuxt@latest -- --no-modules -t ui-vue/dashboard
  2. Configure better-tailwindcss ESLint settings

    main

    The project uses eslint-plugin-better-tailwindcss to enforce Tailwind CSS best practices. You can customize the plugin's behavior via the settings['better-tailwindcss'] object in your ESLint configuration.

    Key configuration options:

    • entryPoint: The path to your main CSS file where Tailwind directives are defined.
    • attributes: An array of Tailwind-related attributes to validate. You can use getDefaultAttributes() to include standard Tailwind attributes and append custom patterns.

    Example of adding a custom attribute pattern for v-bind:ui to match objectValues:

    settings: {
      'better-tailwindcss': {
        entryPoint: 'src/assets/css/main.css',
        attributes: [
          ...getDefaultAttributes(),
          ['^v-bind:ui$', [{ match: 'objectValues' }]]
        ]
      }
    }
  3. Configure Vue and TypeScript ESLint rules

    main

    The project uses a flat configuration combining typescript-eslint and eslint-plugin-vue. To maintain compatibility with the dashboard template's component structure, the following rule overrides are applied:

    • vue/multi-word-component-names: Set to 'off' to allow single-word component names.
    • vue/max-attributes-per-line: Set to an error with a limit of 3 attributes on a single line.
    • no-undef: Set to 'off' (typically to avoid conflicts with TypeScript's own type checking).

    Vue files are parsed using @typescript-eslint/parser to ensure proper type handling within <script> blocks.

    {
      files: ['*.vue', '**/*.vue'],
      languageOptions: {
        parserOptions: {
          parser: '@typescript-eslint/parser'
        }
      },
      rules: {
        'vue/multi-word-component-names': 'off',
        'vue/max-attributes-per-line': ['error', { singleline: 3 }],
        'no-undef': 'off'
      }
    }
  4. Use the useDashboard composable for global dashboard state

    main

    The useDashboard composable provides shared global state for the dashboard, specifically managing the visibility of the notifications slideover. Because it is created using createSharedComposable, the state is shared across all components that call it within the same application instance.

    Key Features

    • Notifications State: Access and control the isNotificationsSlideoverOpen boolean ref.
    • Keyboard Shortcuts: The dashboard includes several built-in shortcuts:
      • g-h: Navigate to Home (/)
      • g-i: Navigate to Inbox (/inbox)
      • g-c: Navigate to Customers (/customers)
      • g-s: Navigate to Settings (/settings)
      • n: Toggle the notifications slideover
    • Automatic Reset: The notifications slideover is automatically closed whenever the route changes.
    import { useDashboard } from '~/composables/useDashboard'
    
    const { isNotificationsSlideoverOpen } = useDashboard()
    
    // Example: Toggling the slideover manually
    const toggleNotifications = () => {
      isNotificationsSlideoverOpen.value = !isNotificationsSlideoverOpen.value
    }
  5. Define Mail, Notification, and Period types

    main

    Communication and time-based filtering are handled by Mail, Notification, and Period types. Mail and Notification both track unread status and include timestamps and sender/user information.

    export interface Mail {
      id: number
      unread?: boolean
      from: User
      subject: string
      body: string
      date: string
    }
    
    export interface Notification {
      id: number
      unread?: boolean
      sender: User
      body: string
      date: string
    }
    
    export type Period = 'daily' | 'weekly' | 'monthly'
  6. Define User and Member data structures

    main

    The template uses specific interfaces for user-related data. A User includes identity details and a UserStatus, while a Member represents a user within a specific context (like an organization) with a defined role. Note that avatar properties use the AvatarProps type from @nuxt/ui.

    export type UserStatus = 'subscribed' | 'unsubscribed' | 'bounced'
    
    export interface User {
      id: number
      name: string
      email: string
      avatar?: AvatarProps
      status: UserStatus
      location: string
    }
    
    export interface Member {
      name: string
      username: string
      role: 'member' | 'owner'
      avatar: AvatarProps
    }
  7. Define Sale and Stat data structures

    main

    For financial or dashboard metrics, use the Sale and Stat interfaces. Sale tracks transaction status via SaleStatus, and Stat provides a structure for dashboard cards, including an optional formatter function to customize how numeric values are displayed.

    export type SaleStatus = 'paid' | 'failed' | 'refunded'
    
    export interface Sale {
      id: string
      date: string
      status: SaleStatus
      email: string
      amount: number
    }
    
    export interface Stat {
      title: string
      icon: string
      value: number | string
      variation: number
      formatter?: (value: number) => string
    }