feat: migrate Modal Popover and Tooltip with shared overlay foundation
This commit is contained in:
@@ -72,6 +72,8 @@ const groups = [
|
||||
{ title: "Label 标签", url: "/components/label" },
|
||||
{ title: "Link 链接", url: "/components/link" },
|
||||
{ title: "Meter 计量条", url: "/components/meter" },
|
||||
{ title: "Modal 模态框", url: "/components/modal" },
|
||||
{ title: "Popover 弹出框", url: "/components/popover" },
|
||||
{ title: "ProgressBar 进度条", url: "/components/progress-bar" },
|
||||
{
|
||||
title: "ProgressCircle 环形进度条",
|
||||
@@ -86,6 +88,7 @@ const groups = [
|
||||
{ title: "Switch 开关", url: "/components/switch" },
|
||||
{ title: "TextArea 多行文本框", url: "/components/textarea" },
|
||||
{ title: "TextField 文本输入框", url: "/components/text-field" },
|
||||
{ title: "Tooltip 工具提示", url: "/components/tooltip" },
|
||||
{ title: "Typography 排版", url: "/components/typography" },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@import "tailwindcss/theme.css" layer(theme);
|
||||
@import "../../../../packages/styles/themes/shared/theme.css";
|
||||
@import "../../../../packages/styles/animations.css";
|
||||
@import "tailwindcss/utilities.css" layer(utilities);
|
||||
@source "../../demos";
|
||||
|
||||
|
||||
@@ -41,3 +41,7 @@ description: 已迁移组件及文档
|
||||
- [Checkbox 复选框](./components/checkbox)
|
||||
- [CheckboxGroup 复选框组](./components/checkbox-group)
|
||||
- [RadioGroup 单选框组](./components/radio-group)
|
||||
|
||||
- [Modal 模态框](./components/modal)
|
||||
- [Popover 弹出框](./components/popover)
|
||||
- [Tooltip 工具提示](./components/tooltip)
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
---
|
||||
title: Modal 模态框
|
||||
description: 用于聚焦用户交互与重要内容的对话框遮罩层。
|
||||
component: modal
|
||||
group: 组件
|
||||
---
|
||||
|
||||
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、v-model、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import { Modal } from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="modal-default" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
Vue 使用具名组件导出。根组件也可将第一个 Button 作为触发器;明确组合时使用 ModalTrigger。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Modal,
|
||||
ModalTrigger,
|
||||
ModalBackdrop,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalCloseTrigger,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
ModalClose,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Modal>
|
||||
<ModalTrigger as-child><Button>Open Modal</Button></ModalTrigger>
|
||||
<ModalBackdrop>
|
||||
<ModalContainer>
|
||||
<ModalDialog>
|
||||
<ModalCloseTrigger />
|
||||
<ModalHeader><ModalHeading>标题</ModalHeading></ModalHeader>
|
||||
<ModalBody>内容</ModalBody>
|
||||
<ModalFooter>
|
||||
<ModalClose as-child><Button>关闭</Button></ModalClose>
|
||||
</ModalFooter>
|
||||
</ModalDialog>
|
||||
</ModalContainer>
|
||||
</ModalBackdrop>
|
||||
</Modal>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="modal-sizes" />
|
||||
|
||||
### 位置
|
||||
|
||||
<ComponentPreview name="modal-placements" />
|
||||
|
||||
### 滚动行为
|
||||
|
||||
<ComponentPreview name="modal-scroll-comparison" />
|
||||
|
||||
### 受控状态
|
||||
|
||||
<ComponentPreview name="modal-controlled" />
|
||||
|
||||
### 搭配表单
|
||||
|
||||
<ComponentPreview name="modal-with-form" />
|
||||
|
||||
### 自定义触发器
|
||||
|
||||
<ComponentPreview name="modal-custom-trigger" />
|
||||
|
||||
### 遮罩变体
|
||||
|
||||
<ComponentPreview name="modal-backdrop-variants" />
|
||||
|
||||
### 自定义遮罩
|
||||
|
||||
<ComponentPreview name="modal-custom-backdrop" />
|
||||
|
||||
### 关闭行为
|
||||
|
||||
<ComponentPreview name="modal-dismiss-behavior" />
|
||||
|
||||
### 关闭方式
|
||||
|
||||
<ComponentPreview name="modal-close-methods" />
|
||||
|
||||
### 自定义动画
|
||||
|
||||
<ComponentPreview name="modal-custom-animations" />
|
||||
|
||||
### 自定义 Portal
|
||||
|
||||
<ComponentPreview name="modal-custom-portal" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="modal-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-modal__backdrop {
|
||||
@apply bg-gradient-to-br from-black/50 to-black/70;
|
||||
}
|
||||
|
||||
.hv-modal__dialog {
|
||||
@apply rounded-2xl border border-white/10 shadow-2xl;
|
||||
}
|
||||
|
||||
.hv-modal__header {
|
||||
@apply text-center;
|
||||
}
|
||||
|
||||
.hv-modal__close-trigger {
|
||||
@apply rounded-full bg-white/10 hover:bg-white/20;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Modal 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/modal.css)):
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-modal__trigger` — 打开 Modal 的触发元素
|
||||
- `.hv-modal__backdrop` — Modal 背后的遮罩层
|
||||
- `.hv-modal__container` — 支持 placement 的定位包裹层
|
||||
- `.hv-modal__dialog` — Modal 内容容器
|
||||
- `.hv-modal__header` — 标题与图标区域
|
||||
- `.hv-modal__body` — 主内容区域
|
||||
- `.hv-modal__footer` — 操作区域
|
||||
- `.hv-modal__close-trigger` — 关闭按钮元素
|
||||
|
||||
#### 遮罩变体
|
||||
|
||||
- `.hv-modal__backdrop--opaque` — 不透明有色遮罩(默认)
|
||||
- `.hv-modal__backdrop--blur` — 带玻璃效果的模糊遮罩
|
||||
- `.hv-modal__backdrop--transparent` — 透明遮罩(无叠加层)
|
||||
|
||||
#### 滚动变体
|
||||
|
||||
- `.hv-modal__container--scroll-outside` — 允许整个 Modal 滚动
|
||||
- `.hv-modal__dialog--scroll-inside` — 限制 Modal 高度,由 body 区域滚动
|
||||
- `.hv-modal__body--scroll-inside` — 仅 body 区域可滚动
|
||||
- `.hv-modal__body--scroll-outside` — 允许整页滚动
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件支持以下交互状态:
|
||||
|
||||
- **焦点**:`:focus-visible` 或 `[data-focus-visible="true"]` — 应用于触发器、对话框与关闭按钮
|
||||
- **悬停**:`:hover` 或 `[data-hovered="true"]` — 应用于关闭按钮悬停
|
||||
- **按下**:`:active` 或 `[data-pressed="true"]` — 应用于关闭按钮按下
|
||||
- **进入**:`[data-entering]` — Modal 打开动画期间
|
||||
- **离开**:`[data-exiting]` — Modal 关闭动画期间
|
||||
- **位置**:`[data-placement="*"]` — 基于 Modal 位置(auto、top、center、bottom)
|
||||
|
||||
## API 参考
|
||||
|
||||
### Modal
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | -------------- | ------ | ---------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 触发器与容器元素 |
|
||||
|
||||
### ModalTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | -------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 自定义触发内容 |
|
||||
| `class` | `string / object / array` | - | CSS 类 |
|
||||
|
||||
### ModalBackdrop
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------------------------- | ------------------------------------- | ---------- | -------------------- |
|
||||
| `variant` | `"opaque" \| "blur" \| "transparent"` | `"opaque"` | 遮罩叠加样式 |
|
||||
| `isDismissable` | `boolean` | `true` | 点击遮罩是否关闭 |
|
||||
| `isKeyboardDismissDisabled` | `boolean` | `false` | 是否禁用 ESC 关闭 |
|
||||
| `isOpen` | `boolean` | - | 受控打开状态 |
|
||||
| `@open-change` | `(isOpen: boolean) => void` | - | 打开状态变化处理函数 |
|
||||
| `class` | `string / object / array` | - | 遮罩 CSS 类 |
|
||||
| `to` | `HTMLElement` | - | 自定义 portal 容器 |
|
||||
|
||||
### ModalContainer
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | --------------------------------------------------- | ---------- | -------------------- |
|
||||
| `placement` | `"auto" \| "center" \| "top" \| "bottom"` | `"auto"` | Modal 在屏幕上的位置 |
|
||||
| `scroll` | `"inside" \| "outside"` | `"inside"` | 滚动行为 |
|
||||
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "cover" \| "full"` | `"md"` | Modal 尺寸变体 |
|
||||
| `class` | `string / object / array` | - | 容器 CSS 类 |
|
||||
|
||||
### ModalDialog
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------ | ------------------------- | ---------- | -------------- |
|
||||
| `默认插槽` | `作用域插槽 { close }` | - | 内容或渲染函数 |
|
||||
| `class` | `string / object / array` | - | CSS 类 |
|
||||
| `role` | `string` | `"dialog"` | ARIA role |
|
||||
| `aria-label` | `string` | - | 无障碍标签 |
|
||||
| `aria-labelledby` | `string` | - | 标签元素的 id |
|
||||
| `aria-describedby` | `string` | - | 描述元素的 id |
|
||||
|
||||
### ModalHeader
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | -------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 头部内容 |
|
||||
| `class` | `string / object / array` | - | CSS 类 |
|
||||
|
||||
### ModalBody
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | -------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 正文内容 |
|
||||
| `class` | `string / object / array` | - | CSS 类 |
|
||||
|
||||
### ModalFooter
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | -------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 底部内容 |
|
||||
| `class` | `string / object / array` | - | CSS 类 |
|
||||
|
||||
### ModalCloseTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | -------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 自定义关闭按钮 |
|
||||
| `class` | `string / object / array` | - | CSS 类 |
|
||||
|
||||
### useOverlayState Hook
|
||||
|
||||
```ts
|
||||
import { useOverlayState } from "@heroui-vue/components";
|
||||
|
||||
const state = useOverlayState({
|
||||
defaultOpen: false,
|
||||
onOpenChange: console.log,
|
||||
});
|
||||
state.isOpen.value; // 当前状态(模板中的顶层 ref 自动解包)
|
||||
state.open();
|
||||
state.close();
|
||||
state.toggle();
|
||||
state.setOpen(true);
|
||||
```
|
||||
|
||||
## 无障碍
|
||||
|
||||
实现 [WAI-ARIA Dialog 模式](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/):
|
||||
|
||||
- **焦点陷阱**:焦点锁定在 Modal 内
|
||||
- **键盘**:`ESC` 关闭(启用时)、`Tab` 在元素间循环
|
||||
- **屏幕阅读器**:正确的 ARIA 属性
|
||||
- **滚动锁定**:打开时禁用 body 滚动
|
||||
|
||||
## Vue API 与组合约定
|
||||
|
||||
Root 的 `open` / `isOpen` 支持受控值,`defaultOpen` 默认 false;推荐 `v-model:open`,事件为 `update:open`、`openChange`(模板 `@open-change`)。父级拒绝请求时保持父级状态,初始值只初始化一次。第一个 Button 可自动作为触发器;自定义内容用显式 Trigger,单元素组合可设 `as-child`。Trigger 的 class/style、ARIA 与 DOM 监听落在实际触发元素,disabled、isDisabled 与加载状态会阻止激活。
|
||||
|
||||
React 的 DOM render 回调改为 `as` 加原生 attrs,例如 `as="div" data-custom="foo"`;class 函数改为 Vue 的字符串/对象/数组绑定。Enter/Space 对自定义按钮根只激活一次,调用者 preventDefault 可取消。Portal 默认 body,可由 ConfigProvider.teleportTo 或 Content/Backdrop 的 to 覆盖;目标应置于所需主题作用域中。SSR Portal 于客户端挂载后插入,尚未承诺 Nuxt 服务端收集。
|
||||
|
||||
### 状态与关闭
|
||||
|
||||
Modal 还接受 `state: OverlayState`,其优先级高于 open / isOpen;复用 `useOverlayState()`。ModalBackdrop 可脱离 Modal 单独使用 `v-model:open`,满足外部按钮控制场景。根已存在时由根统一管理状态。ModalContainer 的 size / placement / scroll 与基线相同,Body 继承滚动模式。
|
||||
|
||||
React 的 `slot="close"` 改为 `<ModalClose as-child><Button>关闭</Button></ModalClose>`;也可通过 ModalDialog 的 `v-slot="{ close }"` 自行关闭。ModalCloseTrigger 默认复用 CloseButton 的图标、可访问名称与变体。Header/Body/Footer/Icon/Heading 支持 as 与原生 attrs。
|
||||
|
||||
ModalDialog 的 ARIA/DOM 事件落在实际 role=dialog 的节点。isDismissable 与 isKeyboardDismissDisabled 位于 Backdrop,分别控制外部交互与 Escape;显式关闭不受它们影响。openAutoFocus、closeAutoFocus、escapeKeyDown、pointerDownOutside、focusOutside、interactOutside 以可取消事件透传。
|
||||
|
||||
### Vue 补充部件
|
||||
|
||||
| 部件 | 属性 / 插槽 | 默认值 | 说明 |
|
||||
| ----------------- | -------------------------------------------- | ----------------------------------------- | --------------------------------------------------------------------------- |
|
||||
| ModalHeading | as / id / class | h2 / 自动唯一 ID | 真实标题关联,显式 ID 可动态更新 |
|
||||
| ModalIcon | as / class / 默认插槽 | div | 复用基线 40px 图标容器 |
|
||||
| ModalClose | as / asChild / isDisabled | button / false / false | 显式替代 React close slot;保留取消与禁用 |
|
||||
| ModalCloseTrigger | variant / isDisabled / disabled / aria-label | default / false / false / Close | 复用 CloseButton 的同名契约,默认插槽可自定义图标 |
|
||||
| Modal | open / isOpen / defaultOpen / state | undefined / undefined / false / undefined | state 优先,推荐 v-model:open;update:open 和 openChange 的参数均为 boolean |
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
|
||||
@@ -0,0 +1,179 @@
|
||||
---
|
||||
title: Popover 弹出框
|
||||
description: 在由按钮或任意自定义元素触发后,于 portal 中展示丰富内容。
|
||||
component: popover
|
||||
group: 组件
|
||||
---
|
||||
|
||||
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、v-model、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import { Popover } from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="popover-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Popover,
|
||||
PopoverTrigger,
|
||||
PopoverContent,
|
||||
PopoverArrow,
|
||||
PopoverDialog,
|
||||
PopoverHeading,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Popover>
|
||||
<PopoverTrigger as-child><Button>点击我</Button></PopoverTrigger>
|
||||
<PopoverContent>
|
||||
<PopoverArrow />
|
||||
<PopoverDialog>
|
||||
<PopoverHeading>标题</PopoverHeading>
|
||||
内容
|
||||
</PopoverDialog>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 带箭头
|
||||
|
||||
<ComponentPreview name="popover-with-arrow" />
|
||||
|
||||
### 可交互内容
|
||||
|
||||
<ComponentPreview name="popover-interactive" />
|
||||
|
||||
### 位置
|
||||
|
||||
<ComponentPreview name="popover-placement" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
<ComponentPreview name="popover-render-function" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="popover-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-popover {
|
||||
@apply rounded-xl shadow-2xl;
|
||||
}
|
||||
|
||||
.hv-popover__dialog {
|
||||
@apply p-4;
|
||||
}
|
||||
|
||||
.hv-popover__heading {
|
||||
@apply text-lg font-bold;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Popover 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/popover.css)):
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-popover` - Popover 根容器样式
|
||||
- `.hv-popover__dialog` - 对话框内容包裹层
|
||||
- `.hv-popover__heading` - 标题文本样式
|
||||
- `.hv-popover__trigger` - 触发元素样式
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件支持以下动画相关状态:
|
||||
|
||||
- **进入**:`[data-entering]` — Popover 出现过程中应用
|
||||
- **离开**:`[data-exiting]` — Popover 消失过程中应用
|
||||
- **位置**:`[data-side="*"]` — 根据 Popover 位置应用
|
||||
- **焦点**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Popover
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------------- | --------------------------- | ------- | ----------------------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 触发器与内容元素 |
|
||||
| `isOpen` | `boolean` | - | 控制 Popover 是否可见(受控) |
|
||||
| `defaultOpen` | `boolean` | `false` | 初始打开状态(非受控) |
|
||||
| `@open-change` | `(isOpen: boolean) => void` | - | 打开状态变化时调用 |
|
||||
|
||||
### PopoverContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | ------------------------------------------------- | ---------- | ------------------------------------------ |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 在 Popover 中展示的内容 |
|
||||
| `placement` | `"top" \| "bottom" \| "left" \| "right"` (及变体) | `"bottom"` | Popover 的位置 |
|
||||
| `offset` | `number` | `8` | 与触发元素的距离 |
|
||||
| `shouldFlip` | `boolean` | `true` | 是否允许 Popover 改变方向以适配空间 |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
| `as` | `string` | `"div"` | Vue 自定义根元素;自定义箭头使用默认插槽。 |
|
||||
|
||||
### PopoverDialog
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | --------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 对话框内容 |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
|
||||
### PopoverTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | ------------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 触发 Popover 的元素 |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
|
||||
### PopoverArrow
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | -------- | -------------------------------- |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
| `默认插槽` | `单个 SVG VNode` | 基线箭头 | 自定义箭头,保留对应 data-slot。 |
|
||||
|
||||
## Vue API 与组合约定
|
||||
|
||||
Root 的 `open` / `isOpen` 支持受控值,`defaultOpen` 默认 false;推荐 `v-model:open`,事件为 `update:open`、`openChange`(模板 `@open-change`)。父级拒绝请求时保持父级状态,初始值只初始化一次。第一个 Button 可自动作为触发器;自定义内容用显式 Trigger,单元素组合可设 `as-child`。Trigger 的 class/style、ARIA 与 DOM 监听落在实际触发元素,disabled、isDisabled 与加载状态会阻止激活。
|
||||
|
||||
React 的 DOM render 回调改为 `as` 加原生 attrs,例如 `as="div" data-custom="foo"`;class 函数改为 Vue 的字符串/对象/数组绑定。Enter/Space 对自定义按钮根只激活一次,调用者 preventDefault 可取消。Portal 默认 body,可由 ConfigProvider.teleportTo 或 Content/Backdrop 的 to 覆盖;目标应置于所需主题作用域中。SSR Portal 于客户端挂载后插入,尚未承诺 Nuxt 服务端收集。
|
||||
|
||||
### 定位与生命周期
|
||||
|
||||
placement 支持 top/bottom/left/right 及对齐变体(如 `top start`、`right bottom`),offset 可为 0,crossOffset 默认 0,shouldFlip 默认 true,containerPadding 默认 12。实际碰撞结果以 `data-side`、`data-align` 表示;箭头由 Reka 定位旋转,不重复应用上游 SVG 旋转。保留源进入/退出动画数值及 data-entering/data-exiting,退出由 Presence 协调卸载。
|
||||
|
||||
PopoverContent 的 isNonModal 默认 false,也可在 Popover Root 设置默认值;交互丰富的内容使用 PopoverDialog,Heading 关联实际对话框名称,不生成两个嵌套 role=dialog。Content 的 isDismissable 默认 true、isKeyboardDismissDisabled 默认 false;进入焦点、外部交互和 Escape 事件可取消。默认模态模式下 closeAutoFocus 继承 Reka 的触发器恢复流程,当前用于通知;自定义取消恢复可用 isNonModal 模式,二者的焦点策略差异见迁移记录。PopoverDialog 的作用域插槽暴露 close。
|
||||
|
||||
### PopoverHeading 与内容语义
|
||||
|
||||
| 部件 | 属性 / 插槽 | 默认值 | 说明 |
|
||||
| -------------- | ------------------------------------- | ---------------- | ------------------------------------------------------------------- |
|
||||
| PopoverHeading | as / id / class / 默认插槽 | h2 / 自动唯一 ID | 动态维护对话框标题引用 |
|
||||
| PopoverDialog | as / class / 默认作用域插槽 { close } | div | 视觉内容层;ARIA 名称/描述透传到实际对话框表面,避免两个嵌套 dialog |
|
||||
| PopoverContent | isNonModal | false | 非模态时不锁定外部交互,不限制焦点范围 |
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
|
||||
@@ -0,0 +1,181 @@
|
||||
---
|
||||
title: Tooltip 工具提示
|
||||
description: 当用户悬停或聚焦某个元素时,展示提示性文本。
|
||||
component: tooltip
|
||||
group: 组件
|
||||
---
|
||||
|
||||
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、v-model、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import { Tooltip } from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="tooltip-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipTrigger,
|
||||
TooltipContent,
|
||||
TooltipArrow,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child><Button>Hover for tooltip</Button></TooltipTrigger>
|
||||
<TooltipContent show-arrow>
|
||||
<TooltipArrow />
|
||||
关于此元素的有用信息
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 位置
|
||||
|
||||
<ComponentPreview name="tooltip-placement" />
|
||||
|
||||
### 带箭头
|
||||
|
||||
<ComponentPreview name="tooltip-with-arrow" />
|
||||
|
||||
### 自定义触发
|
||||
|
||||
<ComponentPreview name="tooltip-custom-trigger" />
|
||||
|
||||
### 渲染函数
|
||||
|
||||
<ComponentPreview name="tooltip-render-function" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="tooltip-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-tooltip {
|
||||
@apply rounded-xl shadow-lg;
|
||||
}
|
||||
|
||||
.hv-tooltip__trigger {
|
||||
@apply cursor-help;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||||
|
||||
### 全局延迟配置
|
||||
|
||||
你可以通过定义 CSS 变量,为应用中所有 Tooltip 设置默认的显示与隐藏延迟:
|
||||
|
||||
```css
|
||||
/* 在你的全局 CSS 文件中 */
|
||||
:root {
|
||||
--tooltip-delay: 1500ms;
|
||||
--tooltip-close-delay: 500ms;
|
||||
}
|
||||
|
||||
/* 也可以为浅色/深色主题设置不同的值 */
|
||||
.light,
|
||||
[data-theme="light"] {
|
||||
--tooltip-delay: 1200ms;
|
||||
}
|
||||
|
||||
.dark,
|
||||
[data-theme="dark"] {
|
||||
--tooltip-close-delay: 300ms;
|
||||
}
|
||||
```
|
||||
|
||||
值支持 `ms`、`s` 等 CSS 时间单位。在单个 Tooltip 上指定 `delay` 或 `closeDelay` 时,会覆盖这些全局设置。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Tooltip 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/tooltip.css)):
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-tooltip` - 带动画的基础 Tooltip 样式
|
||||
- `.hv-tooltip__trigger` - 触发元素样式
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件支持以下动画相关状态:
|
||||
|
||||
- **进入**:`[data-entering]` — Tooltip 出现过程中应用
|
||||
- **离开**:`[data-exiting]` — Tooltip 消失过程中应用
|
||||
- **位置**:`[data-side="*"]` — 根据 Tooltip 位置应用
|
||||
|
||||
## API 参考
|
||||
|
||||
### Tooltip
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------------------- | -------------------- | ------------------ | ------------------------------------------------------------------------------ |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 触发元素与内容 |
|
||||
| `delay` | `number` | `1500` 或 CSS 变量 | 显示 Tooltip 前的延迟(毫秒);可通过 `--tooltip-delay` CSS 变量全局配置 |
|
||||
| `closeDelay` | `number` | `500` 或 CSS 变量 | 隐藏 Tooltip 前的延迟(毫秒);可通过 `--tooltip-close-delay` CSS 变量全局配置 |
|
||||
| `trigger` | `"hover" \| "focus"` | `"hover"` | Tooltip 的触发方式 |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用 Tooltip |
|
||||
| `shouldSkipAnimation` | `boolean` | `false` | 在多个 Tooltip 之间快速切换时,是否跳过进入与退出动画 |
|
||||
|
||||
### TooltipContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ------------------------------------------------- | ------------------- | ------------------------------------------ |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 在 Tooltip 中展示的内容 |
|
||||
| `showArrow` | `boolean` | `false` | 是否显示箭头指示器 |
|
||||
| `offset` | `number` | `3`(带箭头时为 7) | 与触发元素的距离 |
|
||||
| `placement` | `"top" \| "bottom" \| "left" \| "right"` (及变体) | `"top"` | Tooltip 的位置 |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
| `as` | `string` | `"div"` | Vue 自定义根元素;自定义箭头使用默认插槽。 |
|
||||
|
||||
### TooltipTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | ------ | ------------------- |
|
||||
| `默认插槽` | `VNode / 插槽` | - | 触发 Tooltip 的元素 |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
|
||||
### TooltipArrow
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------- | ------------------------- | -------- | -------------------------------- |
|
||||
| `class` | `string / object / array` | - | 额外的 CSS 类名 |
|
||||
| `默认插槽` | `单个 SVG VNode` | 基线箭头 | 自定义箭头,保留对应 data-slot。 |
|
||||
|
||||
## Vue API 与组合约定
|
||||
|
||||
Root 的 `open` / `isOpen` 支持受控值,`defaultOpen` 默认 false;推荐 `v-model:open`,事件为 `update:open`、`openChange`(模板 `@open-change`)。父级拒绝请求时保持父级状态,初始值只初始化一次。第一个 Button 可自动作为触发器;自定义内容用显式 Trigger,单元素组合可设 `as-child`。Trigger 的 class/style、ARIA 与 DOM 监听落在实际触发元素;使用 Tooltip 的 isDisabled 禁用提示。
|
||||
|
||||
React 的 DOM render 回调改为 `as` 加原生 attrs,例如 `as="div" data-custom="foo"`;class 函数改为 Vue 的字符串/对象/数组绑定。Enter/Space 对自定义按钮根只激活一次,调用者 preventDefault 可取消。Portal 默认 body,可由 ConfigProvider.teleportTo 或 Content/Backdrop 的 to 覆盖;目标应置于所需主题作用域中。SSR Portal 于客户端挂载后插入,尚未承诺 Nuxt 服务端收集。
|
||||
|
||||
### 定位与生命周期
|
||||
|
||||
placement 支持 top/bottom/left/right 及对齐变体(如 `top start`、`right bottom`),offset 可为 0,crossOffset 默认 0,shouldFlip 默认 true,containerPadding 默认 12。实际碰撞结果以 `data-side`、`data-align` 表示;箭头由 Reka 定位旋转,不重复应用上游 SVG 旋转。保留源进入/退出动画数值及 data-entering/data-exiting,退出由 Presence 协调卸载。
|
||||
|
||||
Tooltip 的 isDisabled 默认 false;trigger="hover" 同时支持键盘焦点,trigger="focus" 只在聚焦时打开。delay / closeDelay 显式值优先于触发器作用域的 CSS 时间变量(支持 ms/s),缺省 1500/500ms;失焦、点击、Escape 与外部交互立即关闭,悬停离开遵循 closeDelay。ConfigProvider 提供共享的 Reka warmup 边界;未使用 Provider 时各 Root 拥有自己的 warmup 计时。shouldSkipAnimation 默认 false,为 true 时允许 Reka instant-open 阶段跳过动画,此处与 React Aria 的全局 warmup 调度不同。
|
||||
|
||||
showArrow 选择带箭头的默认偏移(7px,否则 3px),仍需显式放置 TooltipArrow,与基线源码相同。Tooltip 通过 aria-describedby 关联隐藏的只读提示文本;可视容器保持 Reka 的语义,不能在其中放需要焦点的按钮/输入,应改用 Popover。TooltipTrigger 支持 as/asChild 和原生 attrs;普通按钮会自动组合。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
|
||||
@@ -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