内容搜索按钮

ButtonGitHub
一个预设样式的按钮,用于打开内容搜索模态框。
此组件仅在安装了 @nuxt/content 模块时可用。

用法

ContentSearchButton 组件用于打开 ContentSearch 模态框。

<template>
  <UContentSearchButton />
</template>

它继承自 Button 组件,因此你可以传递任何属性,例如 colorvariantsize 等。

<template>
  <UContentSearchButton variant="subtle" />
</template>
当未折叠时,按钮默认 color="neutral"variant="outline";当折叠时,默认 variant="ghost"

折叠

使用 collapsed 属性显示按钮的标签和键盘按键。默认为 true

<template>
  <UContentSearchButton :collapsed="false" />
</template>

键盘按键

使用 kbds 属性在按钮中显示键盘按键。默认为 ['meta', 'K'],以匹配 ContentSearch 组件的默认快捷方式。

<template>
  <UContentSearchButton :collapsed="false" :kbds="['alt', 'O']" />
</template>

API

属性

属性默认值类型
as'button'any

此组件在不是链接时应呈现的元素或组件。

图标appConfig.ui.icons.searchany

按钮中显示的图标。

labelt('contentSearchButton.label')string

按钮中显示的标签。

color'neutral'"错误" | "中性" | "主要" | "次要" | "成功" | "信息" | "警告"

按钮的颜色。

variant"solid" | "outline" | "soft" | "subtle" | "ghost" | "link"

按钮的变体。未折叠时默认为 'outline',折叠时默认为 'ghost'。

collapsedtrueboolean

按钮是否折叠。

tooltipfalseboolean | TooltipProps

当按钮折叠时,显示带有按钮标签的工具提示。这优先于全局 tooltip 属性。

键盘按键["meta", "k"](string | undefined)[] | KbdProps[]

要在按钮中显示的键盘按键。{ variant: 'subtle' }

autofocusfalse | true | "true" | "false"
disabledboolean
namestring
type'button'"reset" | "submit" | "button"

当不是链接时,按钮的类型。

activeColor"错误" | "中性" | "主要" | "次要" | "成功" | "信息" | "警告"
activeVariant"solid" | "outline" | "soft" | "subtle" | "ghost" | "link"
尺寸'md'"xs" | "sm" | "md" | "lg" | "xl"
正方形boolean

以四边等距内边距渲染按钮。

blockboolean

渲染全宽按钮。

loadingAutoboolean

根据 @click promise 状态自动设置加载状态

avatarAvatarProps

在左侧显示头像。

前置boolean

当为 true 时,图标将显示在左侧。

leadingIconany

在左侧显示图标。

尾部boolean

当为 true 时,图标将显示在右侧。

trailingIconany

在右侧显示图标。

loadingboolean

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

loadingIconappConfig.ui.icons.loadingany

loading prop 为 true 时显示的图标。

ui{ base?: ClassNameValue; label?: ClassNameValue; trailing?: ClassNameValue; } & { base?: ClassNameValue; label?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailingIcon?: ClassNameValue; }
此组件还支持所有原生 <button> HTML 属性。

插槽

插槽类型
前置{ ui: { base: (props?: Record<string, any> | undefined) => string; label: (props?: Record<string, any> | undefined) => string; leadingIcon: (props?: Record<string, any> | undefined) => string; leadingAvatar: (props?: Record<string, any> | undefined) => string; leadingAvatarSize: (props?: Record<string, any> | undefined) => string; trailingIcon: (props?: Record<string, any> | undefined) => string; }; }
default{ ui: { base: (props?: Record<string, any> | undefined) => string; label: (props?: Record<string, any> | undefined) => string; leadingIcon: (props?: Record<string, any> | undefined) => string; leadingAvatar: (props?: Record<string, any> | undefined) => string; leadingAvatarSize: (props?: Record<string, any> | undefined) => string; trailingIcon: (props?: Record<string, any> | undefined) => string; }; }
尾部{ ui: { base: (props?: Record<string, any> | undefined) => string; label: (props?: Record<string, any> | undefined) => string; leadingIcon: (props?: Record<string, any> | undefined) => string; leadingAvatar: (props?: Record<string, any> | undefined) => string; leadingAvatarSize: (props?: Record<string, any> | undefined) => string; trailingIcon: (props?: Record<string, any> | undefined) => string; }; }

主题

app.config.ts
export default defineAppConfig({
  ui: {
    contentSearchButton: {
      slots: {
        base: '',
        label: '',
        trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
      },
      variants: {
        collapsed: {
          true: {
            label: 'hidden',
            trailing: 'lg:hidden'
          }
        }
      }
    }
  }
})
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: {
        contentSearchButton: {
          slots: {
            base: '',
            label: '',
            trailing: 'hidden lg:flex items-center gap-0.5 ms-auto'
          },
          variants: {
            collapsed: {
              true: {
                label: 'hidden',
                trailing: 'lg:hidden'
              }
            }
          }
        }
      }
    })
  ]
})

更新日志

184ea— chore: 减少类型冗余,通过省略操作按钮中的链接属性

3e72b— 修复:折叠时通过 CSS 隐藏标签和尾部

dd81d— feat: 添加 data-slot 属性 (#5447)

5b177— feat: 扩展原生 HTML 属性 (#5348)

63c0a— feat: 在使用的 slot prop 中暴露 ui (#5207)

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

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

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