06ddb6662a
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.
137 lines
4.7 KiB
Vue
137 lines
4.7 KiB
Vue
<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>
|