仪表板导航栏

GitHub
在仪表板中显示的响应式导航栏。

用法

DashboardNavbar组件是与DashboardSidebar组件集成的响应式导航栏。它包括一个移动的切换按钮,用于在仪表板布局中启用响应式导航。

请在仪表板面板组件的header插槽中使用该工具:

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

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

使用left、default和right插槽自定义导航栏。

Inbox

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道具设置导航栏的标题。

Dashboard

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

图标

使用icon道具设置导航栏的图标。

Dashboard

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

切换

使用toggle属性自定义移动的上显示的切换按钮,该按钮用于打开DashboardSidebar组件。

您可以从Button组件传递任何属性,以自订该组件。

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

切换侧边

使用toggle-side属性来变更切换按钮的边。预设为right。

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

应用程序接口

道具

Prop Default Type
as
'div'
any

The element or component this component should render as.

icon
any

The icon displayed next to the title.

title
string
toggle
true
boolean | Omit<ButtonProps, LinkPropsKeys>

Customize the toggle button to open the sidebar. { color: 'neutral', variant: 'ghost' }

toggleSide
'left'
"left" | "right"

The side to render the toggle button on.

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

x插槽

Slot Type
title
{}
leading
DashboardNavbarSlotsProps & { ui: object; }
trailing
DashboardNavbarSlotsProps & { ui: object; }
left
DashboardNavbarSlotsProps
default
DashboardNavbarSlotsProps
right
DashboardNavbarSlotsProps
toggle
DashboardNavbarSlotsProps & { ui: object; }

主题

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: ''
              }
            }
          }
        }
      }
    })
  ]
})

更改日志

No recent changes