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:
@@ -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",
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -73,10 +73,10 @@
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| dropdown | 验证中(B01) | Root/Trigger/Popover/Menu/Section/Item/ItemIndicator/SubmenuIndicator/SubmenuTrigger;17/17 基线例;Reka DropdownMenu;数组选择模型 |
|
||||
| menu | 验证中(B01) | MenuRoot/Menu 列表与选择/动作上下文;无独立官方文档页,契约折叠于 Dropdown;见 B01 |
|
||||
| menu-item | 验证中(B01) | MenuItem/Indicator/SubmenuIndicator;variant default/danger、checkmark/dot;见 B01 |
|
||||
| menu-section | 验证中(B01) | MenuSection 分组与分组级选择;见 B01 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# B01 菜单家族与 Dropdown
|
||||
|
||||
日期:2026-10-24。独立 worktree `heroui-vue-b01`,分支 `feat/b01-menu-dropdown`,起点 `origin/main` `1c4ecc3`。固定上游 HeroUI 3.2.6 / `ce90ea3`。本批不要求 SSR/水合/Nuxt。
|
||||
|
||||
## 源公开契约
|
||||
|
||||
- 部件:Menu/MenuRoot、MenuItem/Indicator/SubmenuIndicator、MenuSection;DropdownRoot/Trigger/Popover/Menu/Section/Item/ItemIndicator/SubmenuIndicator/SubmenuTrigger。
|
||||
- 变体:menuItem `variant: default|danger`;ItemIndicator `type: checkmark|dot`。
|
||||
- 选择:`selectionMode: none|single|multiple`、`selectedKeys`/`onSelectionChange`、Section 级选择、`disabledKeys`、`onAction`。
|
||||
- 样式:`menu.css` / `menu-item.css` / `menu-section.css` / `dropdown.css` + tv,hv- 前缀移植。
|
||||
- 文档:中文 `dropdown.mdx` **17 预览**;Menu/Item/Section **无独立 Web 文档页**(native menu.mdx 属 heroui-native,不作为契约)。
|
||||
|
||||
## 实现映射
|
||||
|
||||
| 上游 | Vue |
|
||||
| ------------------------ | ---------------------------------------------------------------------------------- |
|
||||
| RAC MenuTrigger + Button | `DropdownRoot`(Reka `DropdownMenuRoot`)+ `DropdownTrigger` / 演示内 Button |
|
||||
| RAC Popover + Menu | `DropdownPopover`(Reka `DropdownMenuContent`)+ `DropdownMenu`(选择/动作上下文) |
|
||||
| RAC MenuItem | `MenuItem`(Reka `DropdownMenuItem`)+ 自有选择 owner |
|
||||
| RAC MenuSection | `MenuSection`(Reka `DropdownMenuGroup`)+ 分组级选择 |
|
||||
| SubmenuTrigger | `DropdownSubmenuTrigger`(Reka `DropdownMenuSub` + `SubTrigger`) |
|
||||
| Selection Set | `MenuKey[]` 数组模型 + 受控/非受控 + 提案更新 |
|
||||
|
||||
选择所有权:Menu 级 owner;Section 提供 `selectionMode`/`selectedKeys` 时覆盖为分组 owner。动作项 `selectionMode=none` 时 `@action` + 默认关闭;multiple 保持展开;single 关闭。
|
||||
|
||||
## 预览清单(17)
|
||||
|
||||
default、with-icons、with-descriptions、with-disabled-items、with-sections、with-multiple-selection、controlled、controlled-open-state、with-single-selection、single-with-custom-indicator、with-section-level-selection、with-keyboard-shortcuts、with-submenus、with-custom-submenu-indicator、custom-trigger、long-press-trigger、custom-styles。
|
||||
|
||||
## 验证
|
||||
|
||||
- `tests/b01-menu-dropdown.test.ts`:动作单次触发、多选切换、分组级选择、禁用标记、指示器 checkmark。
|
||||
- 完整 `pnpm test`、`typecheck` 见验收节。
|
||||
- 浏览器重点:见 verification(子菜单/RTL/Esc/长按)。
|
||||
|
||||
## 上游差异
|
||||
|
||||
- 具名导出替代对象部件;`MenuKey[]` 替代 `Set`/`Selection`;Vue 事件替代 onAction/onSelectionChange。
|
||||
- 长按触发依赖 Reka DropdownMenuRoot 的 trigger 策略;与上游 `trigger="longPress"` 的对应在演示中体现。
|
||||
- Item render props 使用作用域插槽状态,不机械搬 RAC render 函数。
|
||||
- Reka 2.11 主入口导出 `DropdownMenu*` 而非独立 `MenuItem`/`MenuGroup`;本库 MenuItem 基于 `DropdownMenuItem`。
|
||||
|
||||
## 未验证
|
||||
|
||||
完整读屏、物理触屏、Nuxt、逐像素、独立 tarball 安装(本批不作为门槛时如实记录)。
|
||||
|
||||
## 集成增量
|
||||
|
||||
- `packages/vue/src/index.ts`:Menu/Dropdown 命名导出 + 变体/类型。
|
||||
- `packages/styles`:menu*.css、dropdown.css、menu/dropdown variants。
|
||||
- `apps/docs/.vitepress/theme/navigation.ts`:Dropdown 条目(collections)。
|
||||
- `docs/compatibility.md` / `upstream.md`:B01 条目。
|
||||
- `package.json` test:unit:`tests/b01-menu-dropdown.test.ts`。
|
||||
@@ -198,3 +198,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
固定 ce90ea3 的 `apps/docs/src/components/fumadocs/layouts/notebook`、page/toc、`apps/docs/src/app/global.css`、中文组件 meta/overview、component-preview-container、component-source/codeblock-client 与版本/框架/搜索控件。布局尺寸、导航分区、示例结构适配到 VitePress 和本库 Vue 组件,保留 HeroUI Apache-2.0 来源声明;没有运行时依赖相邻仓库。分类缩略图未复制,缺失组件与搜索/Table 原生语义保留项见 [DOCS-01](migrations/DOCS-01-shell-alignment.md)。
|
||||
|
||||
2026-10-24 视觉返修实际对照官网 components/Button 页面;总览直接引用官方组件目录同源 `heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/related-components/{light,dark}-<name>.png` 设计缩略图(来源规则见固定 `component-item.tsx`)。不下载或重绘媒体,图片失败仍保留本地名称/说明/导航;实际 Vue 演示保持原 SFC。官网为视觉补验依据,不替换固定组件 API 基线。
|
||||
|
||||
## B01 Menu / Dropdown(2026-10-24)
|
||||
|
||||
固定 ce90ea3 的 `packages/react/src/components/{menu,menu-item,menu-section,dropdown}`、`packages/styles/components/{menu,menu-item,menu-section,dropdown}.css` 与对应 tv,中文 `(collections)/dropdown.mdx` 及 `demos/cn/dropdown` 17 例。样式加 hv- 前缀;演示图标采用 Tabler Vue。Menu/Item/Section 无独立 Web 文档页(native menu.mdx 属 heroui-native,不作为本契约)。底座为安装版 Reka 2.11 DropdownMenu,未复制 React 源码构建。
|
||||
|
||||
@@ -898,3 +898,11 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
||||
### 左右导航配色与悬浮状态
|
||||
|
||||
实际官网深色导航读数为中性灰 lab(48.496 0 0)、400 字重,与 Tailwind neutral-500 对应;本地原为偏冷的组件 muted/500 字重,现已分离文档导航颜色。普通项中性灰、当前项中性前景,侧栏保留选中表面/阴影,右侧保留章节指示线。两侧导航覆盖装饰线而不更改普通 Link 默认契约,浏览器实际 :hover/data-hovered 状态的 textDecorationLine=none,焦点环不移除。主题深浅色及导航跳转验证,壳层 **12 项**、typecheck、build:docs、格式/diff 检查通过;构建仍有既存 chunk 提示。本轮同时移除上一请求的 Vue 3 标记及废弃样式,框架位置留空。截图 `/private/tmp/heroui-docs-navigation-review.png`,不扩大为整站逐像素验收。
|
||||
|
||||
## 2026-10-24 B01 菜单家族与 Dropdown
|
||||
|
||||
- 实现 Menu/MenuItem/MenuSection 与 Dropdown 全族,复用 Reka 2.11 DropdownMenu;选择为 `MenuKey[]` + 受控/分组级 owner。
|
||||
- 17/17 官方演示移植(文案/id/textValue/结构对照 `cn/dropdown`);Menu/Item/Section 无独立官方页,契约记入 dropdown.md。
|
||||
- `tests/b01-menu-dropdown.test.ts` **6/6**(动作单次、多选保持展开、分组选择、禁用、指示器、子菜单 DOM)。完整 **70 文件 / 869 项**;typecheck、build:docs、Prettier 通过。
|
||||
- 浏览器 5181:17 预览挂载;默认菜单 4 项含 danger;多选点香蕉后苹果+香蕉选中且菜单保持展开;子菜单「其他」→ WhatsApp/Telegram/Discord/Email 可见。
|
||||
- 未验证:完整读屏、物理触屏、Nuxt、逐像素、独立 tarball;Esc 一次关闭多层子菜单(上游逐层)待细修;长按为演示层实现(Reka 无 longPress prop)。
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/b01-menu-dropdown.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue adapters. */
|
||||
/* ==========================================================================
|
||||
Base dropdown styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-dropdown {
|
||||
@apply flex flex-col gap-1;
|
||||
}
|
||||
|
||||
.hv-dropdown__trigger {
|
||||
@apply inline-block;
|
||||
/* Custom trigger (not a library Button) gets button-like affordances */
|
||||
@apply outline-none;
|
||||
transition:
|
||||
transform 250ms var(--ease-out-quart),
|
||||
background-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
&[data-pending="true"] {
|
||||
@apply status-pending;
|
||||
}
|
||||
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
}
|
||||
|
||||
/* Similar to select popover styles */
|
||||
.hv-dropdown__popover {
|
||||
@apply max-w-[48svw] origin-(--trigger-anchor-point) scroll-py-1 scrollbar overflow-y-auto overscroll-contain bg-overlay p-0 text-sm md:min-w-55;
|
||||
border-radius: min(32px, var(--radius-3xl));
|
||||
box-shadow: var(--overlay-shadow);
|
||||
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply outline-none;
|
||||
}
|
||||
|
||||
/* Entering animations */
|
||||
&[data-entering="true"] {
|
||||
@apply animate-in duration-150 ease-smooth fade-in-0 zoom-in-90;
|
||||
|
||||
&[data-placement="top"] {
|
||||
@apply slide-in-from-bottom-1;
|
||||
}
|
||||
|
||||
&[data-placement="bottom"] {
|
||||
@apply slide-in-from-top-1;
|
||||
}
|
||||
|
||||
&[data-placement="left"] {
|
||||
@apply slide-in-from-right-1;
|
||||
}
|
||||
|
||||
&[data-placement="right"] {
|
||||
@apply slide-in-from-left-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Exiting animations */
|
||||
&[data-exiting="true"] {
|
||||
@apply animate-out duration-100 ease-smooth zoom-out-95 fade-out;
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
|
||||
&[data-exiting="true"],
|
||||
&[data-entering="true"] {
|
||||
@apply transition-[opacity,transform] will-change-[opacity,transform];
|
||||
}
|
||||
|
||||
/* Arrow styling */
|
||||
& [data-slot="popover-overlay-arrow"] {
|
||||
fill: var(--overlay);
|
||||
}
|
||||
|
||||
&[data-placement="bottom"] [data-slot="popover-overlay-arrow"] {
|
||||
rotate: 180deg;
|
||||
}
|
||||
|
||||
&[data-placement="left"] [data-slot="popover-overlay-arrow"] {
|
||||
rotate: -90deg;
|
||||
}
|
||||
|
||||
&[data-placement="right"] [data-slot="popover-overlay-arrow"] {
|
||||
rotate: 90deg;
|
||||
}
|
||||
|
||||
/* Menu styles */
|
||||
[data-slot="dropdown-menu"] {
|
||||
@apply p-1.5 outline-none;
|
||||
}
|
||||
|
||||
[data-slot="menu-item"] {
|
||||
@apply px-2.5;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-dropdown__menu {
|
||||
@apply relative flex w-full flex-col gap-0.5 overflow-clip p-1;
|
||||
|
||||
[data-slot="separator"] {
|
||||
@apply ms-[3%] w-[94%];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue adapters. */
|
||||
/* ==========================================================================
|
||||
Base menu item styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-menu-item {
|
||||
@apply relative flex min-h-9 w-full items-center justify-start gap-3 rounded-2xl px-2 py-1.5 outline-none no-highlight;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-out-quart),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
/* Cursor */
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply pointer-events-none w-fit select-none;
|
||||
}
|
||||
|
||||
[data-slot="description"] {
|
||||
@apply pointer-events-none text-wrap select-none;
|
||||
}
|
||||
|
||||
[data-slot="submenu-indicator"] svg {
|
||||
@apply size-3.5;
|
||||
}
|
||||
|
||||
/* Add inline-start padding when indicator is present */
|
||||
&:has(.hv-menu-item__indicator) {
|
||||
@apply ps-7;
|
||||
}
|
||||
|
||||
/* Add inline-end padding when indicator is present and has submenu */
|
||||
&[data-has-submenu="true"]:has(.hv-menu-item__indicator) {
|
||||
@apply ps-2 pe-7;
|
||||
}
|
||||
|
||||
/* Focus visible state (keyboard focus only). */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
@apply will-change-transform;
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
/* Hover state */
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
@apply bg-default;
|
||||
}
|
||||
}
|
||||
|
||||
/* Selected state */
|
||||
&[aria-checked="true"],
|
||||
&[aria-selected="true"],
|
||||
&[data-selected="true"] {
|
||||
[data-slot="menu-item-indicator--checkmark"] {
|
||||
transition: stroke-dashoffset 100ms linear;
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
[data-slot="menu-item-indicator--dot"] {
|
||||
@apply scale-100 opacity-100;
|
||||
}
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&[data-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Menu item indicator
|
||||
========================================================================== */
|
||||
|
||||
.hv-menu-item__indicator {
|
||||
@apply absolute start-2 top-1/2 flex size-4 shrink-0 -translate-y-1/2 items-center justify-center text-muted;
|
||||
|
||||
@apply transition duration-250 motion-reduce:transition-none;
|
||||
|
||||
/* Position on the inline-end when menu item has submenu */
|
||||
.hv-menu-item[data-has-submenu="true"] & {
|
||||
@apply start-auto end-2;
|
||||
}
|
||||
|
||||
/* Checkmark SVG indicator */
|
||||
[data-slot="menu-item-indicator--checkmark"] {
|
||||
@apply size-2.5;
|
||||
|
||||
.hv-menu-item[data-selection-mode="multiple"] & {
|
||||
@apply transition-all duration-300 motion-reduce:transition-none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dot SVG indicator */
|
||||
[data-slot="menu-item-indicator--dot"] {
|
||||
@apply size-2;
|
||||
|
||||
.hv-menu-item[data-selection-mode="multiple"] & {
|
||||
@apply transition-all duration-250 motion-reduce:transition-none;
|
||||
}
|
||||
@apply scale-70 opacity-0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Submenu indicator (chevron-right) */
|
||||
.hv-menu-item__indicator--submenu {
|
||||
@apply text-muted;
|
||||
|
||||
svg {
|
||||
@apply size-3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Default variant */
|
||||
.hv-menu-item--default {
|
||||
}
|
||||
|
||||
/* Danger variant */
|
||||
.hv-menu-item--danger {
|
||||
.hv-menu-item__indicator {
|
||||
@apply text-danger;
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply text-danger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue adapters. */
|
||||
/* ==========================================================================
|
||||
Base menu section styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-menu-section {
|
||||
@apply flex flex-col items-start gap-0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* Apache-2.0; see third-party/HEROUI-LICENSE. hv- namespace and Vue adapters. */
|
||||
/* ==========================================================================
|
||||
Base menu styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-menu {
|
||||
@apply relative flex w-full flex-col gap-1 overflow-clip p-1;
|
||||
|
||||
/* This makes the separator take up 94% of the width and be centered */
|
||||
[data-slot="separator"] {
|
||||
@apply ms-[3%] w-[94%];
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,10 @@
|
||||
@import "./components/list-box.css" layer(components);
|
||||
@import "./components/list-box-item.css" layer(components);
|
||||
@import "./components/list-box-section.css" layer(components);
|
||||
@import "./components/menu.css" layer(components);
|
||||
@import "./components/menu-item.css" layer(components);
|
||||
@import "./components/menu-section.css" layer(components);
|
||||
@import "./components/dropdown.css" layer(components);
|
||||
|
||||
@import "./components/select.css" layer(components);
|
||||
|
||||
|
||||
@@ -1580,3 +1580,50 @@ export const tableVariants = tv({
|
||||
});
|
||||
|
||||
export type TableVariants = VariantProps<typeof tableVariants>;
|
||||
|
||||
export const menuVariants = tv({
|
||||
base: "hv-menu",
|
||||
});
|
||||
|
||||
export type MenuVariants = VariantProps<typeof menuVariants>;
|
||||
|
||||
export const menuItemVariants = tv({
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
slots: {
|
||||
indicator: "hv-menu-item__indicator",
|
||||
item: "hv-menu-item",
|
||||
submenuIndicator:
|
||||
"hv-menu-item__indicator hv-menu-item__indicator--submenu",
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
danger: {
|
||||
item: "hv-menu-item--danger",
|
||||
},
|
||||
default: {
|
||||
item: "hv-menu-item--default",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type MenuItemVariants = VariantProps<typeof menuItemVariants>;
|
||||
|
||||
export const menuSectionVariants = tv({
|
||||
base: "hv-menu-section",
|
||||
});
|
||||
|
||||
export type MenuSectionVariants = VariantProps<typeof menuSectionVariants>;
|
||||
|
||||
export const dropdownVariants = tv({
|
||||
slots: {
|
||||
menu: "hv-dropdown__menu",
|
||||
popover: "hv-dropdown__popover",
|
||||
root: "hv-dropdown",
|
||||
trigger: "hv-dropdown__trigger",
|
||||
},
|
||||
});
|
||||
|
||||
export type DropdownVariants = VariantProps<typeof dropdownVariants>;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h } from "vue";
|
||||
import MenuItem from "../menu-item/MenuItem.vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownItem",
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs, slots }) {
|
||||
return () => h(MenuItem as never, attrs, slots);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h } from "vue";
|
||||
import MenuItemIndicator from "../menu-item/MenuItemIndicator.vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownItemIndicator",
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs, slots }) {
|
||||
return () => h(MenuItemIndicator as never, attrs, slots);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h } from "vue";
|
||||
import Menu from "../menu/Menu.vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownMenu",
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs, slots }) {
|
||||
return () => h(Menu as never, attrs, slots);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
provide,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import {
|
||||
DropdownMenuContent as RekaDropdownMenuContent,
|
||||
injectDropdownMenuRootContext,
|
||||
} from "reka-ui";
|
||||
import {
|
||||
dropdownContextKey,
|
||||
menuCloseKey,
|
||||
submenuContentKey,
|
||||
} from "../menu/context";
|
||||
|
||||
/**
|
||||
* Dropdown popover / menu content shell. Provides close for Menu items.
|
||||
* Inside a submenu, renders a style shell (Reka SubContent already positions).
|
||||
*/
|
||||
export default defineComponent({
|
||||
name: "DropdownPopover",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
side: { type: String as PropType<string>, default: undefined },
|
||||
sideOffset: { type: Number, default: undefined },
|
||||
align: { type: String as PropType<string>, default: undefined },
|
||||
alignOffset: { type: Number, default: undefined },
|
||||
avoidCollisions: { type: Boolean, default: undefined },
|
||||
collisionPadding: {
|
||||
type: [Number, Object] as PropType<number | Record<string, number>>,
|
||||
default: undefined,
|
||||
},
|
||||
loop: { type: Boolean, default: undefined },
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
const inSubmenu = inject(submenuContentKey, false);
|
||||
const rootCtx = injectDropdownMenuRootContext(undefined);
|
||||
|
||||
provide(menuCloseKey, () => {
|
||||
rootCtx?.onOpenChange(false);
|
||||
});
|
||||
|
||||
return () => {
|
||||
const cls = [dropdownCtx?.slots.value.popover(), attrs.class];
|
||||
if (inSubmenu) {
|
||||
return h(
|
||||
"div",
|
||||
{
|
||||
...attrs,
|
||||
class: cls,
|
||||
"data-slot": "dropdown-popover",
|
||||
"data-submenu-content": "true",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
}
|
||||
return h(
|
||||
RekaDropdownMenuContent as never,
|
||||
{
|
||||
...attrs,
|
||||
class: cls,
|
||||
"data-slot": "dropdown-popover",
|
||||
side: props.side,
|
||||
sideOffset: props.sideOffset,
|
||||
align: props.align,
|
||||
alignOffset: props.alignOffset,
|
||||
avoidCollisions: props.avoidCollisions,
|
||||
collisionPadding: props.collisionPadding,
|
||||
loop: props.loop,
|
||||
},
|
||||
slots,
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
provide,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { DropdownMenuRoot as RekaDropdownMenuRoot } from "reka-ui";
|
||||
import { dropdownVariants } from "@heroui-vue/styles";
|
||||
import { dropdownContextKey } from "../menu/context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownRoot",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
open: { type: Boolean, default: undefined },
|
||||
defaultOpen: { type: Boolean, default: undefined },
|
||||
dir: { type: String as PropType<"ltr" | "rtl">, default: undefined },
|
||||
modal: { type: Boolean, default: true },
|
||||
},
|
||||
emits: ["update:open"],
|
||||
setup(props, { slots, emit }) {
|
||||
const attrs = useAttrs();
|
||||
const slotsComputed = computed(() => dropdownVariants());
|
||||
provide(dropdownContextKey, { slots: slotsComputed });
|
||||
|
||||
return () =>
|
||||
h(
|
||||
RekaDropdownMenuRoot as never,
|
||||
{
|
||||
...attrs,
|
||||
open: props.open,
|
||||
defaultOpen: props.defaultOpen,
|
||||
dir: props.dir,
|
||||
modal: props.modal,
|
||||
"onUpdate:open": (value: boolean) => emit("update:open", value),
|
||||
},
|
||||
slots,
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h } from "vue";
|
||||
import MenuSection from "../menu-section/MenuSection.vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownSection",
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs, slots }) {
|
||||
return () => h(MenuSection as never, attrs, slots);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h } from "vue";
|
||||
import MenuItemSubmenuIndicator from "../menu-item/MenuItemSubmenuIndicator.vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownSubmenuIndicator",
|
||||
inheritAttrs: false,
|
||||
setup(_, { attrs, slots }) {
|
||||
return () => h(MenuItemSubmenuIndicator as never, attrs, slots);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,71 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
Fragment,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
provide,
|
||||
useAttrs,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import {
|
||||
DropdownMenuSub as RekaDropdownMenuSub,
|
||||
DropdownMenuSubContent as RekaDropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger as RekaDropdownMenuSubTrigger,
|
||||
} from "reka-ui";
|
||||
import { dropdownContextKey, submenuContentKey } from "../menu/context";
|
||||
|
||||
function flatten(nodes: VNodeChild[], out: VNodeChild[] = []): VNodeChild[] {
|
||||
for (const n of nodes) {
|
||||
if (Array.isArray(n)) flatten(n, out);
|
||||
else out.push(n);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submenu trigger matching upstream:
|
||||
* SubmenuTrigger > Item + Popover > Menu
|
||||
* First child is the trigger item; remaining children render inside SubContent.
|
||||
* Nested DropdownPopover becomes a style shell (Reka SubContent already positions).
|
||||
*/
|
||||
export default defineComponent({
|
||||
name: "DropdownSubmenuTrigger",
|
||||
inheritAttrs: false,
|
||||
setup(_, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
provide(submenuContentKey, true);
|
||||
return () => {
|
||||
const children = flatten(slots.default?.() ?? []);
|
||||
const triggerVNode = children[0] ?? null;
|
||||
const contentVNodes = children.slice(1);
|
||||
return h(
|
||||
RekaDropdownMenuSub as never,
|
||||
{},
|
||||
{
|
||||
default: () => [
|
||||
h(
|
||||
RekaDropdownMenuSubTrigger as never,
|
||||
{
|
||||
...attrs,
|
||||
class: [dropdownCtx?.slots.value.trigger(), attrs.class],
|
||||
"data-slot": "dropdown-submenu-trigger",
|
||||
},
|
||||
{ default: () => triggerVNode },
|
||||
),
|
||||
h(
|
||||
RekaDropdownMenuSubContent as never,
|
||||
{
|
||||
class: [dropdownCtx?.slots.value.popover()],
|
||||
"data-slot": "dropdown-popover",
|
||||
},
|
||||
{ default: () => h(Fragment, contentVNodes as never) },
|
||||
),
|
||||
],
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { DropdownMenuTrigger as RekaDropdownMenuTrigger } from "reka-ui";
|
||||
import { dropdownContextKey } from "../menu/context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "DropdownTrigger",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: undefined },
|
||||
asChild: { type: Boolean, default: undefined },
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
return () =>
|
||||
h(
|
||||
RekaDropdownMenuTrigger as never,
|
||||
{
|
||||
...attrs,
|
||||
as: props.as,
|
||||
asChild: props.asChild ?? true,
|
||||
class: [dropdownCtx?.slots.value.trigger(), attrs.class],
|
||||
"data-slot": "dropdown-trigger",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,115 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
mergeProps,
|
||||
provide,
|
||||
ref,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { DropdownMenuItem as RekaMenuItem } from "reka-ui";
|
||||
import { menuItemVariants, type MenuItemVariants } from "@heroui-vue/styles";
|
||||
import {
|
||||
menuContextKey,
|
||||
menuItemContextKey,
|
||||
menuSectionContextKey,
|
||||
type MenuKey,
|
||||
} from "../menu/context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "MenuItem",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
id: { type: [String, Number] as PropType<MenuKey>, default: undefined },
|
||||
textValue: { type: String, default: undefined },
|
||||
isDisabled: { type: Boolean, default: false },
|
||||
disabled: { type: Boolean, default: undefined },
|
||||
variant: {
|
||||
type: String as PropType<MenuItemVariants["variant"]>,
|
||||
default: "default",
|
||||
},
|
||||
/** Set false to keep the menu open after an action item. */
|
||||
closeOnSelect: { type: Boolean, default: undefined },
|
||||
},
|
||||
emits: {
|
||||
select: (_key: MenuKey) => true,
|
||||
},
|
||||
setup(props, { slots, emit }) {
|
||||
const attrs = useAttrs();
|
||||
const menuCtx = inject(menuContextKey, null);
|
||||
const sectionCtx = inject(menuSectionContextKey, null);
|
||||
const owner = sectionCtx?.selection ?? menuCtx?.selection;
|
||||
const hasSubmenu = ref(false);
|
||||
const key = computed<MenuKey>(
|
||||
() => props.id ?? (attrs.id as MenuKey | undefined) ?? "",
|
||||
);
|
||||
|
||||
const isDisabled = computed(
|
||||
() =>
|
||||
props.isDisabled ||
|
||||
props.disabled === true ||
|
||||
(owner?.isItemDisabled(key.value) ?? false),
|
||||
);
|
||||
const isSelected = computed(
|
||||
() => owner?.isItemSelected(key.value) ?? false,
|
||||
);
|
||||
const slotsComputed = computed(() =>
|
||||
menuItemVariants({ variant: props.variant as never }),
|
||||
);
|
||||
|
||||
provide(menuItemContextKey, {
|
||||
slots: slotsComputed,
|
||||
isDisabled,
|
||||
isSelected,
|
||||
hasSubmenu: computed(() => hasSubmenu.value),
|
||||
setHasSubmenu(value: boolean) {
|
||||
hasSubmenu.value = value;
|
||||
},
|
||||
});
|
||||
|
||||
function handleSelect(event?: { preventDefault?: () => void }) {
|
||||
if (isDisabled.value) return;
|
||||
emit("select", key.value);
|
||||
const mode = owner?.selectionMode.value ?? "none";
|
||||
// Submenu trigger items open a nested menu; never close this level.
|
||||
if (hasSubmenu.value) {
|
||||
event?.preventDefault?.();
|
||||
return;
|
||||
}
|
||||
if (mode !== "none") {
|
||||
owner?.proposeSelection(key.value);
|
||||
// Keep the menu open for multi-select; single closes like upstream.
|
||||
if (mode === "single") {
|
||||
menuCtx?.closeLevel();
|
||||
} else {
|
||||
event?.preventDefault?.();
|
||||
}
|
||||
return;
|
||||
}
|
||||
menuCtx?.emitAction(key.value);
|
||||
if (props.closeOnSelect === false) event?.preventDefault?.();
|
||||
else menuCtx?.closeLevel();
|
||||
}
|
||||
|
||||
return () =>
|
||||
h(
|
||||
RekaMenuItem as never,
|
||||
mergeProps(attrs as Record<string, unknown>, {
|
||||
class: [slotsComputed.value.item(), attrs.class],
|
||||
"data-slot": "menu-item",
|
||||
"data-has-submenu": hasSubmenu.value || undefined,
|
||||
"data-selection-mode": owner?.selectionMode.value ?? "none",
|
||||
disabled: isDisabled.value,
|
||||
textValue: props.textValue,
|
||||
// User handlers (if any) run first via mergeProps array.
|
||||
onSelect: (event: unknown) =>
|
||||
handleSelect(event as { preventDefault?: () => void }),
|
||||
}),
|
||||
slots,
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs, type PropType } from "vue";
|
||||
import { menuItemContextKey } from "../menu/context";
|
||||
|
||||
function CheckmarkIcon(selected: boolean) {
|
||||
return h(
|
||||
"svg",
|
||||
{
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "menu-item-indicator--checkmark",
|
||||
fill: "none",
|
||||
role: "presentation",
|
||||
stroke: "currentColor",
|
||||
"stroke-dasharray": 22,
|
||||
"stroke-dashoffset": selected ? 44 : 66,
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
"stroke-width": 2,
|
||||
viewBox: "0 0 17 18",
|
||||
},
|
||||
[h("polyline", { points: "1 9 7 14 15 4" })],
|
||||
);
|
||||
}
|
||||
|
||||
function DotIcon() {
|
||||
return h(
|
||||
"svg",
|
||||
{
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "menu-item-indicator--dot",
|
||||
fill: "currentColor",
|
||||
"fill-rule": "evenodd",
|
||||
role: "presentation",
|
||||
viewBox: "0 0 16 16",
|
||||
xmlns: "http://www.w3.org/2000/svg",
|
||||
},
|
||||
[
|
||||
h("path", {
|
||||
"clip-rule": "evenodd",
|
||||
d: "M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14",
|
||||
"fill-rule": "evenodd",
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "MenuItemIndicator",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "span" },
|
||||
type: {
|
||||
type: String as PropType<"checkmark" | "dot">,
|
||||
default: "checkmark",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const item = inject(menuItemContextKey, null);
|
||||
return () => {
|
||||
const isSelected = item?.isSelected.value ?? false;
|
||||
const content = slots.default
|
||||
? slots.default({ isSelected })
|
||||
: props.type === "dot"
|
||||
? DotIcon()
|
||||
: CheckmarkIcon(isSelected);
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
"aria-hidden": "true",
|
||||
class: [item?.slots.value.indicator(), attrs.class],
|
||||
"data-slot": "menu-item-indicator",
|
||||
"data-type": props.type,
|
||||
"data-visible": isSelected || undefined,
|
||||
},
|
||||
content,
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
useAttrs,
|
||||
} from "vue";
|
||||
import { menuItemContextKey } from "../menu/context";
|
||||
|
||||
function ChevronIcon() {
|
||||
return h(
|
||||
"svg",
|
||||
{
|
||||
"aria-hidden": "true",
|
||||
fill: "none",
|
||||
height: "16",
|
||||
stroke: "currentColor",
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
"stroke-width": "2",
|
||||
viewBox: "0 0 24 24",
|
||||
width: "16",
|
||||
},
|
||||
[h("path", { d: "m9 18 6-6-6-6" })],
|
||||
);
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "MenuItemSubmenuIndicator",
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: "span" } },
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const item = inject(menuItemContextKey, null);
|
||||
item?.setHasSubmenu(true);
|
||||
onMounted(() => item?.setHasSubmenu(true));
|
||||
onUnmounted(() => item?.setHasSubmenu(false));
|
||||
return () => {
|
||||
if (!item?.hasSubmenu.value) return null;
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
"aria-hidden": "true",
|
||||
class: [item.slots.value.submenuIndicator(), attrs.class],
|
||||
"data-slot": "submenu-indicator",
|
||||
},
|
||||
slots.default ? slots.default() : ChevronIcon(),
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,132 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
provide,
|
||||
ref,
|
||||
useAttrs,
|
||||
watch,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { DropdownMenuGroup as RekaMenuGroup } from "reka-ui";
|
||||
import { menuSectionVariants } from "@heroui-vue/styles";
|
||||
import {
|
||||
menuContextKey,
|
||||
menuSectionContextKey,
|
||||
type MenuKey,
|
||||
type MenuSelectionMode,
|
||||
} from "../menu/context";
|
||||
import { useMenuSelection } from "../menu/useMenuSelection";
|
||||
|
||||
export default defineComponent({
|
||||
name: "MenuSection",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "div" },
|
||||
/** Section-level selection mode. Omit to inherit the menu's selection. */
|
||||
selectionMode: {
|
||||
type: String as PropType<MenuSelectionMode>,
|
||||
default: undefined,
|
||||
},
|
||||
selectedKeys: {
|
||||
type: Array as PropType<ReadonlyArray<MenuKey>>,
|
||||
default: undefined,
|
||||
},
|
||||
defaultSelectedKeys: {
|
||||
type: Array as PropType<ReadonlyArray<MenuKey>>,
|
||||
default: () => [],
|
||||
},
|
||||
disabledKeys: {
|
||||
type: Array as PropType<ReadonlyArray<MenuKey>>,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
emits: {
|
||||
"update:selectedKeys": (_keys: MenuKey[]) => true,
|
||||
selectionChange: (_keys: MenuKey[]) => true,
|
||||
},
|
||||
setup(props, { slots, emit }) {
|
||||
const attrs = useAttrs();
|
||||
const menuCtx = inject(menuContextKey, null);
|
||||
const ownsSelection = computed(
|
||||
() =>
|
||||
props.selectionMode !== undefined || props.selectedKeys !== undefined,
|
||||
);
|
||||
|
||||
const internal = ref<MenuKey[]>([...(props.defaultSelectedKeys ?? [])]);
|
||||
const isControlled = computed(() => props.selectedKeys !== undefined);
|
||||
const acceptedKeys = computed(() =>
|
||||
isControlled.value ? (props.selectedKeys ?? []) : internal.value,
|
||||
);
|
||||
const effectiveMode = computed<MenuSelectionMode>(() => {
|
||||
if (props.selectionMode) return props.selectionMode;
|
||||
if (ownsSelection.value) return "multiple";
|
||||
return menuCtx?.selectionMode.value ?? "none";
|
||||
});
|
||||
|
||||
const sectionSelection = useMenuSelection({
|
||||
selectionMode: effectiveMode,
|
||||
selectedKeys: acceptedKeys,
|
||||
disabledKeys: computed(() => props.disabledKeys ?? []),
|
||||
onSelectionChange(next) {
|
||||
if (!isControlled.value) internal.value = next;
|
||||
emit("update:selectedKeys", next);
|
||||
emit("selectionChange", next);
|
||||
},
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.selectedKeys,
|
||||
(next) => {
|
||||
if (next) internal.value = [...next];
|
||||
},
|
||||
);
|
||||
|
||||
provide(menuSectionContextKey, {
|
||||
selection: {
|
||||
get selectionMode() {
|
||||
return ownsSelection.value
|
||||
? sectionSelection.selectionMode
|
||||
: (menuCtx?.selection.selectionMode ??
|
||||
sectionSelection.selectionMode);
|
||||
},
|
||||
get selectedKeys() {
|
||||
return ownsSelection.value
|
||||
? sectionSelection.selectedKeys
|
||||
: (menuCtx?.selection.selectedKeys ??
|
||||
sectionSelection.selectedKeys);
|
||||
},
|
||||
proposeSelection: (key: MenuKey) =>
|
||||
(ownsSelection.value
|
||||
? sectionSelection
|
||||
: (menuCtx?.selection ?? sectionSelection)
|
||||
).proposeSelection(key),
|
||||
isItemSelected: (key: MenuKey) =>
|
||||
(ownsSelection.value
|
||||
? sectionSelection
|
||||
: (menuCtx?.selection ?? sectionSelection)
|
||||
).isItemSelected(key),
|
||||
isItemDisabled: (key: MenuKey) =>
|
||||
(ownsSelection.value
|
||||
? sectionSelection
|
||||
: (menuCtx?.selection ?? sectionSelection)
|
||||
).isItemDisabled(key),
|
||||
},
|
||||
});
|
||||
|
||||
return () =>
|
||||
h(
|
||||
RekaMenuGroup as never,
|
||||
{
|
||||
...attrs,
|
||||
class: [menuSectionVariants(), attrs.class],
|
||||
"data-slot": "menu-section",
|
||||
role: "group",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,104 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
provide,
|
||||
ref,
|
||||
useAttrs,
|
||||
watch,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { menuVariants } from "@heroui-vue/styles";
|
||||
import {
|
||||
dropdownContextKey,
|
||||
menuCloseKey,
|
||||
menuContextKey,
|
||||
type MenuKey,
|
||||
type MenuSelectionMode,
|
||||
} from "./context";
|
||||
import { useMenuSelection } from "./useMenuSelection";
|
||||
|
||||
/**
|
||||
* Menu list: selection/action context + menu styles.
|
||||
* Place inside DropdownPopover (or a Reka menu content) for keyboard nav.
|
||||
*/
|
||||
export default defineComponent({
|
||||
name: "Menu",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: { type: String, default: "div" },
|
||||
selectionMode: {
|
||||
type: String as PropType<MenuSelectionMode>,
|
||||
default: "none",
|
||||
},
|
||||
selectedKeys: {
|
||||
type: Array as PropType<ReadonlyArray<MenuKey>>,
|
||||
default: undefined,
|
||||
},
|
||||
defaultSelectedKeys: {
|
||||
type: Array as PropType<ReadonlyArray<MenuKey>>,
|
||||
default: () => [],
|
||||
},
|
||||
disabledKeys: {
|
||||
type: Array as PropType<ReadonlyArray<MenuKey>>,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
emits: {
|
||||
"update:selectedKeys": (_keys: MenuKey[]) => true,
|
||||
selectionChange: (_keys: MenuKey[]) => true,
|
||||
action: (_key: MenuKey) => true,
|
||||
},
|
||||
setup(props, { slots, emit }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
const closeLevel = inject(menuCloseKey, () => {});
|
||||
const internal = ref<MenuKey[]>([...(props.defaultSelectedKeys ?? [])]);
|
||||
const isControlled = computed(() => props.selectedKeys !== undefined);
|
||||
const acceptedKeys = computed(() =>
|
||||
isControlled.value ? (props.selectedKeys ?? []) : internal.value,
|
||||
);
|
||||
|
||||
const selection = useMenuSelection({
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
selectedKeys: acceptedKeys,
|
||||
disabledKeys: computed(() => props.disabledKeys ?? []),
|
||||
onSelectionChange(next) {
|
||||
if (!isControlled.value) internal.value = next;
|
||||
emit("update:selectedKeys", next);
|
||||
emit("selectionChange", next);
|
||||
},
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.selectedKeys,
|
||||
(next) => {
|
||||
if (next) internal.value = [...next];
|
||||
},
|
||||
);
|
||||
|
||||
provide(menuContextKey, {
|
||||
closeLevel: () => closeLevel(),
|
||||
emitAction: (key: MenuKey) => emit("action", key),
|
||||
selection,
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
});
|
||||
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [dropdownCtx?.slots.value.menu(), menuVariants(), attrs.class]
|
||||
.filter(Boolean)
|
||||
.join(" "),
|
||||
"data-selection-mode": props.selectionMode,
|
||||
"data-slot": "dropdown-menu",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
|
||||
export type MenuKey = string | number;
|
||||
|
||||
export type MenuSelectionMode = "none" | "single" | "multiple";
|
||||
|
||||
export interface MenuSelectionOwner {
|
||||
selectionMode: ComputedRef<MenuSelectionMode>;
|
||||
selectedKeys: ComputedRef<ReadonlyArray<MenuKey>>;
|
||||
/** Submit a selection proposal. Parent decides accepted value. */
|
||||
proposeSelection: (key: MenuKey) => void;
|
||||
isItemSelected: (key: MenuKey) => boolean;
|
||||
isItemDisabled: (key: MenuKey) => boolean;
|
||||
}
|
||||
|
||||
export interface MenuContextValue {
|
||||
/** Close the nearest menu level (not parent menus). */
|
||||
closeLevel: () => void;
|
||||
/** Fire the menu-level action callback. */
|
||||
emitAction: (key: MenuKey) => void;
|
||||
/** Selection owner (menu-level); section may override. */
|
||||
selection: MenuSelectionOwner;
|
||||
/** Root selection mode for data-selection-mode styling. */
|
||||
selectionMode: ComputedRef<MenuSelectionMode>;
|
||||
}
|
||||
|
||||
export const menuContextKey: InjectionKey<MenuContextValue> = Symbol("hv-menu");
|
||||
|
||||
export interface MenuSectionContextValue {
|
||||
selection: MenuSelectionOwner;
|
||||
}
|
||||
|
||||
export const menuSectionContextKey: InjectionKey<MenuSectionContextValue> =
|
||||
Symbol("hv-menu-section");
|
||||
|
||||
export interface MenuItemContextValue {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
slots: ComputedRef<any>;
|
||||
isDisabled: ComputedRef<boolean>;
|
||||
isSelected: ComputedRef<boolean>;
|
||||
hasSubmenu: ComputedRef<boolean>;
|
||||
setHasSubmenu: (value: boolean) => void;
|
||||
}
|
||||
|
||||
export const menuItemContextKey: InjectionKey<MenuItemContextValue> =
|
||||
Symbol("hv-menu-item");
|
||||
|
||||
/** Provided by DropdownPopover / submenu content to close this menu level. */
|
||||
export const menuCloseKey: InjectionKey<() => void> = Symbol("hv-menu-close");
|
||||
|
||||
/** True when a DropdownPopover nests inside DropdownSubmenuTrigger. */
|
||||
export const submenuContentKey: InjectionKey<boolean> = Symbol(
|
||||
"hv-dropdown-submenu-content",
|
||||
);
|
||||
|
||||
export interface DropdownContextValue {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
slots: ComputedRef<any>;
|
||||
}
|
||||
|
||||
export const dropdownContextKey: InjectionKey<DropdownContextValue> =
|
||||
Symbol("hv-dropdown");
|
||||
@@ -0,0 +1,51 @@
|
||||
import { computed, type ComputedRef, type Ref } from "vue";
|
||||
import type {
|
||||
MenuKey,
|
||||
MenuSelectionMode,
|
||||
MenuSelectionOwner,
|
||||
} from "../menu/context";
|
||||
|
||||
export interface UseMenuSelectionOptions {
|
||||
selectionMode: Ref<MenuSelectionMode> | ComputedRef<MenuSelectionMode>;
|
||||
selectedKeys:
|
||||
Ref<ReadonlyArray<MenuKey>> | ComputedRef<ReadonlyArray<MenuKey>>;
|
||||
disabledKeys?:
|
||||
Ref<ReadonlyArray<MenuKey>> | ComputedRef<ReadonlyArray<MenuKey>>;
|
||||
/** Accepted-value update. Return the accepted keys (may reject the proposal). */
|
||||
onSelectionChange: (keys: MenuKey[]) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu/section selection owner. Proposals are one-shot toggles; the parent
|
||||
* emits the next keys and keeps ownership of the accepted value.
|
||||
*/
|
||||
export function useMenuSelection(
|
||||
options: UseMenuSelectionOptions,
|
||||
): MenuSelectionOwner {
|
||||
const isItemSelected = (key: MenuKey) =>
|
||||
options.selectedKeys.value.some((k) => k === key);
|
||||
const isItemDisabled = (key: MenuKey) =>
|
||||
options.disabledKeys?.value.some((k) => k === key) ?? false;
|
||||
|
||||
const proposeSelection = (key: MenuKey) => {
|
||||
const mode = options.selectionMode.value;
|
||||
if (mode === "none") return;
|
||||
const current = options.selectedKeys.value;
|
||||
const has = isItemSelected(key);
|
||||
if (mode === "single") {
|
||||
options.onSelectionChange(has ? [] : [key]);
|
||||
return;
|
||||
}
|
||||
options.onSelectionChange(
|
||||
has ? current.filter((k) => k !== key) : [...current, key],
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
selectionMode: computed(() => options.selectionMode.value),
|
||||
selectedKeys: computed(() => options.selectedKeys.value),
|
||||
proposeSelection,
|
||||
isItemSelected,
|
||||
isItemDisabled,
|
||||
};
|
||||
}
|
||||
@@ -884,3 +884,31 @@ export { toast, toastQueue } from "./components/toast/toast";
|
||||
|
||||
export type { TableKey } from "./components/table/context";
|
||||
export { default as TableLoadMore } from "./components/table/TableLoadMoreItem.vue";
|
||||
|
||||
/* Menu / Dropdown (B01) */
|
||||
export { default as Menu } from "./components/menu/Menu.vue";
|
||||
export { default as MenuRoot } from "./components/menu/Menu.vue";
|
||||
export { default as MenuItem } from "./components/menu-item/MenuItem.vue";
|
||||
export { default as MenuItemIndicator } from "./components/menu-item/MenuItemIndicator.vue";
|
||||
export { default as MenuItemSubmenuIndicator } from "./components/menu-item/MenuItemSubmenuIndicator.vue";
|
||||
export { default as MenuSection } from "./components/menu-section/MenuSection.vue";
|
||||
export { default as DropdownRoot } from "./components/dropdown/DropdownRoot.vue";
|
||||
export { default as DropdownTrigger } from "./components/dropdown/DropdownTrigger.vue";
|
||||
export { default as DropdownPopover } from "./components/dropdown/DropdownPopover.vue";
|
||||
export { default as DropdownMenu } from "./components/dropdown/DropdownMenu.vue";
|
||||
export { default as DropdownSection } from "./components/dropdown/DropdownSection.vue";
|
||||
export { default as DropdownItem } from "./components/dropdown/DropdownItem.vue";
|
||||
export { default as DropdownItemIndicator } from "./components/dropdown/DropdownItemIndicator.vue";
|
||||
export { default as DropdownSubmenuIndicator } from "./components/dropdown/DropdownSubmenuIndicator.vue";
|
||||
export { default as DropdownSubmenuTrigger } from "./components/dropdown/DropdownSubmenuTrigger.vue";
|
||||
export {
|
||||
menuVariants,
|
||||
menuItemVariants,
|
||||
menuSectionVariants,
|
||||
dropdownVariants,
|
||||
type MenuVariants,
|
||||
type MenuItemVariants,
|
||||
type MenuSectionVariants,
|
||||
type DropdownVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type { MenuKey, MenuSelectionMode } from "./components/menu/context";
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, h, ref, nextTick } from "vue";
|
||||
import {
|
||||
Button,
|
||||
DropdownRoot,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSection,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
Label,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuSection,
|
||||
} from "../packages/vue/src";
|
||||
|
||||
const cleanup: (() => void)[] = [];
|
||||
afterEach(() => {
|
||||
cleanup
|
||||
.splice(0)
|
||||
.reverse()
|
||||
.forEach((fn) => fn());
|
||||
vi.useRealTimers();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
function mountApp(setup: () => unknown, render?: () => unknown) {
|
||||
const w = mount(
|
||||
defineComponent(
|
||||
render
|
||||
? { setup: setup as never, render: render as never }
|
||||
: { setup: setup as never },
|
||||
),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
cleanup.push(() => w.unmount());
|
||||
return w;
|
||||
}
|
||||
|
||||
it("Dropdown opens and action item fires once", async () => {
|
||||
const actions: string[] = [];
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(Button, () => "操作"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, { onAction: (k: string) => actions.push(k) }, () => [
|
||||
h(DropdownItem, { id: "new-file", textValue: "新建文件" }, () =>
|
||||
h(Label, () => "新建文件"),
|
||||
),
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "delete-file", textValue: "删除文件", variant: "danger" },
|
||||
() => h(Label, () => "删除文件"),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const items = document.querySelectorAll('[data-slot="menu-item"]');
|
||||
expect(items.length).toBe(2);
|
||||
expect((items[1] as HTMLElement).className).toContain("hv-menu-item--danger");
|
||||
expect((items[0] as HTMLElement).getAttribute("role")).toBe("menuitem");
|
||||
|
||||
(items[0] as HTMLElement).click();
|
||||
await flushPromises();
|
||||
expect(actions).toEqual(["new-file"]);
|
||||
});
|
||||
|
||||
it("Menu multiple selection toggles keys", async () => {
|
||||
const selected = ref<string[]>(["apple"]);
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(Button, () => "水果"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(
|
||||
DropdownMenu,
|
||||
{
|
||||
selectionMode: "multiple",
|
||||
selectedKeys: selected.value,
|
||||
"onUpdate:selectedKeys": (k: (string | number)[]) => {
|
||||
selected.value = k as string[];
|
||||
},
|
||||
},
|
||||
() => [
|
||||
h(DropdownItem, { id: "apple", textValue: "苹果" }, () => [
|
||||
h(DropdownItemIndicator),
|
||||
h(Label, () => "苹果"),
|
||||
]),
|
||||
h(DropdownItem, { id: "banana", textValue: "香蕉" }, () => [
|
||||
h(DropdownItemIndicator),
|
||||
h(Label, () => "香蕉"),
|
||||
]),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const items = document.querySelectorAll('[data-slot="menu-item"]');
|
||||
expect(items.length).toBe(2);
|
||||
(items[1] as HTMLElement).click();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
expect(selected.value).toContain("banana");
|
||||
expect(selected.value).toContain("apple");
|
||||
});
|
||||
|
||||
it("MenuSection can own section-level selection", async () => {
|
||||
const styles = ref<string[]>(["bold"]);
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(Button, () => "样式"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(Menu, {}, () =>
|
||||
h(
|
||||
MenuSection,
|
||||
{
|
||||
selectionMode: "multiple",
|
||||
selectedKeys: styles.value,
|
||||
"onUpdate:selectedKeys": (k: (string | number)[]) => {
|
||||
styles.value = k as string[];
|
||||
},
|
||||
},
|
||||
() => [
|
||||
h(MenuItem, { id: "bold", textValue: "粗体" }, () =>
|
||||
h(Label, () => "粗体"),
|
||||
),
|
||||
h(MenuItem, { id: "italic", textValue: "斜体" }, () =>
|
||||
h(Label, () => "斜体"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const items = document.querySelectorAll('[data-slot="menu-item"]');
|
||||
expect(items.length).toBe(2);
|
||||
(items[1] as HTMLElement).click();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
expect(styles.value).toEqual(expect.arrayContaining(["bold", "italic"]));
|
||||
});
|
||||
|
||||
it("disabled item is marked disabled", async () => {
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(Button, () => "操作"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(Menu, { disabledKeys: ["x"] }, () =>
|
||||
h(MenuItem, { id: "x", textValue: "X" }, () => h(Label, () => "X")),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const item = document.querySelector('[data-slot="menu-item"]') as HTMLElement;
|
||||
expect(item).toBeTruthy();
|
||||
const disabled =
|
||||
item.hasAttribute("disabled") ||
|
||||
item.getAttribute("aria-disabled") === "true" ||
|
||||
item.getAttribute("data-disabled") === "true" ||
|
||||
(item as HTMLInputElement).disabled === true;
|
||||
expect(disabled).toBe(true);
|
||||
});
|
||||
|
||||
it("indicator uses checkmark svg and data-visible when selected", async () => {
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(Button, () => "水果"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(
|
||||
DropdownMenu,
|
||||
{ selectionMode: "multiple", selectedKeys: ["apple"] },
|
||||
() => [
|
||||
h(DropdownItem, { id: "apple", textValue: "苹果" }, () => [
|
||||
h(DropdownItemIndicator),
|
||||
h(Label, () => "苹果"),
|
||||
]),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const ind = document.querySelector('[data-slot="menu-item-indicator"]');
|
||||
expect(ind).toBeTruthy();
|
||||
expect(ind!.getAttribute("data-type")).toBe("checkmark");
|
||||
expect(
|
||||
ind!.querySelector('[data-slot="menu-item-indicator--checkmark"]'),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("submenu trigger opens nested items", async () => {
|
||||
mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true }, () => [
|
||||
h(Button, () => "分享"),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () => [
|
||||
h(DropdownItem, { id: "copy-link", textValue: "复制链接" }, () =>
|
||||
h(Label, () => "复制链接"),
|
||||
),
|
||||
h(DropdownSubmenuTrigger, {}, () => [
|
||||
h(DropdownItem, { id: "share", textValue: "分享" }, () => [
|
||||
h(Label, () => "其他"),
|
||||
h(DropdownSubmenuIndicator),
|
||||
]),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "whatsapp", textValue: "WhatsApp" },
|
||||
() => h(Label, () => "WhatsApp"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const triggers = document.querySelectorAll(
|
||||
'[data-slot="dropdown-submenu-trigger"]',
|
||||
);
|
||||
expect(triggers.length).toBe(1);
|
||||
// Open submenu via pointer (Reka SubTrigger)
|
||||
(triggers[0] as HTMLElement).dispatchEvent(
|
||||
new MouseEvent("pointerenter", { bubbles: true }),
|
||||
);
|
||||
(triggers[0] as HTMLElement).click();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const html = document.body.innerHTML;
|
||||
expect(html).toContain("WhatsApp");
|
||||
expect(html).toContain("其他");
|
||||
expect(
|
||||
document.querySelector('[data-slot="dropdown-submenu-trigger"]'),
|
||||
).toBeTruthy();
|
||||
});
|
||||
Reference in New Issue
Block a user