feat: migrate Menu and Dropdown with selection and submenus

Port HeroUI menu family and Dropdown from ce90ea3: Reka DropdownMenu base,
MenuKey[] selection with section owners, 17 official demos, dropdown docs
and B01 tests. Long-press stays demo-level; submenu close is level-scoped.
This commit is contained in:
maoyingjie
2026-10-24 20:43:04 +08:00
parent 1c4ecc3def
commit 06ddb6662a
48 changed files with 3091 additions and 5 deletions
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
const open = ref(false);
</script>
<template>
<div class="flex min-w-sm flex-col items-center justify-center gap-4">
<p class="text-sm text-muted">
下拉菜单:
<strong>{{ open ? "打开" : "关闭" }}</strong>
</p>
<DropdownRoot v-model:open="open">
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<Label>打开文件</Label>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<Label>保存文件</Label>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<Label>删除文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</div>
</template>
+48
View File
@@ -0,0 +1,48 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
Button,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["bold"]);
</script>
<template>
<div class="flex min-w-sm flex-col items-center justify-center gap-4">
<p class="text-sm text-muted">
已选:{{ selected.length > 0 ? selected.join("、") : "无" }}
</p>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu
:selected-keys="selected"
selection-mode="multiple"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownItem id="bold" text-value="粗体">
<Label>粗体</Label>
<DropdownItemIndicator />
</DropdownItem>
<DropdownItem id="italic" text-value="斜体">
<Label>斜体</Label>
<DropdownItemIndicator />
</DropdownItem>
<DropdownItem id="underline" text-value="下划线">
<Label>下划线</Label>
<DropdownItemIndicator />
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</div>
</template>
@@ -0,0 +1,46 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover
class="rounded-xl border border-border/80 bg-surface p-1 shadow-sm"
>
<DropdownMenu>
<DropdownItem
id="rename"
text-value="重命名"
class="rounded-lg data-[focused=true]:bg-default"
>
<Label>重命名</Label>
</DropdownItem>
<DropdownItem
id="duplicate"
text-value="复制"
class="rounded-lg data-[focused=true]:bg-default"
>
<Label>复制</Label>
</DropdownItem>
<DropdownItem
id="delete"
text-value="删除"
variant="danger"
class="rounded-lg data-[focused=true]:bg-danger-soft"
>
<Label>删除</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { IconLogout, IconSettings, IconUsers } from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Avatar,
AvatarImage,
AvatarFallback,
Label,
} from "@heroui-vue/components";
</script>
<template>
<DropdownRoot>
<DropdownTrigger class="rounded-full">
<Avatar>
<AvatarImage
alt="Junior Garcia"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"
/>
<AvatarFallback :delay-ms="600">JD</AvatarFallback>
</Avatar>
</DropdownTrigger>
<DropdownPopover>
<div class="px-3 pt-3 pb-1">
<div class="flex items-center gap-2">
<Avatar size="sm">
<AvatarImage
alt="Jane"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg"
/>
<AvatarFallback :delay-ms="600">JD</AvatarFallback>
</Avatar>
<div class="flex flex-col gap-0">
<p class="text-sm leading-5 font-medium">Jane Doe</p>
<p class="text-xs leading-none text-muted">jane@example.com</p>
</div>
</div>
</div>
<DropdownMenu>
<DropdownItem id="dashboard" text-value="仪表盘">
<Label>仪表盘</Label>
</DropdownItem>
<DropdownItem id="profile" text-value="个人资料">
<Label>个人资料</Label>
</DropdownItem>
<DropdownItem id="settings" text-value="设置">
<div class="flex w-full items-center justify-between gap-2">
<Label>设置</Label>
<IconSettings class="size-3.5 text-muted" />
</div>
</DropdownItem>
<DropdownItem id="new-project" text-value="新建项目">
<div class="flex w-full items-center justify-between gap-2">
<Label>创建团队</Label>
<IconUsers class="size-3.5 text-muted" />
</div>
</DropdownItem>
<DropdownItem id="logout" text-value="退出登录" variant="danger">
<div class="flex w-full items-center justify-between gap-2">
<Label>退出登录</Label>
<IconLogout class="size-3.5 text-danger" />
</div>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
+38
View File
@@ -0,0 +1,38 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
<DropdownItem id="copy-link" text-value="复制链接">
<Label>复制链接</Label>
</DropdownItem>
<DropdownItem id="edit-file" text-value="编辑文件">
<Label>编辑文件</Label>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<Label>删除文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,102 @@
<script setup lang="ts">
import { onBeforeUnmount, ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
} from "@heroui-vue/components";
const open = ref(false);
let pressTimer: ReturnType<typeof setTimeout> | null = null;
let suppressClick = false;
function clearPressTimer() {
if (pressTimer !== null) {
clearTimeout(pressTimer);
pressTimer = null;
}
}
function onPointerDown(e: PointerEvent) {
clearPressTimer();
suppressClick = false;
const startX = e.clientX;
const startY = e.clientY;
pressTimer = setTimeout(() => {
pressTimer = null;
suppressClick = true;
open.value = true;
}, 500);
const onMove = (event: PointerEvent) => {
if (
Math.abs(event.clientX - startX) > 10 ||
Math.abs(event.clientY - startY) > 10
) {
clearPressTimer();
window.removeEventListener("pointermove", onMove);
}
};
window.addEventListener("pointermove", onMove);
const cleanupMove = () => {
window.removeEventListener("pointermove", onMove);
window.removeEventListener("pointerup", cleanupMove);
window.removeEventListener("pointercancel", cleanupMove);
};
window.addEventListener("pointerup", cleanupMove);
window.addEventListener("pointercancel", cleanupMove);
}
function onPointerUp() {
clearPressTimer();
}
function onClick(e: MouseEvent) {
e.preventDefault();
e.stopPropagation();
if (suppressClick) {
suppressClick = false;
return;
}
open.value = false;
}
onBeforeUnmount(clearPressTimer);
</script>
<template>
<DropdownRoot v-model:open="open">
<DropdownTrigger>
<Button
aria-label="菜单"
variant="secondary"
@pointerdown="onPointerDown"
@pointerup="onPointerUp"
@pointercancel="onPointerUp"
@pointerleave="onPointerUp"
@click.capture="onClick"
@contextmenu.prevent
>
长按
</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="new-file" text-value="新建文件">
<Label>新建文件</Label>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<Label>打开文件</Label>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<Label>保存文件</Label>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<Label>删除文件</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,136 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator v-slot="{ isSelected }">
<svg
v-if="isSelected"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="text-accent"
clip-rule="evenodd"
d="M8 15A7 7 0 1 0 8 1a7 7 0 0 0 0 14m3.1-8.55a.75.75 0 1 0-1.2-.9L7.419 8.858L6.03 7.47a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.13-.08z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</DropdownItemIndicator>
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,97 @@
<script setup lang="ts">
import { IconArrowRight } from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSubmenuTrigger,
DropdownSubmenuIndicator,
Button,
Label,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">分享</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="copy-link" text-value="复制链接">
<Label>复制链接</Label>
</DropdownItem>
<DropdownItem id="facebook" text-value="Facebook">
<Label>Facebook</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="share" text-value="分享">
<Label>更多选项</Label>
<DropdownSubmenuIndicator>
<IconArrowRight class="size-3.5 text-muted" />
</DropdownSubmenuIndicator>
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="whatsapp" text-value="WhatsApp">
<Label>WhatsApp</Label>
</DropdownItem>
<DropdownItem id="telegram" text-value="Telegram">
<Label>Telegram</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="email" text-value="邮件">
<Label>Email</Label>
<DropdownSubmenuIndicator>
<svg
class="size-3.5 text-muted"
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M9 18l6-6-6-6" />
</svg>
</DropdownSubmenuIndicator>
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="work" text-value="工作邮箱">
<Label>工作邮箱</Label>
</DropdownItem>
<DropdownItem id="personal" text-value="个人邮箱">
<Label>个人邮箱</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
<DropdownItem id="discord" text-value="Discord">
<Label>Discord</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
<DropdownSubmenuTrigger>
<DropdownItem id="other" text-value="其他">
<Label>其他(默认指示器)</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="sms" text-value="SMS">
<Label>SMS</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,89 @@
<script setup lang="ts">
import {
IconDeviceFloppy,
IconFolderOpen,
IconPlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
Description,
Kbd,
KbdAbbr,
KbdContent,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconFolderOpen class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>打开文件</Label>
<Description>打开已有文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconDeviceFloppy class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>保存文件</Label>
<Description>保存当前文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,83 @@
<script setup lang="ts">
import { IconMenu2, IconPencil, IconPlus, IconTrash } from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSection,
Button,
Label,
Description,
Header,
Kbd,
KbdAbbr,
KbdContent,
Separator,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button is-icon-only aria-label="菜单" variant="secondary">
<IconMenu2 class="outline-none" />
</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[220px]">
<DropdownMenu :disabled-keys="['delete-file']" @action="onAction">
<DropdownSection>
<Header>操作</Header>
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="edit-file" text-value="编辑文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPencil class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>编辑文件</Label>
<Description>进行修改</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>E</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection>
<Header>危险区域</Header>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
+68
View File
@@ -0,0 +1,68 @@
<script setup lang="ts">
import {
IconDeviceFloppy,
IconFolderOpen,
IconPlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
Kbd,
KbdAbbr,
KbdContent,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new-file" text-value="新建文件">
<IconPlus class="size-4 shrink-0 text-muted" />
<Label>新建文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open-file" text-value="打开文件">
<IconFolderOpen class="size-4 shrink-0 text-muted" />
<Label>打开文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save-file" text-value="保存文件">
<IconDeviceFloppy class="size-4 shrink-0 text-muted" />
<Label>保存文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<IconTrash class="size-4 shrink-0 text-danger" />
<Label>删除文件</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,58 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
Button,
Label,
Kbd,
KbdAbbr,
KbdContent,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">操作</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="new" text-value="新建">
<Label>新建</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="open" text-value="打开">
<Label>打开</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>O</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="save" text-value="保存">
<Label>保存</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>S</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="delete" text-value="删除" variant="danger">
<Label>删除</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,56 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">喜爱的水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="multiple"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator />
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator />
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator />
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator />
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator />
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,122 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
Kbd,
KbdAbbr,
KbdContent,
Separator,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const textStyles = ref<MenuKey[]>(["bold", "italic"]);
const textAlignment = ref<MenuKey[]>(["left"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">样式</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu>
<DropdownSection>
<Header>操作</Header>
<DropdownItem id="cut" text-value="剪切">
<Label>剪切</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>X</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="copy" text-value="复制">
<Label>复制</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>C</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="paste" text-value="粘贴">
<Label>粘贴</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>U</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection
:selected-keys="textStyles"
selection-mode="multiple"
@update:selected-keys="(keys: MenuKey[]) => (textStyles = keys)"
>
<Header>文本样式</Header>
<DropdownItem id="bold" text-value="粗体">
<DropdownItemIndicator />
<Label>粗体</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>B</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="italic" text-value="斜体">
<DropdownItemIndicator />
<Label>斜体</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>I</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="underline" text-value="下划线">
<DropdownItemIndicator />
<Label>下划线</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>U</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection
:selected-keys="textAlignment"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (textAlignment = keys)"
>
<Header>文本对齐</Header>
<DropdownItem id="left" text-value="左对齐">
<DropdownItemIndicator type="dot" />
<Label>左对齐</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>A</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="center" text-value="居中">
<DropdownItemIndicator type="dot" />
<Label>居中</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>H</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="right" text-value="右对齐">
<DropdownItemIndicator type="dot" />
<Label>右对齐</Label>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="alt" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,88 @@
<script setup lang="ts">
import {
IconDotsVertical,
IconPencil,
IconPlus,
IconTrash,
} from "@tabler/icons-vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSection,
Button,
Label,
Description,
Header,
Kbd,
KbdAbbr,
KbdContent,
Separator,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button is-icon-only aria-label="菜单" variant="secondary">
<IconDotsVertical class="outline-none" />
</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownSection>
<Header>操作</Header>
<DropdownItem id="new-file" text-value="新建文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPlus class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>新建文件</Label>
<Description>创建新文件</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>N</KbdContent>
</Kbd>
</DropdownItem>
<DropdownItem id="edit-file" text-value="编辑文件">
<div class="flex h-8 items-start justify-center pt-px">
<IconPencil class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>编辑文件</Label>
<Description>进行修改</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>E</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
<Separator />
<DropdownSection>
<Header>危险区域</Header>
<DropdownItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,56 @@
<script setup lang="ts">
import { ref } from "vue";
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownItemIndicator,
DropdownSection,
Button,
Header,
Label,
} from "@heroui-vue/components";
import type { MenuKey } from "@heroui-vue/components";
const selected = ref<MenuKey[]>(["apple"]);
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">水果</Button>
</DropdownTrigger>
<DropdownPopover class="min-w-[256px]">
<DropdownMenu
:selected-keys="selected"
selection-mode="single"
@update:selected-keys="(keys: MenuKey[]) => (selected = keys)"
>
<DropdownSection>
<Header>选择水果</Header>
<DropdownItem id="apple" text-value="苹果">
<DropdownItemIndicator />
<Label>苹果</Label>
</DropdownItem>
<DropdownItem id="banana" text-value="香蕉">
<DropdownItemIndicator />
<Label>香蕉</Label>
</DropdownItem>
<DropdownItem id="cherry" text-value="樱桃">
<DropdownItemIndicator />
<Label>樱桃</Label>
</DropdownItem>
</DropdownSection>
<DropdownItem id="orange" text-value="橙子">
<DropdownItemIndicator />
<Label>橙子</Label>
</DropdownItem>
<DropdownItem id="pear" text-value="梨">
<DropdownItemIndicator />
<Label>梨</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>
@@ -0,0 +1,72 @@
<script setup lang="ts">
import {
DropdownRoot,
DropdownTrigger,
DropdownPopover,
DropdownMenu,
DropdownItem,
DropdownSubmenuTrigger,
DropdownSubmenuIndicator,
Button,
Label,
} from "@heroui-vue/components";
function onAction(key: string | number) {
console.log(`Selected: ${key}`);
}
</script>
<template>
<DropdownRoot>
<DropdownTrigger>
<Button aria-label="菜单" variant="secondary">分享</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu @action="onAction">
<DropdownItem id="copy-link" text-value="复制链接">
<Label>复制链接</Label>
</DropdownItem>
<DropdownItem id="facebook" text-value="Facebook">
<Label>Facebook</Label>
</DropdownItem>
<DropdownItem id="twitter" text-value="Twitter">
<Label>X / Twitter</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="share" text-value="分享">
<Label>其他</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="whatsapp" text-value="WhatsApp">
<Label>WhatsApp</Label>
</DropdownItem>
<DropdownItem id="telegram" text-value="Telegram">
<Label>Telegram</Label>
</DropdownItem>
<DropdownItem id="discord" text-value="Discord">
<Label>Discord</Label>
</DropdownItem>
<DropdownSubmenuTrigger>
<DropdownItem id="email" text-value="邮件">
<Label>Email</Label>
<DropdownSubmenuIndicator />
</DropdownItem>
<DropdownPopover>
<DropdownMenu>
<DropdownItem id="work" text-value="工作邮箱">
<Label>工作邮箱</Label>
</DropdownItem>
<DropdownItem id="personal" text-value="个人邮箱">
<Label>个人邮箱</Label>
</DropdownItem>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownSubmenuTrigger>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
</template>