feat: migrate Menu and Dropdown with selection and submenus

Port HeroUI menu family and Dropdown from ce90ea3: Reka DropdownMenu base,
MenuKey[] selection with section owners, 17 official demos, dropdown docs
and B01 tests. Long-press stays demo-level; submenu close is level-scoped.
This commit is contained in:
maoyingjie
2026-10-24 20:43:04 +08:00
parent 1c4ecc3def
commit 06ddb6662a
48 changed files with 3091 additions and 5 deletions
+5
View File
@@ -155,6 +155,11 @@ export const componentItems: DocsItem[] = [
url: "/components/link",
category: "navigation",
},
{
title: "Dropdown 下拉菜单",
url: "/components/dropdown",
category: "collections",
},
{
title: "ListBox 列表框",
url: "/components/list-box",
+236
View File
@@ -0,0 +1,236 @@
---
title: Dropdown 下拉菜单
description: 展示用户可选择的操作或选项列表
component: dropdown
group: 组件
---
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
## 用法
```vue
<script setup lang="ts">
import {
DropdownRoot,
DropdownPopover,
DropdownMenu,
DropdownItem,
Label,
Button,
} from "@heroui-vue/components";
</script>
```
<ComponentPreview name="dropdown-default" />
## 组件结构
```vue
<DropdownRoot>
<Button variant="secondary" aria-label="菜单">操作</Button>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
```
## 示例
### 带图标
<ComponentPreview name="dropdown-with-icons" />
### 带描述
<ComponentPreview name="dropdown-with-descriptions" />
### 含禁用项
<ComponentPreview name="dropdown-with-disabled-items" />
### 分组选项
<ComponentPreview name="dropdown-with-sections" />
### 多选
<ComponentPreview name="dropdown-with-multiple-selection" />
### 受控组件
<ComponentPreview name="dropdown-controlled" />
### 受控展开状态
<ComponentPreview name="dropdown-controlled-open-state" />
### 单选
<ComponentPreview name="dropdown-with-single-selection" />
### 单选自定义指示器
<ComponentPreview name="dropdown-single-with-custom-indicator" />
### 分组级选择
<ComponentPreview name="dropdown-with-section-level-selection" />
### 带快捷键
<ComponentPreview name="dropdown-with-keyboard-shortcuts" />
### 含子菜单
<ComponentPreview name="dropdown-with-submenus" />
### 自定义子菜单指示器
<ComponentPreview name="dropdown-with-custom-submenu-indicator" />
### 自定义触发器
<ComponentPreview name="dropdown-custom-trigger" />
### 长按触发
<ComponentPreview name="dropdown-long-press-trigger" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="dropdown-custom-styles" />
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令。
```css
@layer components {
.hv-dropdown {
@apply flex flex-col gap-1;
}
.hv-dropdown__popover {
@apply rounded-2xl bg-overlay shadow-lg;
}
}
```
## 样式参考
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
### CSS 类
#### 基础类
- `.hv-dropdown` — 根容器
- `.hv-dropdown__trigger` — 触发器
- `.hv-dropdown__popover` — 浮层
- `.hv-dropdown__menu` — 菜单容器
#### 菜单组件类
- `.hv-menu` — 菜单列表
- `.hv-menu-item` — 菜单项
- `.hv-menu-item__indicator` — 选中指示器
- `.hv-menu-item__indicator--submenu` — 子菜单指示器
- `.hv-menu-item--default` / `.hv-menu-item--danger` — 变体
- `.hv-menu-section` — 分组
### 交互状态
- **悬停**:`:hover` 或 `[data-hovered="true"]`
- **聚焦**:`:focus-visible` 或 `[data-focus-visible="true"]`
- **按下**:`[data-pressed="true"]`
- **选中**:`[aria-checked="true"]` / `[data-selected="true"]`
- **禁用**:`[data-disabled="true"]`
- **进入/退出**:`[data-entering]` / `[data-exiting]`
- **放置**:`[data-placement="*"]`
## API 参考
所有部件接受 `class`、`style`、ARIA 与原生事件。选择集合使用 Vue 数组模型(`MenuKey[]`),不使用 React `Set`/`Selection`。
### DropdownRoot
| Prop | 类型 | 默认值 | 描述 |
| ------------- | ---------------- | ------ | -------------- |
| `open` | `boolean` | — | 受控展开 |
| `defaultOpen` | `boolean` | — | 非受控初始展开 |
| `modal` | `boolean` | `true` | 模态焦点管理 |
| `dir` | `'ltr' \| 'rtl'` | — | 文本方向 |
| `update:open` | 事件 | — | 展开变更 |
### DropdownTrigger
| Prop | 类型 | 默认值 | 描述 |
| --------- | --------- | ------ | ---------------------- |
| `asChild` | `boolean` | `true` | 将触发合并到唯一子节点 |
### DropdownPopover
| Prop | 类型 | 默认值 | 描述 |
| ----------------- | --------- | ------ | ---------------- |
| `side` / `align` | `string` | — | 相对触发器的位置 |
| `sideOffset` | `number` | — | 侧边偏移 |
| `avoidCollisions` | `boolean` | — | 碰撞翻转 |
| `loop` | `boolean` | — | 焦点循环 |
### DropdownMenu
| Prop | 类型 | 默认值 | 描述 |
| ----------------------------------------- | ---------------------------------- | -------- | ----------- |
| `selectionMode` | `'none' \| 'single' \| 'multiple'` | `'none'` | 选择模式 |
| `selectedKeys` / `defaultSelectedKeys` | `MenuKey[]` | — / `[]` | 受控 / 初始 |
| `disabledKeys` | `MenuKey[]` | `[]` | 禁用项 |
| `update:selectedKeys` / `selectionChange` | 事件 | — | 选择变更 |
| `action` | 事件 `(key: MenuKey)` | — | 动作项激活 |
### DropdownSection
与 `DropdownMenu` 相同的选择 Props,可在分组内独立拥有 `selectionMode` / `selectedKeys`。
### DropdownItem
| Prop | 类型 | 默认值 | 描述 |
| ------------ | ----------------------- | ----------- | -------------- |
| `id` | `MenuKey` | — | 条目标识 |
| `textValue` | `string` | — | 首字母导航文本 |
| `variant` | `'default' \| 'danger'` | `'default'` | 视觉变体 |
| `isDisabled` | `boolean` | `false` | 禁用 |
| `select` | 事件 `(key: MenuKey)` | — | 激活回调 |
### DropdownItemIndicator
| Prop | 类型 | 默认值 | 描述 |
| ------ | ---------------------- | ------------- | ---------- |
| `type` | `'checkmark' \| 'dot'` | `'checkmark'` | 指示器类型 |
### DropdownSubmenuIndicator / DropdownSubmenuTrigger
子菜单指示器默认 chevron-right;`DropdownSubmenuTrigger` 包裹条目与嵌套 `DropdownPopover`,每层子菜单独立 open 状态。
## 无障碍
菜单使用 `role="menu"` / `menuitem`。上下键与首尾导航、Enter/Space 激活、Esc 关闭并恢复触发器焦点。禁用项跳过;隐藏/退出条目不进入 Tab 顺序。
## 上游差异
- React 对象部件改具名导出;`Selection`/`Set` 改 `MenuKey[]`;`onAction`/`onSelectionChange` 改 Vue 事件。
- `Kbd slot="keyboard"` 为上游原生 slot 透传;本库 Kbd 支持同结构。
- Menu/Item/Section 无独立官方文档页,契约折叠于 Dropdown 页;本库提供同名导出供组合。
- 长按触发由 Reka `DropdownMenuRoot` 的 trigger 策略提供;与上游 `trigger="longPress"` 对应关系见演示。
## 相关组件
- [Button 按钮](./button)
- [Popover 弹出层](./popover)
- [ListBox 列表框](./list-box)
- [Separator 分隔线](./separator)
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
const open = ref(false);
</script>
<template>
<div class="flex min-w-sm flex-col items-center justify-center gap-4">
<p class="text-sm text-muted">
下拉菜单:
<strong>{{ open ? "打开" : "关闭" }}</strong>
</p>
<DropdownRoot v-model:open="open">
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<Label>打开文件</Label>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<Label>保存文件</Label>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<Label>删除文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</div>
</template>
+48
View File
@@ -0,0 +1,48 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
Button,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["bold"]);
</script>
<template>
<div class="flex min-w-sm flex-col items-center justify-center gap-4">
<p class="text-sm text-muted">
已选:{{ selected.length > 0 ? selected.join("、") : "无" }}
</p>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu
:selected-keys="selected"
selection-mode="multiple"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownItem id="bold" text-value="粗体">
<Label>粗体</Label>
<DropdownItemIndicator />
</DropdownItem>
<DropdownItem id="italic" text-value="斜体">
<Label>斜体</Label>
<DropdownItemIndicator />
</DropdownItem>
<DropdownItem id="underline" text-value="下划线">
<Label>下划线</Label>
<DropdownItemIndicator />
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</div>
</template>
@@ -0,0 +1,46 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover
class="rounded-xl border border-border/80 bg-surface p-1 shadow-sm"
>
<DropdownMenu>
<DropdownItem
id="rename"
text-value="重命名"
class="rounded-lg data-[focused=true]:bg-default"
>
<Label>重命名</Label>
</DropdownItem>
<DropdownItem
id="duplicate"
text-value="复制"
class="rounded-lg data-[focused=true]:bg-default"
>
<Label>复制</Label>
</DropdownItem>
<DropdownItem
id="delete"
text-value="删除"
variant="danger"
class="rounded-lg data-[focused=true]:bg-danger-soft"
>
<Label>删除</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { IconLogout, IconSettings, IconUsers } from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Avatar,
AvatarImage,
AvatarFallback,
Label,
} from "@heroui-vue/components";
</script>
<template>
<DropdownRoot>
<DropdownTrigger class="rounded-full">
<Avatar>
<AvatarImage
alt="Junior Garcia"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"
/>
<AvatarFallback :delay-ms="600">JD</AvatarFallback>
</Avatar>
</DropdownTrigger>
<DropdownPopover>
<div class="px-3 pt-3 pb-1">
<div class="flex items-center gap-2">
<Avatar size="sm">
<AvatarImage
alt="Jane"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"
/>
<AvatarFallback :delay-ms="600">JD</AvatarFallback>
</Avatar>
<div class="flex flex-col gap-0">
<p class="text-sm leading-5 font-medium">Jane Doe</p>
<p class="text-xs leading-none text-muted">jane@example.com</p>
</div>
</div>
</div>
<DropdownMenu>
<DropdownItem id="dashboard" text-value="仪表盘">
<Label>仪表盘</Label>
</DropdownItem>
<DropdownItem id="profile" text-value="个人资料">
<Label>个人资料</Label>
</DropdownItem>
<DropdownItem id="settings" text-value="设置">
<div class="flex w-full items-center justify-between gap-2">
<Label>设置</Label>
<IconSettings class="size-3.5 text-muted" />
</div>
</DropdownItem>
<DropdownItem id="new-project" text-value="新建项目">
<div class="flex w-full items-center justify-between gap-2">
<Label>创建团队</Label>
<IconUsers class="size-3.5 text-muted" />
</div>
</DropdownItem>
<DropdownItem id="logout" text-value="退出登录" variant="danger">
<div class="flex w-full items-center justify-between gap-2">
<Label>退出登录</Label>
<IconLogout class="size-3.5 text-danger" />
</div>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
+38
View File
@@ -0,0 +1,38 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
<DropdownItem id="copy-link" text-value="复制链接">
<Label>复制链接</Label>
</DropdownItem>
<DropdownItem id="edit-file" text-value="编辑文件">
<Label>编辑文件</Label>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<Label>删除文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,102 @@
<script setup lang="ts">
import { onBeforeUnmount, ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
const open = ref(false);
let pressTimer: ReturnType<typeof setTimeout> | null = null;
let suppressClick = false;
function clearPressTimer() {
if (pressTimer !== null) {
clearTimeout(pressTimer);
pressTimer = null;
}
}
function onPointerDown(e: PointerEvent) {
clearPressTimer();
suppressClick = false;
const startX = e.clientX;
const startY = e.clientY;
pressTimer = setTimeout(() => {
pressTimer = null;
suppressClick = true;
open.value = true;
}, 500);
const onMove = (event: PointerEvent) => {
if (
Math.abs(event.clientX - startX) > 10 ||
Math.abs(event.clientY - startY) > 10
) {
clearPressTimer();
window.removeEventListener("pointermove", onMove);
}
};
window.addEventListener("pointermove", onMove);
const cleanupMove = () => {
window.removeEventListener("pointermove", onMove);
window.removeEventListener("pointerup", cleanupMove);
window.removeEventListener("pointercancel", cleanupMove);
};
window.addEventListener("pointerup", cleanupMove);
window.addEventListener("pointercancel", cleanupMove);
}
function onPointerUp() {
clearPressTimer();
}
function onClick(e: MouseEvent) {
e.preventDefault();
e.stopPropagation();
if (suppressClick) {
suppressClick = false;
return;
}
open.value = false;
}
onBeforeUnmount(clearPressTimer);
</script>
<template>
<DropdownRoot v-model:open="open">
<DropdownTrigger>
<Button
aria-label="菜单"
variant="secondary"
@pointerdown="onPointerDown"
@pointerup="onPointerUp"
@pointercancel="onPointerUp"
@pointerleave="onPointerUp"
@click.capture="onClick"
@contextmenu.prevent
>
长按
</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<Label>打开文件</Label>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<Label>保存文件</Label>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<Label>删除文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,136 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,97 @@
<script setup lang="ts">
import { IconArrowRight } from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSubmenuTrigger,
DropdownSubmenuIndicator,
Button,
Label,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">分享</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="copy-link" text-value="复制链接">
<Label>复制链接</Label>
</DropdownItem>
<DropdownItem id="facebook" text-value="Facebook">
<Label>Facebook</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="share" text-value="分享">
<Label>更多选项</Label>
<DropdownSubmenuIndicator>
<IconArrowRight class="size-3.5 text-muted" />
</DropdownSubmenuIndicator>
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="whatsapp" text-value="WhatsApp">
<Label>WhatsApp</Label>
</DropdownItem>
<DropdownItem id="telegram" text-value="Telegram">
<Label>Telegram</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="email" text-value="邮件">
<Label>Email</Label>
<DropdownSubmenuIndicator>
<svg
class="size-3.5 text-muted"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M9 18l6-6-6-6" />
</svg>
</DropdownSubmenuIndicator>
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="work" text-value="工作邮箱">
<Label>工作邮箱</Label>
</DropdownItem>
<DropdownItem id="personal" text-value="个人邮箱">
<Label>个人邮箱</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
<DropdownItem id="discord" text-value="Discord">
<Label>Discord</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
<DropdownSubmenuTrigger>
<DropdownItem id="other" text-value="其他">
<Label>其他(默认指示器)</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="sms" text-value="SMS">
<Label>SMS</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,89 @@
<script setup lang="ts">
import {
IconDeviceFloppy,
IconFolderOpen,
IconPlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
Description,
Kbd,
KbdAbbr,
KbdContent,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconFolderOpen class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>打开文件</Label>
<Description>打开已有文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconDeviceFloppy class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>保存文件</Label>
<Description>保存当前文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,83 @@
<script setup lang="ts">
import { IconMenu2, IconPencil, IconPlus, IconTrash } from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSection,
Button,
Label,
Description,
Header,
Kbd,
KbdAbbr,
KbdContent,
Separator,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button is-icon-only aria-label="菜单" variant="secondary">
<IconMenu2 class="outline-none" />
</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[220px]">
<DropdownMenu :disabled-keys="['delete-file']" @action="onAction">
<DropdownSection>
<Header>操作</Header>
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="edit-file" text-value="编辑文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPencil class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>编辑文件</Label>
<Description>进行修改</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>E</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection>
<Header>危险区域</Header>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
+68
View File
@@ -0,0 +1,68 @@
<script setup lang="ts">
import {
IconDeviceFloppy,
IconFolderOpen,
IconPlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
Kbd,
KbdAbbr,
KbdContent,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<IconPlus class="size-4 shrink-0 text-muted" />
<Label>新建文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<IconFolderOpen class="size-4 shrink-0 text-muted" />
<Label>打开文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<IconDeviceFloppy class="size-4 shrink-0 text-muted" />
<Label>保存文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<IconTrash class="size-4 shrink-0 text-danger" />
<Label>删除文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,58 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
Kbd,
KbdAbbr,
KbdContent,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new" text-value="新建">
<Label>新建</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open" text-value="打开">
<Label>打开</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save" text-value="保存">
<Label>保存</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete" text-value="删除" variant="danger">
<Label>删除</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,56 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">喜爱的水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="multiple"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator />
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator />
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator />
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator />
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator />
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,122 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
Kbd,
KbdAbbr,
KbdContent,
Separator,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const textStyles = ref<MenuKey[]>(["bold", "italic"]);
const textAlignment = ref<MenuKey[]>(["left"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">样式</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu>
<DropdownSection>
<Header>操作</Header>
<DropdownItem id="cut" text-value="剪切">
<Label>剪切</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>X</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="copy" text-value="复制">
<Label>复制</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>C</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="paste" text-value="粘贴">
<Label>粘贴</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>U</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection
:selected-keys="textStyles"
selection-mode="multiple"
@update:selected-keys="(keys: MenuKey[]) => (textStyles = keys)"
>
<Header>文本样式</Header>
<DropdownItem id="bold" text-value="粗体">
<DropdownItemIndicator />
<Label>粗体</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>B</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="italic" text-value="斜体">
<DropdownItemIndicator />
<Label>斜体</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>I</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="underline" text-value="下划线">
<DropdownItemIndicator />
<Label>下划线</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>U</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection
:selected-keys="textAlignment"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (textAlignment = keys)"
>
<Header>文本对齐</Header>
<DropdownItem id="left" text-value="左对齐">
<DropdownItemIndicator type="dot" />
<Label>左对齐</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>A</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="center" text-value="居中">
<DropdownItemIndicator type="dot" />
<Label>居中</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>H</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="right" text-value="右对齐">
<DropdownItemIndicator type="dot" />
<Label>右对齐</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,88 @@
<script setup lang="ts">
import {
IconDotsVertical,
IconPencil,
IconPlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSection,
Button,
Label,
Description,
Header,
Kbd,
KbdAbbr,
KbdContent,
Separator,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button is-icon-only aria-label="菜单" variant="secondary">
<IconDotsVertical class="outline-none" />
</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownSection>
<Header>操作</Header>
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="edit-file" text-value="编辑文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPencil class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>编辑文件</Label>
<Description>进行修改</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>E</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection>
<Header>危险区域</Header>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,56 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator />
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator />
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator />
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator />
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator />
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,72 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSubmenuTrigger,
DropdownSubmenuIndicator,
Button,
Label,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">分享</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="copy-link" text-value="复制链接">
<Label>复制链接</Label>
</DropdownItem>
<DropdownItem id="facebook" text-value="Facebook">
<Label>Facebook</Label>
</DropdownItem>
<DropdownItem id="twitter" text-value="Twitter">
<Label>X / Twitter</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="share" text-value="分享">
<Label>其他</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="whatsapp" text-value="WhatsApp">
<Label>WhatsApp</Label>
</DropdownItem>
<DropdownItem id="telegram" text-value="Telegram">
<Label>Telegram</Label>
</DropdownItem>
<DropdownItem id="discord" text-value="Discord">
<Label>Discord</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="email" text-value="邮件">
<Label>Email</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="work" text-value="工作邮箱">
<Label>工作邮箱</Label>
</DropdownItem>
<DropdownItem id="personal" text-value="个人邮箱">
<Label>个人邮箱</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>