仪表盘导航栏

GitHub
一个用于在仪表盘中显示的响应式导航栏。

用法

DashboardNavbar 组件是一个响应式导航栏,它与 DashboardSidebar 组件集成。它包含一个移动端切换按钮,用于在仪表盘布局中实现响应式导航。

DashboardPanel 组件的 header 插槽中使用它。

pages/index.vue
<script setup lang="ts">
definePageMeta({
  layout: 'dashboard'
})
</script>

<template>
  <UDashboardPanel>
    <template #header>
      <UDashboardNavbar />
    </template>
  </UDashboardPanel>
</template>

使用 leftdefaultright 插槽来定制导航栏。

收件箱

4
<script setup lang="ts">
import type { TabsItem } from '@nuxt/ui'

const items: TabsItem[] = [
  {
    label: 'All',
    value: 'all'
  },
  {
    label: 'Unread',
    value: 'unread'
  }
]
</script>

<template>
  <UDashboardNavbar title="Inbox">
    <template #leading>
      <UDashboardSidebarCollapse />
    </template>

    <template #trailing>
      <UBadge label="4" variant="subtle" />
    </template>

    <template #right>
      <UTabs :items="items" default-value="all" size="sm" class="w-40" :content="false" />
    </template>
  </UDashboardNavbar>
</template>
在此示例中,我们在右侧插槽中使用 Tabs 组件来显示一些选项卡。

标题

使用 title prop 来设置导航栏的标题。

Dashboard

<template>
  <UDashboardNavbar title="Dashboard" />
</template>

Icon

使用 icon prop 来设置导航栏的图标。

Dashboard

<template>
  <UDashboardNavbar title="Dashboard" icon="i-lucide-house" />
</template>

Toggle

使用 toggle prop 来自定义在移动端显示的切换按钮,该按钮用于打开 DashboardSidebar 组件。

您可以传递 Button 组件的任何属性来自定义它。

<template>
  <UDashboardNavbar
    title="Dashboard"
    :toggle="{
      color: 'primary',
      variant: 'subtle',
      class: 'rounded-full'
    }"
  />
</template>

切换侧边

使用 toggle-side prop 来更改切换按钮的边。默认为 right

<template>
  <UDashboardNavbar
    title="Dashboard"
    toggle-side="right"
  />
</template>

API

属性

属性默认值类型
as

'div'

any

此组件应渲染为的元素或组件。

图标

字符串 | 对象

显示在标题旁边的图标。

title

string

toggle

true

布尔值 | 部分<ButtonProps>

自定义切换按钮以打开侧边栏。 { color: 'neutral', variant: 'ghost' }

toggleSide

'left'

"right" | "left"

渲染切换按钮的侧边位置。

ui

{ root?: ClassNameValue; left?: ClassNameValue; icon?: ClassNameValue; title?: ClassNameValue; center?: ClassNameValue; right?: ClassNameValue; toggle?: ClassNameValue; }

插槽

插槽类型
title

{}

前置

DashboardNavbarSlotsProps

尾部

DashboardNavbarSlotsProps

left

DashboardNavbarSlotsProps

default

DashboardNavbarSlotsProps

right

DashboardNavbarSlotsProps

toggle

DashboardNavbarSlotsProps

主题

app.config.ts
export default defineAppConfig({
  ui: {
    dashboardNavbar: {
      slots: {
        root: 'h-(--ui-header-height) shrink-0 flex items-center justify-between border-b border-default px-4 sm:px-6 gap-1.5',
        left: 'flex items-center gap-1.5 min-w-0',
        icon: 'shrink-0 size-5 self-center me-1.5',
        title: 'flex items-center gap-1.5 font-semibold text-highlighted truncate',
        center: 'hidden lg:flex',
        right: 'flex items-center shrink-0 gap-1.5',
        toggle: ''
      },
      variants: {
        toggleSide: {
          left: {
            toggle: ''
          },
          right: {
            toggle: ''
          }
        }
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        dashboardNavbar: {
          slots: {
            root: 'h-(--ui-header-height) shrink-0 flex items-center justify-between border-b border-default px-4 sm:px-6 gap-1.5',
            left: 'flex items-center gap-1.5 min-w-0',
            icon: 'shrink-0 size-5 self-center me-1.5',
            title: 'flex items-center gap-1.5 font-semibold text-highlighted truncate',
            center: 'hidden lg:flex',
            right: 'flex items-center shrink-0 gap-1.5',
            toggle: ''
          },
          variants: {
            toggleSide: {
              left: {
                toggle: ''
              },
              right: {
                toggle: ''
              }
            }
          }
        }
      }
    })
  ]
})

更新日志

61b60— 功能:允许传递组件而不是名称 (#4766)

5cb65— 特性:导入 @nuxt/ui-pro 组件