仪表盘搜索

一个随时可用的命令面板,可添加到您的仪表盘中。

用法

DashboardSearch 组件扩展了 CommandPalette 组件,因此您可以传递任何属性,例如 iconplaceholder 等。

将其用在 DashboardGroup 组件的默认插槽中。

layouts/dashboard.vue
<template>
  <UDashboardGroup>
    <UDashboardSidebar>
      <UDashboardSearchButton />
    </UDashboardSidebar>

    <UDashboardSearch />

    <slot />
  </UDashboardGroup>
</template>
您可以通过按 K、使用 DashboardSearchButton 组件或使用 v-model:open 指令来打开 CommandPalette。

快捷键

使用 shortcut 属性来更改 defineShortcuts 中用于打开 ContentSearch 组件的快捷键。默认值为 meta_k K)。

app.vue
<template>
  <UDashboardSearch
    v-model:search-term="searchTerm"
    shortcut="meta_k"
    :groups="groups"
    :fuse="{ resultLimit: 42 }"
  />
</template>

颜色模式

默认情况下,一组命令将被添加到命令面板,以便您可以切换浅色和深色模式。只有在特定页面未强制设置 colorMode 时,此行为才会生效,可以通过 definePageMeta 实现。

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

您可以将 color-mode 属性设置为 false 来禁用此行为。

app.vue
<template>
  <UDashboardSearch
    v-model:search-term="searchTerm"
    :color-mode="false"
    :groups="groups"
    :fuse="{ resultLimit: 42 }"
  />
</template>

API

属性

属性默认值类型
图标

appConfig.ui.icons.search

字符串 | 对象

输入框中显示的图标。

placeholder

t('commandPalette.placeholder')

string

输入框的占位文本。

autofocus

true

boolean

组件挂载时自动聚焦输入框。

loading

boolean

当为 true 时,将显示加载图标。

loadingIcon

appConfig.ui.icons.loading

字符串 | 对象

loading prop 为 true 时显示的图标。

close

true

布尔值 | 部分<ButtonProps>

在输入框中显示一个关闭按钮(例如,在模态框中很有用)。{ size: 'md', color: 'neutral', variant: 'ghost' }

closeIcon

appConfig.ui.icons.close

字符串 | 对象

关闭按钮中显示的图标。

shortcut

'meta_k'

string

用于打开搜索的键盘快捷键(由defineShortcuts)

分组

CommandPaletteGroup<CommandPaletteItem>[]

fuse

{}

UseFuseOptions<CommandPaletteItem>

用于 `useFuse` 的选项useFuse传递给CommandPalette.

colorMode

true

boolean

如果为 true,则主题命令将添加到组中。

portal

true

string | false | true | HTMLElement

在传送门中渲染模态框。

内容

DialogContentProps & Partial<EmitsToProps<DialogContentImplEmits>>

模态框的内容。

description

string

title

string

叠加层

true

boolean

在模态框后面渲染一个叠加层。

过渡动画

true

boolean

在打开或关闭时为模态框添加动画效果。

可关闭的

true

boolean

当为 false 时,点击外部或按下 Escape 键时模态框将不会关闭。

全屏

false

boolean

当为 true 时,模态框将占据整个屏幕。

modal

boolean

对话框的模态性。当设置为 true 时,
与外部元素的交互将被禁用,并且只有对话框内容对屏幕阅读器可见。

open

false

boolean

搜索词

''

string

ui

{ modal?: ClassNameValue; input?: ClassNameValue; } &{ root?: ClassNameValue; input?: ClassNameValue; close?: ClassNameValue; back?: ClassNameValue; content?: ClassNameValue; footer?: ClassNameValue; viewport?: ClassNameValue; group?: ClassNameValue; empty?: ClassNameValue; label?: ClassNameValue; item?: ClassNameValue; itemLeadingIcon?: ClassNameValue; itemLeadingAvatar?: ClassNameValue; itemLeadingAvatarSize?: ClassNameValue; itemLeadingChip?: ClassNameValue; itemLeadingChipSize?: ClassNameValue; itemTrailing?: ClassNameValue; itemTrailingIcon?: ClassNameValue; itemTrailingHighlightedIcon?: ClassNameValue; itemTrailingKbds?: ClassNameValue; itemTrailingKbdsSize?: ClassNameValue; itemLabel?: ClassNameValue; itemLabelBase?: ClassNameValue; itemLabelPrefix?: ClassNameValue; itemLabelSuffix?: ClassNameValue; }

插槽

插槽类型

{ searchTerm?: string | undefined; }

页脚

{ ui: {}; }

返回

{ ui: {}; }

close

{ ui: {}; }

item

{ item: CommandPaletteItem; index: number; }

item-leading

{ item: CommandPaletteItem; index: number; }

item-label

{ item: CommandPaletteItem; index: number; }

item-trailing

{ item: CommandPaletteItem; index: number; }

内容

{}

事件

事件类型
update:open

[value: boolean]

update:searchTerm

[value: string]

主题

app.config.ts
export default defineAppConfig({
  ui: {
    dashboardSearch: {
      slots: {
        modal: '',
        input: '[&>input]:text-base/5'
      },
      variants: {
        fullscreen: {
          false: {
            modal: 'sm:max-w-3xl sm:h-[28rem]'
          }
        }
      }
    }
  }
})
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: {
        dashboardSearch: {
          slots: {
            modal: '',
            input: '[&>input]:text-base/5'
          },
          variants: {
            fullscreen: {
              false: {
                modal: 'sm:max-w-3xl sm:h-[28rem]'
              }
            }
          }
        }
      }
    })
  ]
})

更新日志

095a0— fix: proxy modal props to support fullscreen

3173b— fix: proxySlots 响应性 (#4969)

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

946c2— fix: make ui.modal work

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