feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import OverlayAnimationLab from "./OverlayAnimationLab.vue";
|
||||
const animationLab =
|
||||
typeof window !== "undefined" &&
|
||||
new URLSearchParams(window.location.search).has("overlay-animation");
|
||||
import OverlayLab from "./OverlayLab.vue";
|
||||
import OverlayComponentsLab from "./OverlayComponentsLab.vue";
|
||||
const componentsLab =
|
||||
typeof window !== "undefined" &&
|
||||
new URLSearchParams(window.location.search).has("overlay-components");
|
||||
const overlayLab =
|
||||
typeof window !== "undefined" &&
|
||||
new URLSearchParams(window.location.search).has("overlay-lab");
|
||||
import { Button, Card, Input, Switch } from "@heroui-vue/components";
|
||||
const dark = ref(false),
|
||||
notifications = ref(true),
|
||||
@@ -11,7 +23,10 @@ function save() {
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="lab" :data-theme="dark ? 'dark' : 'light'">
|
||||
<OverlayAnimationLab v-if="animationLab" />
|
||||
<OverlayComponentsLab v-else-if="componentsLab" />
|
||||
<OverlayLab v-else-if="overlayLab" />
|
||||
<div v-else class="lab" :data-theme="dark ? 'dark' : 'light'">
|
||||
<header>
|
||||
<a class="wordmark" href="#">
|
||||
hero
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onBeforeUnmount, ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalHeading,
|
||||
ModalCloseTrigger,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
} from "@heroui-vue/components";
|
||||
const records = ref<string[]>([]);
|
||||
let frame = 0;
|
||||
function record(event: Event) {
|
||||
const el = event.target as HTMLElement;
|
||||
const slot = el.dataset.slot;
|
||||
if (
|
||||
!slot ||
|
||||
!/^(modal-(backdrop|container|dialog)|popover-content|tooltip-content)$/.test(
|
||||
slot,
|
||||
)
|
||||
)
|
||||
return;
|
||||
const css = getComputedStyle(el);
|
||||
const ae = event as AnimationEvent;
|
||||
records.value.push(
|
||||
JSON.stringify({
|
||||
slot,
|
||||
event: event.type,
|
||||
name: ae.animationName,
|
||||
elapsed: ae.elapsedTime,
|
||||
duration: css.animationDuration,
|
||||
easing: css.animationTimingFunction,
|
||||
origin: css.transformOrigin,
|
||||
}),
|
||||
);
|
||||
if (event.type !== "animationstart") return;
|
||||
const start = performance.now();
|
||||
let last = -1;
|
||||
const sample = () => {
|
||||
if (!el.isConnected) return;
|
||||
const bucket = Math.floor((performance.now() - start) / 35);
|
||||
if (bucket !== last) {
|
||||
const c = getComputedStyle(el);
|
||||
records.value.push(
|
||||
JSON.stringify({
|
||||
slot,
|
||||
ms: Math.round(performance.now() - start),
|
||||
enter: el.dataset.entering,
|
||||
exit: el.dataset.exiting,
|
||||
opacity: c.opacity,
|
||||
transform: c.transform,
|
||||
transition: c.transitionDuration,
|
||||
}),
|
||||
);
|
||||
last = bucket;
|
||||
}
|
||||
if (performance.now() - start < 360) frame = requestAnimationFrame(sample);
|
||||
};
|
||||
sample();
|
||||
}
|
||||
onMounted(() => {
|
||||
for (const event of ["animationstart", "animationend", "animationcancel"])
|
||||
document.addEventListener(event, record, true);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
for (const event of ["animationstart", "animationend", "animationcancel"])
|
||||
document.removeEventListener(event, record, true);
|
||||
cancelAnimationFrame(frame);
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<main class="p-8 flex flex-col gap-6">
|
||||
<h1>弹层动画诊断(真实组件)</h1>
|
||||
<p>
|
||||
基线:Modal 内容进入 250ms,遮罩进入 150ms;Popover/Tooltip 进入
|
||||
150ms;退出均 100ms。
|
||||
</p>
|
||||
<div class="flex gap-4">
|
||||
<Modal>
|
||||
<Button>动画 Modal</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog>
|
||||
<ModalHeading>动画检查</ModalHeading>
|
||||
<ModalCloseTrigger />
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
<Popover>
|
||||
<Button>动画 Popover</Button>
|
||||
<PopoverContent>
|
||||
<PopoverDialog>Popover 内容</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Tooltip :delay="0" :close-delay="0">
|
||||
<Button>动画 Tooltip</Button>
|
||||
<TooltipContent>Tooltip 内容</TooltipContent>
|
||||
</Tooltip>
|
||||
<Button variant="secondary" @click="records = []">清空记录</Button>
|
||||
</div>
|
||||
<pre data-testid="animation-records" class="text-xs whitespace-pre-wrap">{{
|
||||
records.join("\n")
|
||||
}}</pre>
|
||||
</main>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalHeading,
|
||||
ModalBody,
|
||||
ModalCloseTrigger,
|
||||
ModalClose,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<main class="lab" style="padding: 2rem">
|
||||
<h1>公开弹层组合回归</h1>
|
||||
<Modal>
|
||||
<Button>打开主弹层</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog>
|
||||
<ModalCloseTrigger />
|
||||
<ModalHeading>主弹层</ModalHeading>
|
||||
<ModalBody class="flex flex-col gap-4">
|
||||
<input aria-label="主层字段" />
|
||||
<Popover>
|
||||
<Button>打开定位层</Button>
|
||||
<PopoverContent>
|
||||
<PopoverDialog class="flex flex-col gap-3">
|
||||
<PopoverHeading>定位层</PopoverHeading>
|
||||
<input aria-label="定位字段" />
|
||||
<Tooltip :delay="0">
|
||||
<Button>提示触发器</Button>
|
||||
<TooltipContent>嵌套提示</TooltipContent>
|
||||
</Tooltip>
|
||||
<Modal>
|
||||
<Button>打开子模态框</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog>
|
||||
<ModalHeading>子模态框</ModalHeading>
|
||||
<input aria-label="子层字段" />
|
||||
<ModalClose as-child>
|
||||
<Button>关闭子层</Button>
|
||||
</ModalClose>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<ModalClose as-child><Button>关闭主层</Button></ModalClose>
|
||||
</ModalBody>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</main>
|
||||
</template>
|
||||
@@ -0,0 +1,213 @@
|
||||
<script setup lang="ts">
|
||||
import { nextTick, ref } from "vue";
|
||||
import {
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
PopoverRoot,
|
||||
PopoverTrigger,
|
||||
PopoverPortal,
|
||||
PopoverContent,
|
||||
} from "../../../packages/vue/src/components/overlay/primitives";
|
||||
import { ConfigProvider, useOverlayState } from "@heroui-vue/components";
|
||||
import OverlayDialogRoot from "../../../packages/vue/src/components/overlay/OverlayDialogRoot.vue";
|
||||
import OverlayDialogContent from "../../../packages/vue/src/components/overlay/OverlayDialogContent.vue";
|
||||
import OverlayPortal from "../../../packages/vue/src/components/overlay/OverlayPortal.vue";
|
||||
import OverlayBackdrop from "../../../packages/vue/src/components/overlay/OverlayBackdrop.vue";
|
||||
|
||||
const opened = ref(false);
|
||||
const dismissable = ref(true);
|
||||
const keyboardDisabled = ref(false);
|
||||
const rejectClose = ref(false);
|
||||
const state = useOverlayState({
|
||||
isOpen: opened,
|
||||
onOpenChange(value) {
|
||||
if (value || !rejectClose.value) opened.value = value;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ConfigProvider teleport-to="#overlay-lab-portals">
|
||||
<main class="overlay-lab">
|
||||
<h1>弹层基础设施验证</h1>
|
||||
<p>私有基础设施探针:使用自编 120ms 动画,不代表 HeroUI 公开组件效果。</p>
|
||||
<p>
|
||||
<a href="http://127.0.0.1:5173/components/modal">
|
||||
正式组件文档(5173)
|
||||
</a>
|
||||
·
|
||||
<a href="?overlay-animation">公开组件动画诊断</a>
|
||||
</p>
|
||||
<label>
|
||||
<input v-model="dismissable" type="checkbox" />
|
||||
允许外部关闭
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="keyboardDisabled" type="checkbox" />
|
||||
禁用 Escape 关闭
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="rejectClose" type="checkbox" />
|
||||
父级拒绝关闭
|
||||
</label>
|
||||
<output data-testid="open-state">{{ opened ? "open" : "closed" }}</output>
|
||||
<OverlayDialogRoot :state="state">
|
||||
<DialogTrigger data-testid="open-modal">打开模态探针</DialogTrigger>
|
||||
<OverlayPortal>
|
||||
<OverlayBackdrop class="lab-backdrop" data-testid="backdrop" />
|
||||
<OverlayDialogContent
|
||||
class="lab-panel"
|
||||
data-testid="modal"
|
||||
:is-dismissable="dismissable"
|
||||
:is-keyboard-dismiss-disabled="keyboardDisabled"
|
||||
>
|
||||
<DialogTitle>主弹层</DialogTitle>
|
||||
<DialogDescription>
|
||||
验证焦点循环、嵌套关闭、受控拒绝与退出生命周期。
|
||||
</DialogDescription>
|
||||
<input aria-label="主弹层输入" />
|
||||
<PopoverRoot>
|
||||
<PopoverTrigger>打开定位探针</PopoverTrigger>
|
||||
<PopoverPortal>
|
||||
<PopoverContent
|
||||
class="lab-floating"
|
||||
aria-label="定位探针"
|
||||
:side-offset="8"
|
||||
>
|
||||
<label>
|
||||
定位探针
|
||||
<input aria-label="浮层输入" />
|
||||
</label>
|
||||
</PopoverContent>
|
||||
</PopoverPortal>
|
||||
</PopoverRoot>
|
||||
<OverlayDialogRoot>
|
||||
<DialogTrigger data-testid="open-nested">
|
||||
打开嵌套弹层
|
||||
</DialogTrigger>
|
||||
<OverlayPortal>
|
||||
<OverlayBackdrop class="lab-backdrop lab-nested-backdrop" />
|
||||
<OverlayDialogContent
|
||||
class="lab-panel lab-nested-panel"
|
||||
data-testid="nested"
|
||||
>
|
||||
<DialogTitle>嵌套弹层</DialogTitle>
|
||||
<DialogDescription>
|
||||
Escape 应先关闭本层,主弹层继续锁定滚动。
|
||||
</DialogDescription>
|
||||
<input aria-label="嵌套输入" />
|
||||
<DialogClose>关闭嵌套弹层</DialogClose>
|
||||
</OverlayDialogContent>
|
||||
</OverlayPortal>
|
||||
</OverlayDialogRoot>
|
||||
<button
|
||||
@click="
|
||||
state.close();
|
||||
nextTick(state.open);
|
||||
"
|
||||
>
|
||||
快速关闭再打开
|
||||
</button>
|
||||
<DialogClose>关闭主弹层</DialogClose>
|
||||
</OverlayDialogContent>
|
||||
</OverlayPortal>
|
||||
</OverlayDialogRoot>
|
||||
<button @click="state.open">命令式打开</button>
|
||||
<button data-testid="outside">外部按钮</button>
|
||||
<div class="lab-scroll-space">滚动区域</div>
|
||||
</main>
|
||||
<div id="overlay-lab-portals" />
|
||||
</ConfigProvider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.overlay-lab {
|
||||
padding: 2rem;
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
max-width: 50rem;
|
||||
margin: auto;
|
||||
}
|
||||
.overlay-lab button,
|
||||
.lab-panel button,
|
||||
.lab-panel input,
|
||||
.lab-floating input {
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
.lab-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 50;
|
||||
background: #0006;
|
||||
}
|
||||
.lab-panel {
|
||||
position: fixed;
|
||||
z-index: 51;
|
||||
top: 20%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: min(30rem, calc(100vw - 2rem));
|
||||
padding: 1.5rem;
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
background: var(--surface, white);
|
||||
color: var(--foreground, #111);
|
||||
border-radius: 1rem;
|
||||
box-shadow: 0 10px 40px #0003;
|
||||
}
|
||||
.lab-nested-backdrop {
|
||||
z-index: 60;
|
||||
}
|
||||
.lab-nested-panel {
|
||||
z-index: 61;
|
||||
top: 25%;
|
||||
}
|
||||
.lab-floating {
|
||||
z-index: 70;
|
||||
padding: 1rem;
|
||||
background: var(--surface, white);
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
.lab-scroll-space {
|
||||
height: 140vh;
|
||||
}
|
||||
.lab-panel[data-state="open"],
|
||||
.lab-backdrop[data-state="open"],
|
||||
.lab-floating[data-state="open"] {
|
||||
animation: lab-enter 120ms ease-out;
|
||||
}
|
||||
.lab-panel[data-state="closed"],
|
||||
.lab-backdrop[data-state="closed"],
|
||||
.lab-floating[data-state="closed"] {
|
||||
animation: lab-exit 120ms ease-in;
|
||||
pointer-events: none;
|
||||
}
|
||||
@keyframes lab-enter {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
@keyframes lab-exit {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.lab-panel,
|
||||
.lab-backdrop,
|
||||
.lab-floating {
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
@import "tailwindcss";
|
||||
@import "../../../packages/styles/dist/styles.css";
|
||||
@import "@heroui-vue/styles/css";
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user