Morphing Search
将搜索框展开为建议、最近记录或可编辑筛选标签。
适用场景
- 当界面需要以下行为时使用 Morphing Search:将搜索框展开为建议、最近记录或可编辑筛选标签。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/morphing-search.json https://orvui.efu.me/r/morphing-search-chips.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
Chip Search
chips.vue将提交的词语转换为可移除标签,搜索表面围绕标签展开。
Enter adds a filter. Backspace at the start of the field selects the last filter, and again removes it. Delete removes the highlighted recent search.
packages/vue/src/blocks/morphing-search/examples/chips.vue
<script setup lang="ts">
import { MorphingSearchChips } from "@/components/orvui/blocks/morphing-search";
const tileColors = [
"from-rose-400/40 to-orange-300/30",
"from-sky-400/40 to-indigo-400/30",
"from-emerald-400/40 to-teal-300/30",
"from-amber-300/40 to-rose-300/30",
"from-violet-400/40 to-fuchsia-300/30",
"from-teal-300/40 to-sky-300/30",
];
const suggestions = [
"dashboards",
"data tables",
"dark mode",
"empty states",
"onboarding",
"pricing pages",
"settings",
"sign in",
];
</script>
<template>
<div
class="relative flex h-[440px] w-full max-w-2xl flex-col justify-end overflow-hidden rounded-3xl border border-border bg-muted/40 p-4"
>
<div
aria-hidden="true"
class="absolute inset-4 grid grid-cols-3 gap-3 opacity-80"
>
<div
v-for="tile in tileColors"
:key="tile"
class="rounded-2xl bg-gradient-to-br"
:class="tile"
/>
</div>
<MorphingSearchChips
class="mx-auto"
placeholder="Search inspiration"
label="Search inspiration"
:default-chips="['onboarding']"
:default-recents="['dashboards', 'empty states', 'pricing pages']"
storage-key="orvui:morphing-search-chips:recents"
:max-chips="4"
:suggestions="suggestions"
/>
</div>
</template>
packages/vue/src/blocks/morphing-search/src/MorphingSearchChips.vue
Morphing Search
overlay.vue通过指针或键盘,从输入框或紧凑触发器打开较大的搜索表面。
packages/vue/src/blocks/morphing-search/examples/overlay.vue
<script setup lang="ts">
import { Blocks, BookOpen, Bot, FolderOpen, Palette } from "lucide-vue-next";
import { MorphingSearch, type MorphingSearchItem } from "@/components/orvui/blocks/morphing-search";
const entries = [
[
"project-folder",
"Project Folder",
"Block · Files and previews",
["files", "overlay"],
FolderOpen,
],
[
"motion-components",
"Motion components",
"Collection · Interaction primitives",
["animation", "components"],
Blocks,
],
[
"agent-interfaces",
"Agent interfaces",
"Collection · AI building blocks",
["ai", "chat"],
Bot,
],
[
"installation",
"Installation guide",
"Documentation · Add your first component",
["setup", "shadcn"],
BookOpen,
],
[
"design-tokens",
"Design tokens",
"Documentation · Color, type, and motion",
["theme", "styles"],
Palette,
],
] as const;
const items: MorphingSearchItem[] = entries.map(
([id, title, description, keywords, icon]) => ({
id,
title,
description,
keywords: [...keywords],
icon,
}),
);
</script>
<template>
<div class="flex w-full max-w-[22rem] items-center gap-3">
<MorphingSearch
:items="items"
placeholder="Find components"
/><MorphingSearch
:items="items"
placeholder="Find components"
shortcut=""
icon-only
/>
</div>
</template>
packages/vue/src/blocks/morphing-search/src/MorphingSearch.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
MorphingSearch | v-model:openboolean | update:open |
MorphingSearchChips | v-model:chipsstring[] | update:chips |
MorphingSearchChips | v-model:querystring | update:query |
MorphingSearchChips | v-model:recentsstring[] | update:recents |
MorphingSearchChips | v-model:openboolean | update:open |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
Chip Search
chips?string[]—defaultChips?string[]() => []query?string—defaultQuery?string""recents?string[]localRecents.valuedefaultRecents?string[]() => []storageKey?string—maxRecents?number5suggestions?string[]() => []filter?false | (term: string, query: string) => booleanundefinedmaxSuggestions?number6loading?booleanfalsemaxChips?number—normalize?(term: string) => string | null—emptyState?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>undefinedside?"top" | "bottom" | "auto""top"open?booleanundefineddefaultOpen?booleanfalsedisabled?booleanfalsename?string—placeholder?string"Search"label?string"Search"actions?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>undefined事件
update:chips[chips: string[]]@update:chipschipsChange[chips: string[]]@chipsChangeupdate:query[query: string]@update:queryqueryChange[query: string]@queryChangeupdate:recents[recents: string[]]@update:recentsrecentsChange[recents: string[]]@recentsChangeupdate:open[open: boolean]@update:openopenChange[open: boolean]@openChange插槽
empty() => VNodeChild#emptyactions() => VNodeChild#actionsMorphing Search
itemsMorphingSearchItem[]—placeholder?string"Search"shortcut?string"f"iconOnly?booleanfalseemptyMessage?string"No results found."open?booleanundefineddefaultOpen?booleanfalse事件
update:open[open: boolean]@update:openopenChange[open: boolean]@openChangequeryChange[query: string]@queryChangeselect[item: MorphingSearchItem]@select无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Morphing Search?
- 通过 items、placeholder、shortcut、iconOnly、emptyMessage、open、defaultOpen 配置 Morphing Search;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:open、openChange、queryChange、select,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
请留意
部分组件参考了开源作品,相关署名与独立许可请参阅 NOTICE。
更新于
来源与许可 ↗MIT · 0.1.1