Files
heroui-vue/apps/docs/demos/modal-placements.vue
T

67 lines
2.1 KiB
Vue

<script setup lang="ts">
import {
Button,
Modal,
ModalBackdrop,
ModalBody,
ModalClose,
ModalCloseTrigger,
ModalContainer,
ModalDialog,
ModalFooter,
ModalHeader,
ModalHeading,
ModalIcon,
} from "@heroui-vue/components";
import { IconRocket as Rocket } from "@tabler/icons-vue";
const PLACEMENT_LABELS = {
auto: "自动",
bottom: "底部",
center: "居中",
top: "顶部",
} as const;
const placements = ["auto", "top", "center", "bottom"] as const;
</script>
<template>
<div class="flex flex-wrap gap-4">
<template v-for="placement in placements" :key="placement">
<Modal>
<Button variant="secondary">{{ PLACEMENT_LABELS[placement] }}</Button>
<ModalBackdrop>
<ModalContainer :placement="placement">
<ModalDialog class="sm:max-w-[360px]">
<ModalCloseTrigger></ModalCloseTrigger>
<ModalHeader>
<ModalIcon class="bg-default text-foreground">
<Rocket aria-hidden="true" class="size-5"></Rocket>
</ModalIcon>
<ModalHeading>
{{
placement === "auto"
? "自动定位"
: `${PLACEMENT_LABELS[placement]}位置`
}}
</ModalHeading>
</ModalHeader>
<ModalBody>
<p>
{{
placement === "auto"
? "在移动端默认靠近底部,在桌面端居中,以获得更合适的阅读与操作体验。"
: `模态框将锚定在视口的「${PLACEMENT_LABELS[placement]}」区域。可尝试不同 placement 查看屏幕上的定位效果。`
}}
</p>
</ModalBody>
<ModalFooter>
<ModalClose as-child>
<Button class="w-full">继续</Button>
</ModalClose>
</ModalFooter>
</ModalDialog>
</ModalContainer>
</ModalBackdrop>
</Modal>
</template>
</div>
</template>