DashboardSearch

CommandPaletteGitLab
Um CommandPalette pronto para adicionar ao seu dashboard.

Uso

O componente DashboardSearch estende o componente CommandPalette, então você pode passar qualquer propriedade como icon, placeholder, etc.

Use-o dentro do slot padrão do componente DashboardGroup:

layouts/dashboard.vue
<template>
  <NDashboardGroup>
    <NDashboardSidebar>
      <NDashboardSearchButton />
    </NDashboardSidebar>

    <NDashboardSearch />

    <slot />
  </NDashboardGroup>
</template>
Você pode abrir o CommandPalette pressionando K, usando o componente DashboardSearchButton ou usando uma diretiva v-model:open.

Atalho

Use a prop shortcut para alterar o atalho usado em defineShortcuts para abrir o componente ContentSearch. O padrão é meta_k ( K).

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

Modo de cor

Por padrão, um grupo de comandos será adicionado à paleta de comandos para você alternar entre os modos claro e escuro. Isso só terá efeito se o colorMode não estiver forçado em uma página específica, o que pode ser feito por meio de definePageMeta:

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

Você pode desabilitar esse comportamento definindo a prop color-mode como false:

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

API

Props

Prop Default Type
size'md' "sm" | "md" | "xs" | "lg" | "xl"
closetrueboolean | Omit<ButtonProps, LinkPropsKeys>

Display a close button in the input (useful when inside a Modal for example). { size: 'md', color: 'neutral', variant: 'ghost' }

inputtrueboolean | Omit<InputProps<AcceptableValue, ModelModifiers>, "modelValue" | "defaultValue">

Configure the input or hide it with false. { fixed: true }

shortcut'meta_k' string

Keyboard shortcut to open the search (used by defineShortcuts)

fuse{ fuseOptions: { ignoreLocation: true, useTokenSearch: true, threshold: 0.1, keys: ['label', 'description', 'suffix'] }, resultLimit: 12, matchAllWhenSearchEmpty: true } UseFuseOptions<CommandPaletteItem>

Options for useFuse passed to the CommandPalette.

searchDelay100 number

Delay (in milliseconds) before the search term is passed to Fuse (debounced). Useful for large datasets where running fuzzy search on every keystroke is the bottleneck — the input stays responsive while Fuse only re-runs after typing settles. Set to 0 to disable.

colorModetrueboolean

When true, the theme command will be added to the groups.

title string
transitiontrueboolean

Animate the modal when opening or closing.

description string
overlaytrueboolean

Render an overlay behind the modal.

content DialogContentProps & Partial<EmitsToProps<DialogContentImplEmits>>

The content of the modal.

dismissibletrueboolean

When false, the modal will not close when clicking outside or pressing escape.

fullscreenfalseboolean

When true, the modal will take up the full screen.

modalboolean

The modality of the dialog When set to true,
interaction with outside elements will be disabled and only dialog content will be visible to screen readers.

portaltrue string | false | true | HTMLElement

Render the modal in a portal.

unmountOnHidetrueboolean

When set to false, the dialog content will not be unmounted when closed, but instead hidden with CSS.
Useful for SEO or when you want to improve performance by not remounting the component on every open.

iconappConfig.ui.icons.searchany

The icon displayed in the input. Set to false to hide the icon.

autofocustrueboolean

Automatically focus the input when component is mounted.

disabledboolean

When true, prevents the user from interacting with listbox

trailingIconappConfig.ui.icons.searchany

The icon displayed on the right side of the input.

loadingboolean

When true, the loading icon will be displayed.

loadingIconappConfig.ui.icons.loadingany

The icon when the loading prop is true.

selectedIconappConfig.ui.icons.checkany

The icon displayed when an item is selected.

childrenIconappConfig.ui.icons.chevronRightany

The icon displayed when an item has children.

placeholdert('commandPalette.placeholder') string

The placeholder text for the input.

closeIconappConfig.ui.icons.closeany

The icon displayed in the close button.

backtrueboolean | Omit<ButtonProps, LinkPropsKeys>

Display a button to navigate back in history. { size: 'md', color: 'neutral', variant: 'link' }

backIconappConfig.ui.icons.arrowLeftany

The icon displayed in the back button.

highlightOnHoverboolean

When true, hover over item will trigger highlight

labelKey'label' string

The key used to get the label from the item.

descriptionKey'description' string

The key used to get the description from the item.

preserveGroupOrderfalseboolean

Whether to preserve the order of groups as defined in the groups prop when filtering. When false, groups will appear based on item matches.

virtualizefalseboolean | { overscan?: number ; estimateSize?: number | ((index: number) => number) | undefined; } | undefined

Enable virtualization for large lists. Note: when enabled, all groups are flattened into a single list due to a limitation of Reka UI (https://github.com/unovue/reka-ui/issues/1885).

groups CommandPaletteGroup<CommandPaletteItem>[]
openfalseboolean
searchTerm'' string
ui { modal?: SlotClass; input?: SlotClass; } & { root?: SlotClass; input?: SlotClass; close?: SlotClass; back?: SlotClass; content?: SlotClass; footer?: SlotClass; viewport?: SlotClass; group?: SlotClass; empty?: SlotClass; label?: SlotClass; item?: SlotClass; itemLeadingIcon?: SlotClass; itemLeadingAvatar?: SlotClass; itemLeadingAvatarSize?: SlotClass; itemLeadingChip?: SlotClass; itemLeadingChipSize?: SlotClass; itemTrailing?: SlotClass; itemTrailingIcon?: SlotClass; itemTrailingHighlightedIcon?: SlotClass; itemTrailingKbds?: SlotClass; itemTrailingKbdsSize?: SlotClass; itemWrapper?: SlotClass; itemLabel?: SlotClass; itemLabelBase?: SlotClass; itemLabelPrefix?: SlotClass; itemLabelSuffix?: SlotClass; itemDescription?: SlotClass; }

Slots

Slot Type
empty{ searchTerm: string; }
footer{ ui: object; }
back{ ui: object; }
close{ ui: object; }
item{ item: CommandPaletteItem; index: number; ui: object; }
item-leading{ item: CommandPaletteItem; index: number; ui: object; }
item-label{ item: CommandPaletteItem; index: number; ui: object; }
item-description{ item: CommandPaletteItem; index: number; ui: object; }
item-trailing{ item: CommandPaletteItem; index: number; ui: object; }
group-label{ group: CommandPaletteGroup<CommandPaletteItem>; label: string; ui: object; }
content{ close: () => void; }

Emits

Event Type
update:open[value: boolean]
update:searchTerm[value: string]

Expose

Ao acessar o componente por meio de um template ref, você pode usar o seguinte:

NameType
commandPaletteRefRef<InstanceType<typeof UCommandPalette> | null>

Tema

app.config.ts
export default defineAppConfig({
  ui: {
    dashboardSearch: {
      slots: {
        modal: '',
        input: ''
      },
      variants: {
        fullscreen: {
          false: {
            modal: 'sm:max-w-3xl h-full sm:h-[28rem]'
          }
        },
        size: {
          xs: {},
          sm: {},
          md: {},
          lg: {},
          xl: {}
        }
      },
      defaultVariants: {
        size: 'md'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        dashboardSearch: {
          slots: {
            modal: '',
            input: ''
          },
          variants: {
            fullscreen: {
              false: {
                modal: 'sm:max-w-3xl h-full sm:h-[28rem]'
              }
            },
            size: {
              xs: {},
              sm: {},
              md: {},
              lg: {},
              xl: {}
            }
          },
          defaultVariants: {
            size: 'md'
          }
        }
      }
    })
  ]
})

Changelog

No recent changes