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:
@@ -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>
|
||||
Reference in New Issue
Block a user