merge: integrate reviewed AlertDialog Drawer with ListBox main
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const VARIANT_LABELS = {
|
||||
blur: "模糊",
|
||||
opaque: "不透明",
|
||||
transparent: "透明",
|
||||
} as const;
|
||||
const variants = ["opaque", "blur", "transparent"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="variant in variants" :key="variant">
|
||||
<Button variant="secondary">{{ VARIANT_LABELS[variant] }}</Button>
|
||||
<AlertDialogBackdrop :variant="variant">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>
|
||||
背景:{{ VARIANT_LABELS[variant] }}
|
||||
</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
{{
|
||||
variant === "opaque"
|
||||
? "不透明的深色背景会完全遮挡背后内容,让用户把注意力集中在对话框上。"
|
||||
: variant === "blur"
|
||||
? "模糊背景会柔和地虚化背后内容,同时保留一定的环境上下文。"
|
||||
: "透明背景会完整保留背后内容,适合重要性较低的确认场景。"
|
||||
}}
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,87 @@
|
||||
<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>
|
||||
@@ -0,0 +1,149 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { useOverlayState } from "@heroui-vue/components";
|
||||
import {
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const isOpen = ref(false);
|
||||
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">配合 ref / v-model</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="isOpen = true">
|
||||
打开对话框
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="isOpen = !isOpen">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AlertDialogBackdrop v-model:is-open="isOpen">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>由 ref 控制</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
该警告对话框由 Vue 的
|
||||
<code>ref</code>
|
||||
控制。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</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>
|
||||
|
||||
<AlertDialogBackdrop :state="state">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="success" />
|
||||
<AlertDialogHeading>由 useOverlayState() 控制</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
<code>useOverlayState</code>
|
||||
为常见操作提供专用方法,直接使用
|
||||
<code>state.open()</code>
|
||||
、
|
||||
<code>state.close()</code>
|
||||
或
|
||||
<code>state.toggle()</code>
|
||||
即可。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
<script setup lang="ts">
|
||||
import { IconArrowUp, IconSparkles } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const animations = [
|
||||
{
|
||||
name: "运动学缩放",
|
||||
icon: IconSparkles,
|
||||
description:
|
||||
"基于物理感的弹性缩放,模拟高阻尼弹簧:瞬态响应快、回落时间长,适合警告框与模态框。",
|
||||
backdropClass:
|
||||
"data-[entering]:duration-400 data-[entering]:ease-[cubic-bezier(0.16,1,0.3,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.7,0,0.84,0)]",
|
||||
containerClass:
|
||||
"data-[entering]:animate-in data-[entering]:fade-in-0 data-[entering]:zoom-in-95 data-[entering]:duration-400 data-[entering]:ease-[cubic-bezier(0.16,1,0.3,1)] data-[exiting]:animate-out data-[exiting]:fade-out-0 data-[exiting]:zoom-out-95 data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.7,0,0.84,0)]",
|
||||
},
|
||||
{
|
||||
name: "流体滑入",
|
||||
icon: IconArrowUp,
|
||||
description:
|
||||
"模拟在介质中运动并受流体阻力影响,避免机械式线性,更自然、更贴地。",
|
||||
backdropClass:
|
||||
"data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]",
|
||||
containerClass:
|
||||
"data-[entering]:animate-in data-[entering]:fade-in-0 data-[entering]:slide-in-from-bottom-4 data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:animate-out data-[exiting]:fade-out-0 data-[exiting]:slide-out-to-bottom-2 data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]",
|
||||
},
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="animation in animations" :key="animation.name">
|
||||
<Button variant="secondary">{{ animation.name }}</Button>
|
||||
<AlertDialogBackdrop :class="animation.backdropClass">
|
||||
<AlertDialogContainer :class="animation.containerClass">
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent">
|
||||
<component
|
||||
:is="animation.icon"
|
||||
class="size-5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>{{ animation.name }} 动画</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p class="mt-1">{{ animation.description }}</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">关闭</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>再试一次</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { IconAlertTriangle } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="danger">删除账户</Button>
|
||||
<AlertDialogBackdrop
|
||||
class="bg-linear-to-t from-red-950/90 via-red-950/50 to-transparent dark:from-red-950/95 dark:via-red-950/60"
|
||||
variant="blur"
|
||||
>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[420px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader class="items-center text-center">
|
||||
<AlertDialogIcon status="danger">
|
||||
<IconAlertTriangle class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>要永久删除账户吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
此操作无法撤销。你的数据、设置与内容将从服务器永久清除。醒目的红色背景用于强调该决定的严重性与不可逆性。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter class="flex-col-reverse">
|
||||
<AlertDialogClose as-child>
|
||||
<Button class="w-full">保留账户</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button class="w-full" variant="danger">永久删除</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { IconLockOpen } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">重置密码</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="warning">
|
||||
<IconLockOpen class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>要重置密码吗?</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>
|
||||
</template>
|
||||
@@ -0,0 +1,73 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const portalEl = ref<HTMLElement | null>(null);
|
||||
</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="portalEl"
|
||||
class="relative flex h-[380px] items-center justify-center overflow-hidden rounded bg-muted/20"
|
||||
style="transform: translate(0)"
|
||||
>
|
||||
<AlertDialog v-if="portalEl">
|
||||
<Button>打开警告对话框</Button>
|
||||
<AlertDialogBackdrop class="h-full" :to="portalEl">
|
||||
<AlertDialogContainer class="h-full max-h-full">
|
||||
<AlertDialogDialog class="h-full max-h-full sm:max-w-md">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>自定义传送门</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p class="text-sm text-muted">
|
||||
此段为示例占位文案,用于演示在自定义容器内渲染对话框时的滚动与排版效果。
|
||||
</p>
|
||||
<p class="text-sm text-muted">
|
||||
通过将浮层挂载到局部容器,可以配合裁剪、缩放或卡片布局,避免遮挡整个页面。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">退出登录</Button>
|
||||
<AlertDialogBackdrop
|
||||
class="bg-overlay/50 dark:bg-overlay/60"
|
||||
variant="blur"
|
||||
>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog
|
||||
class="relative overflow-hidden border border-border/80 bg-surface shadow-2xl ring-1 ring-accent/10 sm:max-w-[400px] dark:border-border/90 dark:bg-surface dark:ring-accent/15"
|
||||
>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-x-0 top-0 h-24 bg-linear-to-b from-accent/6 to-transparent dark:from-accent/10"
|
||||
/>
|
||||
<AlertDialogHeader class="relative">
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>确定要退出账户吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody class="relative">
|
||||
<p class="text-muted">
|
||||
您将在此设备上退出登录。除非已保存到云端,否则
|
||||
<strong class="text-foreground">Acme 工作区</strong>
|
||||
中未保存的工作可能会丢失。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">保持登录</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>退出登录</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,64 @@
|
||||
<script setup lang="ts">
|
||||
import { IconTrash } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
AlertDialogTrigger,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger
|
||||
class="group flex items-center gap-3 rounded-2xl bg-surface p-4 shadow-xs select-none hover:bg-surface-secondary"
|
||||
>
|
||||
<div
|
||||
class="flex size-12 shrink-0 items-center justify-center rounded-xl bg-danger-soft text-danger-soft-foreground"
|
||||
>
|
||||
<IconTrash class="size-6" aria-hidden="true" />
|
||||
</div>
|
||||
<div class="flex flex-1 flex-col gap-0.5">
|
||||
<p class="text-sm font-semibold">删除条目</p>
|
||||
<p class="text-xs text-muted">永久移除此条目</p>
|
||||
</div>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger">
|
||||
<IconTrash class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>要删除此条目吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
使用
|
||||
<code>AlertDialogTrigger</code>
|
||||
可在标准按钮之外自定义触发区域。此示例展示带图标与说明文字的卡片式触发器。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="danger">删除条目</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="danger">删除项目</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger" />
|
||||
<AlertDialogHeading>要永久删除项目吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
此操作将永久删除
|
||||
<strong>我的精彩项目</strong>
|
||||
及其全部数据,且无法撤销。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="danger">删除项目</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,105 @@
|
||||
<script setup lang="ts">
|
||||
import { IconInfoCircle } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex max-w-sm flex-col gap-6">
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="text-lg font-semibold">isDismissable</h3>
|
||||
<p class="text-sm text-muted">
|
||||
控制是否允许通过点击遮罩关闭对话框。警告框通常需要明确操作,因此默认为
|
||||
<code>false</code>
|
||||
。对重要性较低的确认,可设为
|
||||
<code>true</code>
|
||||
。
|
||||
</p>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">打开警告对话框</Button>
|
||||
<AlertDialogBackdrop :is-dismissable="false">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger">
|
||||
<IconInfoCircle class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>isDismissable = false</AlertDialogHeading>
|
||||
<p class="text-sm leading-5 text-muted">
|
||||
点击遮罩不会关闭此对话框
|
||||
</p>
|
||||
</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">isKeyboardDismissDisabled</h3>
|
||||
<p class="text-sm text-muted">
|
||||
控制是否允许通过 ESC 关闭。警告框通常需要明确操作,因此默认为
|
||||
<code>true</code>
|
||||
(禁用 ESC)。设为
|
||||
<code>false</code>
|
||||
时将允许 ESC 关闭。
|
||||
</p>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">打开警告对话框</Button>
|
||||
<AlertDialogBackdrop :is-keyboard-dismiss-disabled="true">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent">
|
||||
<IconInfoCircle class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>
|
||||
isKeyboardDismissDisabled = true
|
||||
</AlertDialogHeading>
|
||||
<p class="text-sm leading-5 text-muted">已禁用 ESC 关闭</p>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>按下 ESC 不会有任何反应,必须通过操作按钮关闭此对话框。</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
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">
|
||||
<AlertDialog v-for="placement in placements" :key="placement">
|
||||
<Button variant="secondary">{{ PLACEMENT_LABELS[placement] }}</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer :placement="placement">
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>
|
||||
{{
|
||||
placement === "auto"
|
||||
? "自动定位"
|
||||
: `${PLACEMENT_LABELS[placement]}位置`
|
||||
}}
|
||||
</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
{{
|
||||
placement === "auto"
|
||||
? "在移动端默认靠近底部,在桌面端居中,以获得更合适的阅读与操作体验。"
|
||||
: `对话框将锚定在视口的「${PLACEMENT_LABELS[placement]}」区域。重要确认通常使用居中 placement 以吸引最多注意。`
|
||||
}}
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { IconRocket } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const SIZE_LABELS = {
|
||||
cover: "通栏",
|
||||
lg: "大",
|
||||
md: "中",
|
||||
sm: "小",
|
||||
xs: "超小",
|
||||
} as const;
|
||||
const sizes = ["xs", "sm", "md", "lg", "cover"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="size in sizes" :key="size">
|
||||
<Button variant="secondary">{{ SIZE_LABELS[size] }}</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer :size="size">
|
||||
<AlertDialogDialog>
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon class="bg-default text-foreground">
|
||||
<IconRocket aria-hidden="true" class="size-5" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>
|
||||
尺寸:{{ SIZE_LABELS[size] }}
|
||||
</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p v-if="size === 'cover'">
|
||||
此警告框使用
|
||||
<code>cover</code>
|
||||
尺寸:在移动端与桌面端保留边距铺满可视区域,仍保持圆角与标准内边距。
|
||||
</p>
|
||||
<p v-else>
|
||||
此警告框使用
|
||||
<code>{{ size }}</code>
|
||||
尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const examples = [
|
||||
{
|
||||
actions: { cancel: "保持登录", confirm: "退出登录" },
|
||||
body: "退出后需要重新登录才能访问账户,未保存的更改将丢失。",
|
||||
classNames: "bg-accent-soft text-accent-soft-foreground",
|
||||
header: "要退出当前账户吗?",
|
||||
status: "accent",
|
||||
trigger: "退出登录",
|
||||
},
|
||||
{
|
||||
actions: { cancel: "稍后再说", confirm: "标记完成" },
|
||||
body: "将把该任务标记为完成并通知所有成员,任务会移入已完成列表。",
|
||||
classNames: "bg-success-soft text-success-soft-foreground",
|
||||
header: "要完成此任务吗?",
|
||||
status: "success",
|
||||
trigger: "完成任务",
|
||||
},
|
||||
{
|
||||
actions: { cancel: "继续编辑", confirm: "放弃更改" },
|
||||
body: "你有未保存的更改,放弃后将永久丢失。确定要放弃吗?",
|
||||
classNames: "bg-warning-soft text-warning-soft-foreground",
|
||||
header: "要放弃未保存的更改吗?",
|
||||
status: "warning",
|
||||
trigger: "放弃更改",
|
||||
},
|
||||
{
|
||||
actions: { cancel: "取消", confirm: "删除账户" },
|
||||
body: "将永久删除你的账户并从服务器移除全部数据,此操作不可恢复。",
|
||||
classNames: "bg-danger-soft text-danger-soft-foreground",
|
||||
header: "要删除账户吗?",
|
||||
status: "danger",
|
||||
trigger: "删除账户",
|
||||
},
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="example in examples" :key="example.status">
|
||||
<Button :class="example.classNames">{{ example.trigger }}</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon :status="example.status" />
|
||||
<AlertDialogHeading>{{ example.header }}</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>{{ example.body }}</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">{{ example.actions.cancel }}</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button
|
||||
:variant="example.status === 'danger' ? 'danger' : 'primary'"
|
||||
>
|
||||
{{ example.actions.confirm }}
|
||||
</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHandle,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const VARIANT_LABELS = {
|
||||
blur: "模糊",
|
||||
opaque: "不透明",
|
||||
transparent: "透明",
|
||||
} as const;
|
||||
const variants = ["opaque", "blur", "transparent"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<Drawer v-for="variant in variants" :key="variant">
|
||||
<Button variant="secondary">{{ VARIANT_LABELS[variant] }}</Button>
|
||||
<DrawerBackdrop :variant="variant">
|
||||
<DrawerContent>
|
||||
<DrawerDialog>
|
||||
<DrawerHandle />
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>背景:{{ VARIANT_LABELS[variant] }}</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
此抽屉使用
|
||||
<code>{{ variant }}</code>
|
||||
背景变体。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button class="w-full">关闭</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">打开抽屉</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>抽屉标题</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
这是一个从屏幕边缘滑入的抽屉,并通过流畅的 CSS
|
||||
过渡呈现动画效果。可拖动标题或页脚区域关闭。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>确认</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,128 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
useOverlayState,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const isOpen = ref(false);
|
||||
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">配合 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"
|
||||
>
|
||||
<p class="text-xs text-muted">
|
||||
状态:
|
||||
<span class="font-mono font-medium text-foreground">
|
||||
{{ isOpen ? "打开" : "关闭" }}
|
||||
</span>
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<Button size="sm" variant="secondary" @click="isOpen = true">
|
||||
打开抽屉
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="isOpen = !isOpen">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<DrawerBackdrop v-model:is-open="isOpen">
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>由 ref 控制</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
该抽屉由 Vue 的
|
||||
<code>ref</code>
|
||||
控制。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">关闭</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</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>
|
||||
获得
|
||||
<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"
|
||||
>
|
||||
<p class="text-xs text-muted">
|
||||
状态:
|
||||
<span class="font-mono font-medium text-foreground">
|
||||
{{ state.isOpen.value ? "打开" : "关闭" }}
|
||||
</span>
|
||||
</p>
|
||||
<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>
|
||||
<DrawerBackdrop :state="state">
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>由 useOverlayState() 控制</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
<code>useOverlayState</code>
|
||||
为常见操作提供专用方法。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">关闭</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">打开筛选</Button>
|
||||
<DrawerBackdrop variant="blur">
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog class="border-l border-border/80 bg-surface">
|
||||
<DrawerHeader>
|
||||
<DrawerHeading class="text-foreground">筛选</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p class="text-sm text-muted">按状态、负责人或日期缩小结果范围。</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>应用</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
IconBell,
|
||||
IconHome,
|
||||
IconMail,
|
||||
IconMenu2,
|
||||
IconSearch,
|
||||
IconSettings,
|
||||
IconUser,
|
||||
} from "@tabler/icons-vue";
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const navItems = [
|
||||
{ icon: IconHome, label: "首页" },
|
||||
{ icon: IconSearch, label: "搜索" },
|
||||
{ icon: IconBell, label: "通知" },
|
||||
{ icon: IconMail, label: "消息" },
|
||||
{ icon: IconUser, label: "个人资料" },
|
||||
{ icon: IconSettings, label: "设置" },
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">
|
||||
<IconMenu2 aria-hidden="true" class="size-4" />
|
||||
菜单
|
||||
</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="left">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>导航</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<nav class="flex flex-col gap-1">
|
||||
<button
|
||||
v-for="item in navItems"
|
||||
:key="item.label"
|
||||
class="flex items-center gap-3 rounded-xl px-3 py-2.5 text-sm text-foreground transition-colors hover:bg-default"
|
||||
type="button"
|
||||
>
|
||||
<component
|
||||
:is="item.icon"
|
||||
class="size-5 text-muted"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</nav>
|
||||
</DrawerBody>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">重要操作</Button>
|
||||
<DrawerBackdrop :is-dismissable="false">
|
||||
<DrawerContent>
|
||||
<DrawerDialog>
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>确认操作</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
此抽屉无法通过点击外部或拖拽关闭。你必须使用下方按钮之一来完成操作。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>确认</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHandle,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const PLACEMENT_LABELS = {
|
||||
bottom: "底部",
|
||||
left: "左侧",
|
||||
right: "右侧",
|
||||
top: "顶部",
|
||||
} as const;
|
||||
const placements = ["bottom", "top", "left", "right"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<Drawer v-for="placement in placements" :key="placement">
|
||||
<Button variant="secondary">{{ PLACEMENT_LABELS[placement] }}</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent :placement="placement">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHandle v-if="placement === 'bottom'" />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>
|
||||
{{ PLACEMENT_LABELS[placement] }}抽屉
|
||||
</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
此抽屉从屏幕
|
||||
<strong>{{ PLACEMENT_LABELS[placement] }}</strong>
|
||||
边缘滑入。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>完成</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
<DrawerHandle v-if="placement === 'top'" />
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHandle,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">条款与条件</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent>
|
||||
<DrawerDialog>
|
||||
<DrawerHandle />
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>条款与条件</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p v-for="i in 20" :key="i" class="mb-3">
|
||||
段落 {{ i }}:Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
elit. Nullam pulvinar risus non risus hendrerit venenatis.
|
||||
Pellentesque sit amet hendrerit risus, sed porttitor quam.
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">拒绝</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>接受</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
Input,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">编辑资料</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>编辑资料</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<form class="flex flex-col gap-4">
|
||||
<TextField class="w-full" name="name" type="text">
|
||||
<Label>姓名</Label>
|
||||
<Input placeholder="输入你的姓名" variant="secondary" />
|
||||
</TextField>
|
||||
<TextField class="w-full" name="email" type="email">
|
||||
<Label>邮箱</Label>
|
||||
<Input placeholder="输入你的邮箱" variant="secondary" />
|
||||
</TextField>
|
||||
<TextField class="w-full" name="bio">
|
||||
<Label>简介</Label>
|
||||
<Input placeholder="介绍一下你自己" variant="secondary" />
|
||||
</TextField>
|
||||
</form>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>保存更改</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
Reference in New Issue
Block a user