88 lines
3.0 KiB
Vue
88 lines
3.0 KiB
Vue
<script setup lang="ts">
|
||
import {
|
||
AlertDialog,
|
||
AlertDialogBackdrop,
|
||
AlertDialogBody,
|
||
AlertDialogClose,
|
||
AlertDialogContainer,
|
||
AlertDialogDialog,
|
||
AlertDialogFooter,
|
||
AlertDialogHeader,
|
||
AlertDialogHeading,
|
||
AlertDialogIcon,
|
||
Button,
|
||
} from "@heroui-vue/components";
|
||
</script>
|
||
|
||
<template>
|
||
<div class="flex max-w-2xl flex-col gap-8">
|
||
<div class="flex flex-col gap-2">
|
||
<h3 class="text-lg font-semibold">使用 AlertDialogClose</h3>
|
||
<p class="text-sm text-muted">
|
||
在对话框内用
|
||
<code>AlertDialogClose</code>
|
||
包裹按钮,点击后会自动关闭对话框。
|
||
</p>
|
||
<AlertDialog>
|
||
<Button variant="secondary">打开对话框</Button>
|
||
<AlertDialogBackdrop>
|
||
<AlertDialogContainer>
|
||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||
<AlertDialogHeader>
|
||
<AlertDialogIcon status="accent" />
|
||
<AlertDialogHeading>使用 AlertDialogClose</AlertDialogHeading>
|
||
</AlertDialogHeader>
|
||
<AlertDialogBody>
|
||
<p>点击下方任一按钮都会自动关闭对话框。</p>
|
||
</AlertDialogBody>
|
||
<AlertDialogFooter>
|
||
<AlertDialogClose as-child>
|
||
<Button variant="tertiary">取消</Button>
|
||
</AlertDialogClose>
|
||
<AlertDialogClose as-child>
|
||
<Button>确认</Button>
|
||
</AlertDialogClose>
|
||
</AlertDialogFooter>
|
||
</AlertDialogDialog>
|
||
</AlertDialogContainer>
|
||
</AlertDialogBackdrop>
|
||
</AlertDialog>
|
||
</div>
|
||
|
||
<div class="flex flex-col gap-2">
|
||
<h3 class="text-lg font-semibold">使用作用域插槽 close</h3>
|
||
<p class="text-sm text-muted">
|
||
通过 Dialog 的作用域插槽获取
|
||
<code>close</code>
|
||
方法,从而完全控制关闭时机与方式,便于在关闭前加入校验等自定义逻辑。
|
||
</p>
|
||
<AlertDialog>
|
||
<Button variant="secondary">打开对话框</Button>
|
||
<AlertDialogBackdrop>
|
||
<AlertDialogContainer>
|
||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||
<template #default="{ close }">
|
||
<AlertDialogHeader>
|
||
<AlertDialogIcon status="success" />
|
||
<AlertDialogHeading>使用作用域插槽 close</AlertDialogHeading>
|
||
</AlertDialogHeader>
|
||
<AlertDialogBody>
|
||
<p>
|
||
下方按钮使用插槽提供的
|
||
<code>close</code>
|
||
方法。
|
||
</p>
|
||
</AlertDialogBody>
|
||
<AlertDialogFooter>
|
||
<Button variant="tertiary" @click="close()">取消</Button>
|
||
<Button @click="close()">确认</Button>
|
||
</AlertDialogFooter>
|
||
</template>
|
||
</AlertDialogDialog>
|
||
</AlertDialogContainer>
|
||
</AlertDialogBackdrop>
|
||
</AlertDialog>
|
||
</div>
|
||
</div>
|
||
</template>
|