Files
heroui-vue/apps/docs/demos/modal-custom-portal.vue
T

67 lines
2.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
Modal,
ModalBackdrop,
ModalContainer,
ModalDialog,
ModalCloseTrigger,
ModalHeader,
ModalHeading,
ModalBody,
ModalFooter,
ModalClose,
} from "@heroui-vue/components";
const portalContainer = ref<HTMLElement>();
</script>
<template>
<div class="flex flex-col gap-4">
<div>
<p class="text-sm">
在自定义容器内渲染模态框,而非
<code>document.body</code>
</p>
<p class="text-sm text-muted">
为容器应用
<code class="rounded px-1 py-0.5 text-xs">
transform: translateZ(0)
</code>
以创建新的层叠上下文。
</p>
</div>
<div
ref="portalContainer"
class="relative flex h-[380px] items-center justify-center overflow-hidden rounded bg-muted/20"
style="transform: translate(0)"
>
<Modal v-if="portalContainer">
<Button>打开模态框</Button>
<ModalBackdrop :to="portalContainer" class="h-full">
<ModalContainer class="h-full max-h-full">
<ModalDialog class="h-full max-h-full sm:max-w-md">
<ModalCloseTrigger />
<ModalHeader>
<ModalHeading>自定义 Portal</ModalHeading>
</ModalHeader>
<ModalBody>
<p v-for="i in 3" :key="i" class="text-sm text-muted">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
</p>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button variant="secondary">关闭</Button>
</ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</Modal>
</div>
</div>
</template>