feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<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 VARIANT_LABELS = {
|
||||
blur: "模糊",
|
||||
opaque: "不透明",
|
||||
transparent: "透明",
|
||||
} as const;
|
||||
const variants = ["opaque", "blur", "transparent"] as const;
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<template v-for="variant in variants" :key="variant">
|
||||
<Modal>
|
||||
<Button variant="secondary">{{ VARIANT_LABELS[variant] }}</Button>
|
||||
<ModalBackdrop :variant="variant">
|
||||
<ModalContainer>
|
||||
<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>背景:{{ VARIANT_LABELS[variant] }}</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
{{
|
||||
variant === "opaque"
|
||||
? "不透明背景会完全遮挡背后内容,让用户把注意力集中在模态框上。"
|
||||
: variant === "blur"
|
||||
? "模糊背景会柔和地虚化背后内容,同时保留一定的环境上下文。"
|
||||
: "透明背景会完整保留背后内容,适合重要性较低的交互场景。"
|
||||
}}
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">继续</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,97 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
IconInfoCircle as CircleInfo,
|
||||
IconCircleCheck as CircleCheck,
|
||||
} from "@tabler/icons-vue";
|
||||
</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">使用 ModalClose</h3>
|
||||
<p class="text-sm text-muted">
|
||||
关闭模态框的最简方式:用
|
||||
<code>ModalClose</code>
|
||||
包装模态框内的 Button,点击即可自动关闭。
|
||||
</p>
|
||||
<Modal>
|
||||
<Button variant="secondary">打开模态框</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
|
||||
<CircleInfo aria-hidden="true" class="size-5"></CircleInfo>
|
||||
</ModalIcon>
|
||||
<ModalHeading>使用 ModalClose</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
点击下方任一按钮——它们都使用
|
||||
<code>ModalClose</code>
|
||||
,会自动关闭模态框。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>确认</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="text-lg font-semibold">使用 Dialog 作用域插槽</h3>
|
||||
<p class="text-sm text-muted">
|
||||
通过 Dialog 的作用域插槽访问
|
||||
<code>close</code>
|
||||
方法,可完全控制关闭时机与方式,并在关闭前加入自定义逻辑。
|
||||
</p>
|
||||
<Modal>
|
||||
<Button variant="secondary">打开模态框</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]" v-slot="slotProps">
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-success-soft text-success-soft-foreground">
|
||||
<CircleCheck aria-hidden="true" class="size-5"></CircleCheck>
|
||||
</ModalIcon>
|
||||
<ModalHeading>使用 Dialog 作用域插槽</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
下方按钮使用作用域插槽中的
|
||||
<code>close</code>
|
||||
方法。可在调用
|
||||
<code>slotProps.close()</code>
|
||||
前进行校验或其他逻辑。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button variant="secondary" @click="slotProps.close()">
|
||||
取消
|
||||
</Button>
|
||||
<Button @click="slotProps.close()">确认</Button>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,152 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
useOverlayState,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCircleCheck as CircleCheck } from "@tabler/icons-vue";
|
||||
const isOpen = ref(false);
|
||||
function setIsOpen(value: boolean) {
|
||||
isOpen.value = value;
|
||||
}
|
||||
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">配合 Vue 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"
|
||||
>
|
||||
<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="setIsOpen(true)">
|
||||
打开模态框
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="setIsOpen(!isOpen)">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<ModalBackdrop v-model:open="isOpen">
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
|
||||
<CircleCheck aria-hidden="true" class="size-5"></CircleCheck>
|
||||
</ModalIcon>
|
||||
<ModalHeading>由 ref() 控制</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
该模态框由 Vue 的
|
||||
<code>ref</code>
|
||||
控制。将
|
||||
<code>open</code>
|
||||
与
|
||||
<code>update:open</code>
|
||||
传入即可在外部管理状态。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>确认</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</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>
|
||||
<ModalBackdrop :open="state.isOpen.value" @update:open="state.setOpen">
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-success-soft text-success-soft-foreground">
|
||||
<CircleCheck aria-hidden="true" class="size-5"></CircleCheck>
|
||||
</ModalIcon>
|
||||
<ModalHeading>由 useOverlayState() 控制</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
<code>useOverlayState</code>
|
||||
为常见操作提供专用方法,无需手写回调,直接使用
|
||||
<code>state.open()</code>
|
||||
、
|
||||
<code>state.close()</code>
|
||||
或
|
||||
<code>state.toggle()</code>
|
||||
即可。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>确认</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,115 @@
|
||||
<script setup lang="ts">
|
||||
import type { Component } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
IconSparkles as Sparkles,
|
||||
IconArrowBarUp as ArrowUpFromLine,
|
||||
} from "@tabler/icons-vue";
|
||||
const iconMap: Record<string, Component> = {
|
||||
"tabler:arrow-bar-up": ArrowUpFromLine,
|
||||
"tabler:sparkles": Sparkles,
|
||||
};
|
||||
const animations = [
|
||||
{
|
||||
classNames: {
|
||||
backdrop: [
|
||||
"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)]",
|
||||
].join(" "),
|
||||
container: [
|
||||
"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)]",
|
||||
].join(" "),
|
||||
},
|
||||
description:
|
||||
"基于物理的弹性缩放,模拟高阻尼弹簧系统:快速瞬态响应与较长 settling 时间。适用于模态框与弹出层。",
|
||||
icon: "tabler:sparkles",
|
||||
name: "运动缩放",
|
||||
},
|
||||
{
|
||||
classNames: {
|
||||
backdrop: [
|
||||
"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)]",
|
||||
].join(" "),
|
||||
container: [
|
||||
"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)]",
|
||||
].join(" "),
|
||||
},
|
||||
description:
|
||||
"模拟流体阻力中的运动,摆脱机械式线性动画,呈现更自然、沉稳的质感。适用于底部抽屉或 Toast。",
|
||||
icon: "tabler:arrow-bar-up",
|
||||
name: "流体滑入",
|
||||
},
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<template
|
||||
v-for="{ classNames, description, icon, name } in animations"
|
||||
:key="name"
|
||||
>
|
||||
<Modal>
|
||||
<Button variant="secondary">{{ name }}</Button>
|
||||
<ModalBackdrop :class="classNames.backdrop">
|
||||
<ModalContainer :class="classNames.container">
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-default text-foreground">
|
||||
<template v-if="!!iconMap[icon]">
|
||||
<component :is="iconMap[icon]" class="size-5"></component>
|
||||
</template>
|
||||
</ModalIcon>
|
||||
<ModalHeading>{{ name }} 动画</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p class="mt-1">{{ description }}</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="tertiary">关闭</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>再试一次</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconSparkles as Sparkles } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<Modal>
|
||||
<Button variant="secondary">自定义背景</Button>
|
||||
<ModalBackdrop
|
||||
class="bg-linear-to-t from-black/80 via-black/40 to-transparent dark:from-zinc-800/80 dark:via-zinc-800/40"
|
||||
variant="blur"
|
||||
>
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalHeader class="items-center text-center">
|
||||
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
|
||||
<Sparkles aria-hidden="true" class="size-5"></Sparkles>
|
||||
</ModalIcon>
|
||||
<ModalHeading>高级背景</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
此背景采用从底部深色过渡到顶部完全透明的精致渐变,并配合柔和的模糊效果。渐变会在浅色与深色模式下自动调整强度,以获得最佳对比度。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter class="flex-col-reverse">
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">Amazing!</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full" variant="secondary">关闭</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<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>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCircleCheck as CircleCheck } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<Modal>
|
||||
<Button variant="secondary">打开</Button>
|
||||
<ModalBackdrop class="bg-overlay/50 dark:bg-overlay/65" variant="blur">
|
||||
<ModalContainer>
|
||||
<ModalDialog
|
||||
class="relative overflow-hidden border border-border/80 bg-surface/90 shadow-2xl ring-1 ring-black/5 backdrop-blur-xl sm:max-w-[340px] dark:border-border/90 dark:bg-surface/85 dark:ring-white/10"
|
||||
>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-x-0 top-0 h-20 bg-linear-to-b from-neutral-500/8 to-transparent dark:from-neutral-400/10"
|
||||
></div>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-x-10 top-0 h-px bg-linear-to-r from-transparent via-neutral-400/40 to-transparent dark:via-neutral-500/35"
|
||||
></div>
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader class="relative">
|
||||
<ModalIcon
|
||||
class="bg-neutral-100 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-200"
|
||||
>
|
||||
<CircleCheck aria-hidden="true" class="size-5"></CircleCheck>
|
||||
</ModalIcon>
|
||||
<ModalHeading>更改已保存</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody class="relative">
|
||||
<p class="text-sm text-muted">你的草稿已在各设备间同步。</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">完成</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
ModalTrigger,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconSettings as Gear } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<Modal>
|
||||
<ModalTrigger
|
||||
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-accent-soft text-accent-soft-foreground"
|
||||
>
|
||||
<Gear aria-hidden="true" class="size-6"></Gear>
|
||||
</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>
|
||||
</ModalTrigger>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
|
||||
<Gear aria-hidden="true" class="size-5"></Gear>
|
||||
</ModalIcon>
|
||||
<ModalHeading>设置</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
使用
|
||||
<code>Modal.Trigger</code>
|
||||
可在标准按钮之外创建自定义触发器。此示例展示带图标与说明文字的卡片式触发器。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>保存</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<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";
|
||||
</script>
|
||||
<template>
|
||||
<Modal>
|
||||
<Button variant="secondary">打开模态框</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<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>欢迎使用 HeroUI</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
一套美观、快速、现代的 Vue UI 库,可轻松构建无障碍且高度可定制的
|
||||
Web 应用。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">继续</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,96 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconInfoCircle as CircleInfo } from "@tabler/icons-vue";
|
||||
</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>true</code>
|
||||
。设为
|
||||
<code>false</code>
|
||||
时需通过明确操作关闭。
|
||||
</p>
|
||||
<Modal>
|
||||
<Button variant="secondary">打开模态框</Button>
|
||||
<ModalBackdrop :isDismissable="false">
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-default text-foreground">
|
||||
<CircleInfo aria-hidden="true" class="size-5"></CircleInfo>
|
||||
</ModalIcon>
|
||||
<ModalHeading>isDismissable = false</ModalHeading>
|
||||
<p class="text-sm leading-5 text-muted">
|
||||
点击遮罩不会关闭此模态框
|
||||
</p>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
尝试点击遮罩区域——模态框不会关闭,必须使用关闭按钮或按 ESC
|
||||
键关闭。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">关闭</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</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,用户须通过明确操作关闭。
|
||||
</p>
|
||||
<Modal>
|
||||
<Button variant="secondary">打开模态框</Button>
|
||||
<ModalBackdrop isKeyboardDismissDisabled>
|
||||
<ModalContainer>
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-default text-foreground">
|
||||
<CircleInfo aria-hidden="true" class="size-5"></CircleInfo>
|
||||
</ModalIcon>
|
||||
<ModalHeading>isKeyboardDismissDisabled = true</ModalHeading>
|
||||
<p class="text-sm leading-5 text-muted">已禁用 ESC 键</p>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
按 ESC 无反应。必须使用关闭按钮或点击遮罩才能关闭此模态框。
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button class="w-full">关闭</Button>
|
||||
</ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<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>
|
||||
@@ -0,0 +1,83 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
Radio,
|
||||
RadioContent,
|
||||
RadioControl,
|
||||
RadioGroup,
|
||||
RadioIndicator,
|
||||
} from "@heroui-vue/components";
|
||||
const scroll = ref<"inside" | "outside">("inside");
|
||||
function setScroll(value: "inside" | "outside") {
|
||||
scroll.value = value;
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<RadioGroup
|
||||
orientation="horizontal"
|
||||
:model-value="scroll"
|
||||
@update:model-value="(value) => setScroll(value as 'inside' | 'outside')"
|
||||
>
|
||||
<Radio value="inside">
|
||||
<RadioContent>
|
||||
<RadioControl><RadioIndicator></RadioIndicator></RadioControl>
|
||||
内部
|
||||
</RadioContent>
|
||||
</Radio>
|
||||
<Radio value="outside">
|
||||
<RadioContent>
|
||||
<RadioControl><RadioIndicator></RadioIndicator></RadioControl>
|
||||
外部
|
||||
</RadioContent>
|
||||
</Radio>
|
||||
</RadioGroup>
|
||||
<Modal>
|
||||
<Button variant="secondary">
|
||||
打开模态框({{ scroll.charAt(0).toUpperCase() + scroll.slice(1) }})
|
||||
</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer :scroll="scroll">
|
||||
<ModalDialog class="sm:max-w-[360px]">
|
||||
<ModalHeader>
|
||||
<ModalHeading>
|
||||
{{ scroll === "inside" ? "滚动:内部" : "滚动:外部" }}
|
||||
</ModalHeading>
|
||||
<p class="text-sm leading-5 text-muted">
|
||||
对比滚动行为——内部在模态框内滚动内容,外部允许页面滚动
|
||||
</p>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<template v-for="(_, i) in Array.from({ length: 30 })" :key="i">
|
||||
<p class="mb-3">
|
||||
段落 {{ i + 1 }}: Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit. Nullam pulvinar risus non risus hendrerit
|
||||
venenatis. Pellentesque sit amet hendrerit risus, sed
|
||||
porttitor quam.
|
||||
</p>
|
||||
</template>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>确认</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
<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 SIZE_LABELS = {
|
||||
cover: "通栏",
|
||||
full: "全屏",
|
||||
lg: "大",
|
||||
md: "中",
|
||||
sm: "小",
|
||||
xs: "超小",
|
||||
} as const;
|
||||
const sizes = ["xs", "sm", "md", "lg", "cover", "full"] as const;
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<template v-for="size in sizes" :key="size">
|
||||
<Modal>
|
||||
<Button variant="secondary">{{ SIZE_LABELS[size] }}</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer :size="size">
|
||||
<ModalDialog>
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-default text-foreground">
|
||||
<Rocket aria-hidden="true" class="size-5"></Rocket>
|
||||
</ModalIcon>
|
||||
<ModalHeading>尺寸:{{ SIZE_LABELS[size] }}</ModalHeading>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>
|
||||
<template v-if="size === 'cover'">
|
||||
此模态框使用
|
||||
<code>cover</code>
|
||||
尺寸:在移动端与桌面端保留边距(移动端约 16px、桌面端约
|
||||
40px)铺满可视区域,仍保持圆角与标准内边距,适合需要最大宽度又保留模态框气质的内容展示。
|
||||
</template>
|
||||
<template v-else>
|
||||
<template v-if="size === 'full'">
|
||||
此模态框使用
|
||||
<code>full</code>
|
||||
尺寸,占满整个视口,无边距、圆角或阴影,提供真正的全屏体验,适合沉浸式内容或全页交互。
|
||||
</template>
|
||||
<template v-else>
|
||||
此模态框使用
|
||||
<code>{{ size }}</code>
|
||||
尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度,以适配不同信息量。
|
||||
</template>
|
||||
</template>
|
||||
</p>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<ModalClose as-child><Button>确认</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, useId } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Input,
|
||||
Label,
|
||||
Modal,
|
||||
ModalBackdrop,
|
||||
ModalBody,
|
||||
ModalClose,
|
||||
ModalCloseTrigger,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalIcon,
|
||||
Surface,
|
||||
TextField,
|
||||
useOverlayState,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail as Envelope } from "@tabler/icons-vue";
|
||||
const state = useOverlayState();
|
||||
const formId = useId();
|
||||
const result = ref<Record<string, FormDataEntryValue>>();
|
||||
function submit(event: SubmitEvent) {
|
||||
result.value = Object.fromEntries(
|
||||
new FormData(event.currentTarget as HTMLFormElement),
|
||||
);
|
||||
state.close();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<Modal :state="state">
|
||||
<Button variant="secondary">打开联系表单</Button>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer placement="auto">
|
||||
<ModalDialog class="sm:max-w-md">
|
||||
<ModalCloseTrigger></ModalCloseTrigger>
|
||||
<ModalHeader>
|
||||
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
|
||||
<Envelope aria-hidden="true" class="size-5"></Envelope>
|
||||
</ModalIcon>
|
||||
<ModalHeading>联系我们</ModalHeading>
|
||||
<p class="mt-1.5 text-sm leading-5 text-muted">
|
||||
填写下方表单,我们会尽快回复。在移动端弹出键盘时,模态框会自动适配。
|
||||
</p>
|
||||
</ModalHeader>
|
||||
<ModalBody class="p-6">
|
||||
<Surface variant="default">
|
||||
<form
|
||||
:id="formId"
|
||||
class="flex flex-col gap-4"
|
||||
@submit.prevent="submit"
|
||||
>
|
||||
<TextField class="w-full" name="name" type="text">
|
||||
<Label>姓名</Label>
|
||||
<Input placeholder="输入你的姓名"></Input>
|
||||
</TextField>
|
||||
<TextField class="w-full" name="email" type="email">
|
||||
<Label>邮箱</Label>
|
||||
<Input placeholder="输入你的邮箱"></Input>
|
||||
</TextField>
|
||||
<TextField class="w-full" name="phone" type="tel">
|
||||
<Label>电话</Label>
|
||||
<Input placeholder="输入你的电话号码"></Input>
|
||||
</TextField>
|
||||
<TextField class="w-full" name="company">
|
||||
<Label>公司</Label>
|
||||
<Input placeholder="输入公司名称"></Input>
|
||||
</TextField>
|
||||
<TextField class="w-full" name="message">
|
||||
<Label>留言</Label>
|
||||
<Input placeholder="输入留言内容"></Input>
|
||||
</TextField>
|
||||
</form>
|
||||
</Surface>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</ModalClose>
|
||||
<Button type="submit" :form="formId">发送消息</Button>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
<p v-if="result" role="status" class="mt-3 text-sm text-muted">
|
||||
已记录表单:{{ result }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Popover>
|
||||
<Button>点击我</Button>
|
||||
<PopoverContent class="max-w-64">
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>弹出层标题</PopoverHeading>
|
||||
<p class="mt-2 text-sm text-muted">
|
||||
这是弹出层内容,你可以在这里放置任何内容。
|
||||
</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Popover>
|
||||
<Button variant="secondary">详情</Button>
|
||||
<PopoverContent
|
||||
class="max-w-56 overflow-hidden rounded-xl border border-border/80 bg-surface/90 p-0 shadow-xl ring-1 ring-black/5 backdrop-blur-xl dark:border-border/90 dark:bg-surface/85 dark:ring-white/10"
|
||||
>
|
||||
<PopoverDialog class="relative p-4">
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-x-0 top-0 h-12 bg-linear-to-b from-neutral-500/6 to-transparent dark:from-neutral-400/8"
|
||||
></div>
|
||||
<PopoverHeading
|
||||
class="relative font-medium text-neutral-800 dark:text-neutral-100"
|
||||
>
|
||||
键盘快捷键
|
||||
</PopoverHeading>
|
||||
<dl class="relative mt-3 space-y-2 text-sm">
|
||||
<div class="flex justify-between gap-4">
|
||||
<dt class="text-muted">保存</dt>
|
||||
<dd class="font-mono text-neutral-700 dark:text-neutral-300">
|
||||
⌘ S
|
||||
</dd>
|
||||
</div>
|
||||
<div class="flex justify-between gap-4">
|
||||
<dt class="text-muted">搜索</dt>
|
||||
<dd class="font-mono text-neutral-700 dark:text-neutral-300">
|
||||
⌘ K
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</template>
|
||||
@@ -0,0 +1,81 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Avatar,
|
||||
AvatarFallback,
|
||||
AvatarImage,
|
||||
Button,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
PopoverTrigger,
|
||||
} from "@heroui-vue/components";
|
||||
const isFollowing = ref(false);
|
||||
function setIsFollowing(value: boolean) {
|
||||
isFollowing.value = value;
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<Popover>
|
||||
<PopoverTrigger aria-label="用户资料">
|
||||
<div class="flex items-center gap-2">
|
||||
<Avatar size="sm">
|
||||
<AvatarImage
|
||||
alt="Sarah Johnson"
|
||||
src="https://img.heroui.chat/image/avatar?w=400&h=400&u=1"
|
||||
></AvatarImage>
|
||||
<AvatarFallback>SJ</AvatarFallback>
|
||||
</Avatar>
|
||||
<div class="flex flex-col">
|
||||
<p class="text-sm font-medium">Sarah Johnson</p>
|
||||
<p class="text-xs text-muted">@sarahj</p>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="w-[320px]">
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<Avatar size="md">
|
||||
<AvatarImage
|
||||
alt="Sarah Johnson"
|
||||
src="https://img.heroui.chat/image/avatar?w=400&h=400&u=1"
|
||||
></AvatarImage>
|
||||
<AvatarFallback>SJ</AvatarFallback>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p class="font-semibold">Sarah Johnson</p>
|
||||
<p class="text-sm text-muted">@sarahj</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
class="rounded-full"
|
||||
size="sm"
|
||||
:variant="isFollowing ? 'tertiary' : 'primary'"
|
||||
@click="setIsFollowing(!isFollowing)"
|
||||
>
|
||||
{{ isFollowing ? "已关注" : "关注" }}
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverHeading>
|
||||
<p class="mt-3 text-sm text-muted">
|
||||
产品设计师兼创意总监,打造有意义的美好体验。
|
||||
</p>
|
||||
<div class="mt-3 flex gap-4">
|
||||
<div>
|
||||
<span class="font-semibold">892</span>
|
||||
<span class="ms-1 text-sm text-muted">关注中</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="font-semibold">12.5K</span>
|
||||
<span class="ms-1 text-sm text-muted">粉丝</span>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverArrow,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div></div>
|
||||
<Popover>
|
||||
<Button class="w-full" variant="tertiary">Top</Button>
|
||||
<PopoverContent placement="top">
|
||||
<PopoverDialog>
|
||||
<PopoverArrow></PopoverArrow>
|
||||
<p class="text-sm">顶部位置</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div></div>
|
||||
<Popover>
|
||||
<Button class="w-full" variant="tertiary">Left</Button>
|
||||
<PopoverContent placement="left">
|
||||
<PopoverDialog>
|
||||
<PopoverArrow></PopoverArrow>
|
||||
<p class="text-sm">左侧位置</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div class="flex items-center justify-center">
|
||||
<span class="text-sm text-muted">点击按钮</span>
|
||||
</div>
|
||||
<Popover>
|
||||
<Button class="w-full" variant="tertiary">Right</Button>
|
||||
<PopoverContent placement="right">
|
||||
<PopoverDialog>
|
||||
<PopoverArrow></PopoverArrow>
|
||||
<p class="text-sm">右侧位置</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div></div>
|
||||
<Popover>
|
||||
<Button class="w-full" variant="tertiary">Bottom</Button>
|
||||
<PopoverContent placement="bottom">
|
||||
<PopoverDialog>
|
||||
<PopoverArrow></PopoverArrow>
|
||||
<p class="text-sm">底部位置</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div></div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Popover>
|
||||
<Button>点击我</Button>
|
||||
<PopoverContent class="max-w-64" as="div" data-custom="foo">
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>弹出层标题</PopoverHeading>
|
||||
<p class="mt-2 text-sm text-muted">
|
||||
这是弹出层内容,你可以在这里放置任何内容。
|
||||
</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
PopoverArrow,
|
||||
PopoverContent,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconDots as Ellipsis } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Popover>
|
||||
<Button variant="secondary">带箭头</Button>
|
||||
<PopoverContent class="max-w-64">
|
||||
<PopoverDialog>
|
||||
<PopoverArrow></PopoverArrow>
|
||||
<PopoverHeading>带箭头的弹出层</PopoverHeading>
|
||||
<p class="mt-2 text-sm text-muted">箭头指向触发弹出层的元素。</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Popover>
|
||||
<Button isIconOnly aria-label="更多选项" variant="tertiary">
|
||||
<Ellipsis aria-hidden="true"></Ellipsis>
|
||||
</Button>
|
||||
<PopoverContent class="max-w-64" :offset="10">
|
||||
<PopoverDialog>
|
||||
<PopoverArrow></PopoverArrow>
|
||||
<PopoverHeading>带箭头的弹出层</PopoverHeading>
|
||||
<p class="mt-2 text-sm text-muted">箭头指向触发弹出层的元素。</p>
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { Button, Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
import { IconInfoCircle as CircleInfo } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Tooltip :delay="0">
|
||||
<Button variant="secondary">悬停查看</Button>
|
||||
<TooltipContent><p>这是一个工具提示</p></TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip :delay="0">
|
||||
<Button isIconOnly aria-label="更多信息" variant="tertiary">
|
||||
<CircleInfo aria-hidden="true"></CircleInfo>
|
||||
</Button>
|
||||
<TooltipContent><p>更多信息</p></TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { Button, Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Tooltip :delay="0">
|
||||
<Button variant="secondary">分享链接</Button>
|
||||
<TooltipContent
|
||||
class="rounded-lg border border-border/80 bg-surface px-2.5 py-1 text-xs text-foreground shadow-sm"
|
||||
>
|
||||
<p>已复制到剪贴板</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</template>
|
||||
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Avatar,
|
||||
AvatarFallback,
|
||||
AvatarImage,
|
||||
Chip,
|
||||
ChipLabel,
|
||||
Tooltip,
|
||||
TooltipArrow,
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
IconCircleCheckFilled as CircleCheckFill,
|
||||
IconHelpCircle as CircleQuestion,
|
||||
} from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-6">
|
||||
<Tooltip :delay="0">
|
||||
<TooltipTrigger aria-label="用户头像">
|
||||
<Avatar size="sm">
|
||||
<AvatarImage
|
||||
alt="Jane Doe"
|
||||
src="https://img.heroui.chat/image/avatar?w=400&h=400&u=4"
|
||||
></AvatarImage>
|
||||
<AvatarFallback>JD</AvatarFallback>
|
||||
</Avatar>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent showArrow>
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<div class="flex flex-col gap-0 py-1">
|
||||
<p class="font-semibold">Jane Doe</p>
|
||||
<p class="text-xs text-muted">jane@example.com</p>
|
||||
</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip :delay="0">
|
||||
<TooltipTrigger aria-label="状态标签">
|
||||
<Chip color="success">
|
||||
<CircleCheckFill aria-hidden="true" :width="12"></CircleCheckFill>
|
||||
<ChipLabel>活跃</ChipLabel>
|
||||
</Chip>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent class="flex items-center gap-1.5">
|
||||
<span class="relative flex size-2">
|
||||
<span
|
||||
class="absolute inline-flex h-full w-full animate-ping rounded-full bg-success opacity-75"
|
||||
></span>
|
||||
<span
|
||||
class="relative inline-flex size-2 rounded-full bg-success"
|
||||
></span>
|
||||
</span>
|
||||
<p>Jane 当前在线</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip :delay="0">
|
||||
<TooltipTrigger aria-label="信息图标">
|
||||
<div class="rounded-full bg-accent-soft p-2">
|
||||
<CircleQuestion
|
||||
aria-hidden="true"
|
||||
class="text-accent"
|
||||
></CircleQuestion>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent showArrow>
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<div class="max-w-xs px-1 py-1.5">
|
||||
<p class="mb-1 font-semibold">帮助信息</p>
|
||||
<p class="text-sm text-muted">
|
||||
这是包含有关此功能更详细信息的实用工具提示。
|
||||
</p>
|
||||
</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Tooltip,
|
||||
TooltipArrow,
|
||||
TooltipContent,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div></div>
|
||||
<Tooltip :delay="0">
|
||||
<Button class="w-full" variant="tertiary">Top</Button>
|
||||
<TooltipContent showArrow placement="top">
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<p>顶部位置</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<div></div>
|
||||
<Tooltip :delay="0">
|
||||
<Button class="w-full" variant="tertiary">Left</Button>
|
||||
<TooltipContent showArrow placement="left">
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<p>左侧位置</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<div class="flex items-center justify-center">
|
||||
<span class="text-sm text-muted">悬停按钮</span>
|
||||
</div>
|
||||
<Tooltip :delay="0">
|
||||
<Button class="w-full" variant="tertiary">Right</Button>
|
||||
<TooltipContent showArrow placement="right">
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<p>右侧位置</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<div></div>
|
||||
<Tooltip :delay="0">
|
||||
<Button class="w-full" variant="tertiary">Bottom</Button>
|
||||
<TooltipContent showArrow placement="bottom">
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<p>底部位置</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<div></div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { Button, Tooltip, TooltipContent } from "@heroui-vue/components";
|
||||
import { IconInfoCircle as CircleInfo } from "@tabler/icons-vue";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Tooltip :delay="0">
|
||||
<Button variant="secondary">悬停查看</Button>
|
||||
<TooltipContent as="div" data-custom="foo">
|
||||
<p>这是一个工具提示</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip :delay="0">
|
||||
<Button isIconOnly aria-label="更多信息" variant="tertiary">
|
||||
<CircleInfo aria-hidden="true"></CircleInfo>
|
||||
</Button>
|
||||
<TooltipContent as="div" data-custom="foo">
|
||||
<p>更多信息</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Tooltip,
|
||||
TooltipArrow,
|
||||
TooltipContent,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex items-center gap-4">
|
||||
<Tooltip :delay="0">
|
||||
<Button variant="secondary">带箭头</Button>
|
||||
<TooltipContent showArrow>
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<p>带箭头指示器的工具提示</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip :delay="0">
|
||||
<Button variant="primary">自定义偏移</Button>
|
||||
<TooltipContent showArrow :offset="12">
|
||||
<TooltipArrow></TooltipArrow>
|
||||
<p>与触发器的自定义偏移</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user