import { createApp, h, ref, defineComponent } from "vue"; import { Button, DropdownRoot, DropdownTrigger, DropdownPopover, DropdownMenu, DropdownSection, DropdownItem, DropdownItemIndicator, DropdownSubmenuTrigger, DropdownSubmenuIndicator, Header, Label, Menu, MenuItem, Modal, ModalTrigger, ModalBackdrop, ModalContainer, ModalDialog, ModalHeader, ModalHeading, ModalBody, ModalFooter, ModalCloseTrigger, } from "@heroui-vue/components"; import "@heroui-vue/styles/css"; const selected = ref(["a"]); const actions = []; window.__actions = actions; const fruits = ["a", "b", "c", "d", "e", "f", "g", "h"]; const names = ["苹果", "香蕉", "樱桃", "橙子", "梨", "葡萄", "西瓜", "芒果"]; const SelectionCase = defineComponent({ name: "SelectionCase", setup() { return () => h("div", { "data-case": "clipping", class: "clip-ancestor" }, [ h(DropdownRoot, { modal: false }, () => [ h(DropdownTrigger, null, () => h(Button, { "aria-label": "水果" }, () => "选择水果"), ), h(DropdownPopover, null, () => h( DropdownMenu, { "aria-label": "水果操作", selectionMode: "multiple", selectedKeys: selected.value, "onUpdate:selectedKeys": (k) => (selected.value = k), }, () => h(DropdownSection, null, () => [ h(Header, null, () => "水果"), ...fruits.map((id, index) => h(DropdownItem, { id, textValue: names[index] }, () => [ h(DropdownItemIndicator), h(Label, null, () => names[index]), ]), ), ]), ), ), ]), ]); }, }); const SubmenuCase = defineComponent({ name: "SubmenuCase", setup() { return () => h("div", { "data-case": "submenu", class: "case" }, [ h(DropdownRoot, { modal: false }, () => [ h(DropdownTrigger, null, () => h(Button, { "aria-label": "分享" }, () => "分享"), ), h(DropdownPopover, null, () => h( DropdownMenu, { onAction: (k) => actions.push(String(k)) }, () => [ h(DropdownItem, { id: "copy", textValue: "复制链接" }, () => h(Label, null, () => "复制链接"), ), h(DropdownSubmenuTrigger, null, () => [ h(DropdownItem, { id: "more", textValue: "更多" }, () => [ h(Label, null, () => "更多"), h(DropdownSubmenuIndicator), ]), h(DropdownPopover, null, () => h(DropdownMenu, null, () => [ h(DropdownItem, { id: "wa", textValue: "WhatsApp" }, () => h(Label, null, () => "WhatsApp"), ), h(DropdownItem, { id: "tg", textValue: "Telegram" }, () => h(Label, null, () => "Telegram"), ), h(DropdownSubmenuTrigger, null, () => [ h( DropdownItem, { id: "mail", textValue: "邮件" }, () => [ h(Label, null, () => "邮件"), h(DropdownSubmenuIndicator), ], ), h(DropdownPopover, null, () => h(DropdownMenu, null, () => h( DropdownItem, { id: "work", textValue: "工作邮箱" }, () => h(Label, null, () => "工作邮箱"), ), ), ), ]), ]), ), ]), h( DropdownItem, { id: "link", textValue: "文档", href: "#docs" }, () => h(Label, null, () => "文档链接"), ), ], ), ), ]), ]); }, }); const ModalCase = defineComponent({ name: "ModalCase", setup() { return () => h("div", { "data-case": "modal", class: "case" }, [ h(Modal, null, () => [ h(ModalTrigger, null, () => h(Button, null, () => "打开组合复核")), h(ModalBackdrop, null, () => h(ModalContainer, null, () => h(ModalDialog, null, () => [ h(ModalHeader, null, () => h(ModalHeading, null, () => "模态内菜单"), ), h(ModalBody, null, () => [ h(DropdownRoot, { modal: false }, () => [ h(DropdownTrigger, null, () => h(Button, { "aria-label": "菜单" }, () => "菜单"), ), h(DropdownPopover, null, () => h(DropdownMenu, null, () => [ h(DropdownItem, { id: "m1", textValue: "一" }, () => h(Label, null, () => "一"), ), h(DropdownItem, { id: "m2", textValue: "二" }, () => h(Label, null, () => "二"), ), ]), ), ]), ]), h(ModalFooter, null, () => h(ModalCloseTrigger, null, () => h(Button, null, () => "关闭"), ), ), ]), ), ), ]), ]); }, }); const WrapCase = defineComponent({ name: "WrapCase", setup() { return () => h("div", { "data-case": "wrap", class: "case" }, [ h(DropdownRoot, { modal: false }, () => [ h(DropdownTrigger, null, () => h(Button, { "aria-label": "循环" }, () => "循环"), ), h(DropdownPopover, null, () => h(DropdownMenu, null, () => h(DropdownSubmenuTrigger, null, () => [ h(DropdownItem, { id: "wrap-sub", textValue: "子菜单" }, () => [ h(Label, null, () => "子菜单"), h(DropdownSubmenuIndicator), ]), h(DropdownPopover, null, () => h(DropdownMenu, { shouldFocusWrap: true }, () => [ h( DropdownItem, { id: "wrap-first", textValue: "First" }, () => h(Label, null, () => "First"), ), h( DropdownItem, { id: "wrap-last", textValue: "Last" }, () => h(Label, null, () => "Last"), ), ]), ), ]), ), ), ]), ]); }, }); const StandaloneCase = defineComponent({ name: "StandaloneCase", setup() { return () => h("div", { "data-case": "standalone", class: "case" }, [ h(Menu, { "aria-label": "内联菜单" }, () => [ h(MenuItem, { id: "s1" }, () => "内联项一"), h(MenuItem, { id: "s2" }, () => "内联项二"), ]), ]); }, }); const only = new URLSearchParams(location.search).get("only"); const cases = { selection: SelectionCase, submenu: SubmenuCase, modal: ModalCase, standalone: StandaloneCase, wrap: WrapCase, }; const shown = only && cases[only] ? [cases[only]] : Object.values(cases); createApp( defineComponent({ name: "App", setup() { return () => h( "main", { style: "display:flex;flex-direction:column;gap:16px;padding:16px" }, shown.map((component) => h(component)), ); }, }), ).mount("#app");