feat: migrate Modal Popover and Tooltip with shared overlay foundation

This commit is contained in:
maoyingjie
2026-10-22 23:39:51 +08:00
parent b086d7f30d
commit 2b4ac04df1
108 changed files with 6888 additions and 100 deletions
+152
View File
@@ -0,0 +1,152 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
ModalBackdrop,
ModalBody,
ModalClose,
ModalCloseTrigger,
ModalContainer,
ModalDialog,
ModalFooter,
ModalHeader,
ModalHeading,
ModalIcon,
useOverlayState,
} from "@heroui-vue/components";
import { IconCircleCheck as CircleCheck } from "@tabler/icons-vue";
const isOpen = ref(false);
function setIsOpen(value: boolean) {
isOpen.value = value;
}
const state = useOverlayState();
</script>
<template>
<div class="flex max-w-md flex-col gap-8">
<div class="flex flex-col gap-3">
<h3 class="text-lg font-semibold text-foreground">配合 Vue ref()</h3>
<p class="text-sm leading-relaxed text-pretty text-muted">
使用 Vue 的
<code class="text-foreground">ref</code>
管理模态框开关,适合简单场景。
</p>
<div
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
>
<div class="flex w-full items-center justify-between">
<p class="text-xs text-muted">
状态:
<span class="font-mono font-medium text-foreground">
{{ isOpen ? "打开" : "关闭" }}
</span>
</p>
</div>
<div class="flex gap-2">
<Button size="sm" variant="secondary" @click="setIsOpen(true)">
打开模态框
</Button>
<Button size="sm" variant="tertiary" @click="setIsOpen(!isOpen)">
切换
</Button>
</div>
</div>
<ModalBackdrop v-model:open="isOpen">
<ModalContainer>
<ModalDialog class="sm:max-w-[360px]">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
<CircleCheck aria-hidden="true" class="size-5"></CircleCheck>
</ModalIcon>
<ModalHeading>由 ref() 控制</ModalHeading>
</ModalHeader>
<ModalBody>
<p>
该模态框由 Vue 的
<code>ref</code>
控制。将
<code>open</code>
与
<code>update:open</code>
传入即可在外部管理状态。
</p>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button variant="secondary">取消</Button>
</ModalClose>
<ModalClose as-child><Button>确认</Button></ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</div>
<div class="flex flex-col gap-3">
<h3 class="text-lg font-semibold text-foreground">
配合 useOverlayState()
</h3>
<p class="text-sm leading-relaxed text-pretty text-muted">
使用
<code class="text-foreground">useOverlayState</code>
获得更简洁的 API,内置
<code>open()</code>
、
<code>close()</code>
、
<code>toggle()</code>
等方法。
</p>
<div
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
>
<div class="flex w-full items-center justify-between">
<p class="text-xs text-muted">
状态:
<span class="font-mono font-medium text-foreground">
{{ state.isOpen.value ? "打开" : "关闭" }}
</span>
</p>
</div>
<div class="flex gap-2">
<Button size="sm" variant="secondary" @click="state.open">
打开模态框
</Button>
<Button size="sm" variant="tertiary" @click="state.toggle">
切换
</Button>
</div>
</div>
<ModalBackdrop :open="state.isOpen.value" @update:open="state.setOpen">
<ModalContainer>
<ModalDialog class="sm:max-w-[360px]">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-success-soft text-success-soft-foreground">
<CircleCheck aria-hidden="true" class="size-5"></CircleCheck>
</ModalIcon>
<ModalHeading>由 useOverlayState() 控制</ModalHeading>
</ModalHeader>
<ModalBody>
<p>
<code>useOverlayState</code>
为常见操作提供专用方法,无需手写回调,直接使用
<code>state.open()</code>
、
<code>state.close()</code>
或
<code>state.toggle()</code>
即可。
</p>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button variant="secondary">取消</Button>
</ModalClose>
<ModalClose as-child><Button>确认</Button></ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</div>
</div>
</template>