feat: migrate AlertDialog and Drawer with reviewed overlay lifecycles
This commit is contained in:
@@ -47,6 +47,7 @@ const groups = [
|
||||
items: [
|
||||
{ title: "Accordion 手风琴", url: "/components/accordion" },
|
||||
{ title: "Alert 警告", url: "/components/alert" },
|
||||
{ title: "AlertDialog 警告对话框", url: "/components/alert-dialog" },
|
||||
{ title: "Avatar 头像", url: "/components/avatar" },
|
||||
{ title: "AvatarGroup 头像组", url: "/components/avatar-group" },
|
||||
{ title: "Badge 徽章", url: "/components/badge" },
|
||||
@@ -67,6 +68,7 @@ const groups = [
|
||||
title: "DisclosureGroup 折叠面板组",
|
||||
url: "/components/disclosure-group",
|
||||
},
|
||||
{ title: "Drawer 抽屉", url: "/components/drawer" },
|
||||
{ title: "EmptyState 空状态", url: "/components/empty-state" },
|
||||
{ title: "FieldError 字段错误", url: "/components/field-error" },
|
||||
{ title: "Fieldset 字段组", url: "/components/fieldset" },
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
---
|
||||
title: AlertDialog 警告对话框
|
||||
description: 需要用户明确确认的警告对话框,默认禁止误关闭。
|
||||
component: alert-dialog
|
||||
group: 组件
|
||||
---
|
||||
|
||||
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、v-model、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import { AlertDialog } from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="alert-dialog-default" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="danger">删除项目</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog>
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger" />
|
||||
<AlertDialogHeading>要永久删除项目吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>此操作无法撤销。</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="danger">删除</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
```
|
||||
|
||||
`Dialog` 渲染 `role="alertdialog"`。**默认 `isDismissable=false`、`isKeyboardDismissDisabled=true`**(与 Modal 相反),二者可独立配置。
|
||||
|
||||
## 示例
|
||||
|
||||
### 状态类型
|
||||
|
||||
<ComponentPreview name="alert-dialog-statuses" />
|
||||
|
||||
### 弹出位置
|
||||
|
||||
<ComponentPreview name="alert-dialog-placements" />
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="alert-dialog-sizes" />
|
||||
|
||||
### 受控模式
|
||||
|
||||
<ComponentPreview name="alert-dialog-controlled" />
|
||||
|
||||
### 自定义图标
|
||||
|
||||
<ComponentPreview name="alert-dialog-custom-icon" />
|
||||
|
||||
### 自定义触发器
|
||||
|
||||
<ComponentPreview name="alert-dialog-custom-trigger" />
|
||||
|
||||
### 遮罩变体
|
||||
|
||||
<ComponentPreview name="alert-dialog-backdrop-variants" />
|
||||
|
||||
### 自定义遮罩
|
||||
|
||||
<ComponentPreview name="alert-dialog-custom-backdrop" />
|
||||
|
||||
### 关闭行为
|
||||
|
||||
<ComponentPreview name="alert-dialog-dismiss-behavior" />
|
||||
|
||||
### 关闭方式
|
||||
|
||||
<ComponentPreview name="alert-dialog-close-methods" />
|
||||
|
||||
### 自定义动画
|
||||
|
||||
<ComponentPreview name="alert-dialog-custom-animations" />
|
||||
|
||||
### 自定义 Portal
|
||||
|
||||
<ComponentPreview name="alert-dialog-custom-portal" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="alert-dialog-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令:
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-alert-dialog__backdrop {
|
||||
@apply bg-gradient-to-br from-black/60 to-black/80;
|
||||
}
|
||||
|
||||
.hv-alert-dialog__dialog {
|
||||
@apply rounded-2xl border border-red-500/20 shadow-2xl;
|
||||
}
|
||||
|
||||
.hv-alert-dialog__header {
|
||||
@apply gap-4;
|
||||
}
|
||||
|
||||
.hv-alert-dialog__icon {
|
||||
@apply size-16;
|
||||
}
|
||||
|
||||
.hv-alert-dialog__close-trigger {
|
||||
@apply rounded-full bg-white/10 hover:bg-white/20;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论。类名前缀 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-alert-dialog__trigger` - 打开警告对话框的触发元素
|
||||
- `.hv-alert-dialog__backdrop` - 遮罩层
|
||||
- `.hv-alert-dialog__container` - 支持 placement 的定位包裹层
|
||||
- `.hv-alert-dialog__dialog` - 对话框内容容器
|
||||
- `.hv-alert-dialog__header` - 图标与标题头部
|
||||
- `.hv-alert-dialog__heading` - 标题文本
|
||||
- `.hv-alert-dialog__body` - 主内容区域
|
||||
- `.hv-alert-dialog__footer` - 操作按钮区域
|
||||
- `.hv-alert-dialog__icon` - 状态色图标容器
|
||||
- `.hv-alert-dialog__close-trigger` - 关闭按钮
|
||||
|
||||
#### 遮罩变体
|
||||
|
||||
- `.hv-alert-dialog__backdrop--opaque` / `--blur` / `--transparent`
|
||||
|
||||
#### 状态变体(图标)[!toc]
|
||||
|
||||
- `.hv-alert-dialog__icon--default` / `--accent` / `--success` / `--warning` / `--danger`
|
||||
|
||||
### 交互状态
|
||||
|
||||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Active**:`:active` 或 `[data-pressed="true"]`
|
||||
- **Entering**:`[data-entering]`
|
||||
- **Exiting**:`[data-exiting]`
|
||||
- **Placement**:`[data-placement="*"]`(auto、top、center、bottom)
|
||||
|
||||
## API 参考
|
||||
|
||||
### AlertDialog / AlertDialogRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------------------------------------------- | -------------------------- | ------- | -------------------------------- |
|
||||
| `open` / `isOpen` | `boolean` | - | 受控打开 |
|
||||
| `defaultOpen` | `boolean` | `false` | 初始打开 |
|
||||
| `state` | `OverlayState` | - | useOverlayState 实例 |
|
||||
| `update:open` / `update:isOpen` / `openChange` | `(value: boolean) => void` | - | 状态事件 |
|
||||
| 默认插槽 | `{ isOpen, close }` | - | 内容;首个 Button 自动作为触发器 |
|
||||
|
||||
### AlertDialogTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ------- | ---------------- |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `asChild` | `boolean` | `false` | 合并到唯一子元素 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用触发 |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | - | - | 触发器内容 |
|
||||
|
||||
### AlertDialogBackdrop
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| --------------------------------- | ------------------------------------- | ----------- | --------------------------------------------- |
|
||||
| `variant` | `'opaque' \| 'blur' \| 'transparent'` | `'opaque'` | 遮罩样式 |
|
||||
| `isDismissable` | `boolean` | **`false`** | 点击遮罩是否关闭 |
|
||||
| `isKeyboardDismissDisabled` | `boolean` | **`true`** | 是否禁用 ESC |
|
||||
| `open` / `isOpen` / `defaultOpen` | | | 无父 AlertDialog 时自建状态 |
|
||||
| `state` | `OverlayState` | - | 受控状态 |
|
||||
| `to` | `string \| HTMLElement` | body | 传送门容器(替代 `UNSTABLE_portalContainer`) |
|
||||
| `update:open` / `openChange` | `(value: boolean) => void` | - | 状态事件 |
|
||||
| 默认插槽 | `{ isOpen, close }` | - | Container 等 |
|
||||
|
||||
### AlertDialogContainer
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ----------------------------------------- | -------- | --------- |
|
||||
| `placement` | `'auto' \| 'center' \| 'top' \| 'bottom'` | `'auto'` | 位置 |
|
||||
| `size` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'cover'` | `'md'` | 尺寸 |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | `{ close }` | - | Dialog 等 |
|
||||
|
||||
### AlertDialogDialog
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------------------------------- | --------------------------- | --------------- | ---------------- |
|
||||
| `role` | `string` | `'alertdialog'` | ARIA role |
|
||||
| `aria-label` / `aria-labelledby` / `aria-describedby` | `string` | 自动标题关联 | 无障碍名称与描述 |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `id` | `string` | 自动 | 内容 id |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | `{ close, isOpen }` | - | 面板内容 |
|
||||
|
||||
### AlertDialogHeader / Heading / Body / Footer
|
||||
|
||||
| 部件 | Prop | 描述 |
|
||||
| ------- | -------------------------------- | ------------------ |
|
||||
| Header | `class`、默认插槽 | 图标 + 标题容器 |
|
||||
| Heading | `as`(默认 `h2`)、`id`、`class` | 注册为 dialog 标题 |
|
||||
| Body | `class`、默认插槽 | 正文 |
|
||||
| Footer | `class`、默认插槽 | 操作区 |
|
||||
|
||||
### AlertDialogIcon
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | ------------------------------------------------------------- | ---------- | ------------------ |
|
||||
| `status` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'danger'` | 状态配色与默认图标 |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | - | 状态 SVG | 自定义图标 |
|
||||
|
||||
### AlertDialogCloseTrigger / AlertDialogClose
|
||||
|
||||
| 部件 | Prop | 描述 |
|
||||
| ------------ | -------------------------------- | ------------------------------------------- |
|
||||
| CloseTrigger | `variant`、`isDisabled`、`class` | X 按钮,点击关闭 |
|
||||
| Close | `as`、`asChild`、`isDisabled` | 包裹任意控件以关闭;替代上游 `slot="close"` |
|
||||
|
||||
### useOverlayState
|
||||
|
||||
```ts
|
||||
import { useOverlayState } from "@heroui-vue/components";
|
||||
|
||||
const state = useOverlayState({ defaultOpen: false });
|
||||
state.isOpen.value;
|
||||
state.open();
|
||||
state.close();
|
||||
state.toggle();
|
||||
state.setOpen(true);
|
||||
```
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React | Vue |
|
||||
| ----------------------------- | ------------------------------ |
|
||||
| 对象子部件 `AlertDialog.Icon` | 具名导出 |
|
||||
| `Button slot="close"` | `AlertDialogClose as-child` |
|
||||
| Dialog render props | 作用域插槽 `{ close, isOpen }` |
|
||||
| `UNSTABLE_portalContainer` | `to` |
|
||||
| `onPress` | `@click` |
|
||||
|
||||
## 无障碍
|
||||
|
||||
- `role="alertdialog"`,标题经 `aria-labelledby` 关联真实 Heading
|
||||
- 显式 `aria-labelledby` / `aria-label` 优先于自动计算
|
||||
- 默认禁止 ESC 与外部点击误关闭
|
||||
- 破坏性操作示例仅修改本地演示状态
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Modal 模态框](./modal)
|
||||
- [Button 按钮](./button)
|
||||
@@ -0,0 +1,268 @@
|
||||
---
|
||||
title: Drawer 抽屉
|
||||
description: 从屏幕边缘滑出的面板,支持四方向与拖动关闭。
|
||||
component: drawer
|
||||
group: 组件
|
||||
---
|
||||
|
||||
> 基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、v-model、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
|
||||
|
||||
## 用法
|
||||
|
||||
```ts
|
||||
import { Drawer } from "@heroui-vue/components";
|
||||
```
|
||||
|
||||
<ComponentPreview name="drawer-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
`Content` 负责边缘定位与滑入/滑出,`Dialog` 是可交互面板(拖动、焦点、ARIA)。二者职责分离。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
DrawerHandle,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button>打开</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="bottom">
|
||||
<DrawerDialog>
|
||||
<DrawerHandle />
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader><DrawerHeading>标题</DrawerHeading></DrawerHeader>
|
||||
<DrawerBody>内容</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child><Button>关闭</Button></DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
```
|
||||
|
||||
拖动从 **Handle / Header / Footer** 启动(Body 排除,避免与滚动冲突)。阈值:位移超过尺寸 **30%** 或速度超过 **0.5px/ms** 则关闭,否则回弹。`isDismissable=false` 时禁用拖动与外部点击。
|
||||
|
||||
## 示例
|
||||
|
||||
### 弹出位置
|
||||
|
||||
<ComponentPreview name="drawer-placements" />
|
||||
|
||||
### 不可关闭
|
||||
|
||||
<ComponentPreview name="drawer-non-dismissable" />
|
||||
|
||||
### 可滚动内容
|
||||
|
||||
<ComponentPreview name="drawer-scrollable-content" />
|
||||
|
||||
### 受控模式
|
||||
|
||||
<ComponentPreview name="drawer-controlled" />
|
||||
|
||||
### 搭配表单
|
||||
|
||||
<ComponentPreview name="drawer-with-form" />
|
||||
|
||||
### 导航抽屉
|
||||
|
||||
<ComponentPreview name="drawer-navigation" />
|
||||
|
||||
### 遮罩变体
|
||||
|
||||
<ComponentPreview name="drawer-backdrop-variants" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="drawer-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令:
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-drawer__backdrop {
|
||||
@apply bg-gradient-to-br from-black/50 to-black/70;
|
||||
}
|
||||
|
||||
.hv-drawer__dialog {
|
||||
@apply rounded-2xl border border-white/10 shadow-2xl;
|
||||
}
|
||||
|
||||
.hv-drawer__header {
|
||||
@apply text-center;
|
||||
}
|
||||
|
||||
.hv-drawer__close-trigger {
|
||||
@apply rounded-full bg-white/10 hover:bg-white/20;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论。类名前缀 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
#### 基础类
|
||||
|
||||
- `.hv-drawer__trigger` - 打开抽屉的触发元素
|
||||
- `.hv-drawer__backdrop` - 抽屉背后的遮罩层
|
||||
- `.hv-drawer__content` - 抽屉面板的定位包裹层
|
||||
- `.hv-drawer__dialog` - 抽屉面板本身
|
||||
- `.hv-drawer__header` - 标题区域
|
||||
- `.hv-drawer__heading` - 主标题文本
|
||||
- `.hv-drawer__body` - 主可滚动内容区域
|
||||
- `.hv-drawer__footer` - 操作按钮区域
|
||||
- `.hv-drawer__handle` - 视觉拖拽手柄指示器
|
||||
- `.hv-drawer__close-trigger` - 关闭按钮元素
|
||||
|
||||
#### 遮罩变体
|
||||
|
||||
- `.hv-drawer__backdrop--opaque` - 不透明彩色遮罩(默认)
|
||||
- `.hv-drawer__backdrop--blur` - 模糊遮罩
|
||||
- `.hv-drawer__backdrop--transparent` - 透明遮罩
|
||||
|
||||
#### 位置变体
|
||||
|
||||
- `.hv-drawer__content--bottom` - 从底部边缘滑入(默认)
|
||||
- `.hv-drawer__content--top` - 从顶部边缘滑入
|
||||
- `.hv-drawer__content--left` - 从左侧边缘滑入
|
||||
- `.hv-drawer__content--right` - 从右侧边缘滑入
|
||||
|
||||
#### 对话框变体
|
||||
|
||||
- `.hv-drawer__dialog--top` / `--bottom` / `--left` / `--right`
|
||||
|
||||
### 交互状态
|
||||
|
||||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Active**:`:active` 或 `[data-pressed="true"]`
|
||||
- **Entering**:`[data-entering]` - 打开动画期间
|
||||
- **Exiting**:`[data-exiting]` - 关闭动画期间(CSS 动画,供 Presence 延迟卸载)
|
||||
- **Placement**:`[data-placement="*"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Drawer / DrawerRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------- | -------------------------- | ------- | -------------------------------- |
|
||||
| `open` / `isOpen` | `boolean` | - | 受控打开 |
|
||||
| `defaultOpen` | `boolean` | `false` | 初始打开 |
|
||||
| `state` | `OverlayState` | - | useOverlayState 实例 |
|
||||
| `update:open` / `update:isOpen` | `(value: boolean) => void` | - | 打开状态变更 |
|
||||
| `openChange` | `(value: boolean) => void` | - | 打开状态变更 |
|
||||
| 默认插槽 | `{ isOpen, close }` | - | 内容;首个 Button 自动作为触发器 |
|
||||
|
||||
### DrawerTrigger
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ------- | ---------------- |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `asChild` | `boolean` | `false` | 合并到唯一子元素 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用触发 |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | - | - | 触发器内容 |
|
||||
|
||||
### DrawerBackdrop
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ---------------------------- | ------------------------------------- | ---------- | -------------------------- |
|
||||
| `variant` | `'opaque' \| 'blur' \| 'transparent'` | `'opaque'` | 遮罩样式 |
|
||||
| `isDismissable` | `boolean` | `true` | 点击遮罩 / 拖动关闭 |
|
||||
| `isKeyboardDismissDisabled` | `boolean` | `false` | 禁用 ESC |
|
||||
| `open` / `isOpen` | `boolean` | - | 受控打开(无父 Drawer 时) |
|
||||
| `defaultOpen` | `boolean` | `false` | 初始打开 |
|
||||
| `update:isOpen` | `(value: boolean) => void` | - | 状态事件 |
|
||||
| `state` | `OverlayState` | - | 受控状态 |
|
||||
| `to` | `string \| HTMLElement` | body | 传送门容器 |
|
||||
| `update:open` / `openChange` | `(value: boolean) => void` | - | 状态事件 |
|
||||
| 默认插槽 | `{ isOpen, close }` | - | Content 等 |
|
||||
|
||||
### DrawerContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ---------------------------------------- | ---------- | --------- |
|
||||
| `placement` | `'bottom' \| 'top' \| 'left' \| 'right'` | `'bottom'` | 滑入边缘 |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | `{ close }` | - | Dialog 等 |
|
||||
|
||||
### DrawerDialog
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------------------------------- | --------------------------- | ------------ | ----------------------- |
|
||||
| `role` | `string` | `'dialog'` | ARIA role(透传可覆盖) |
|
||||
| `aria-label` / `aria-labelledby` / `aria-describedby` | `string` | 自动标题关联 | 无障碍名称与描述 |
|
||||
| `as` | `string` | `'div'` | 渲染元素 |
|
||||
| `id` | `string` | 自动 | 内容 id |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | `{ close, isOpen }` | - | 面板内容 |
|
||||
|
||||
### DrawerHeader / DrawerHeading / DrawerBody / DrawerFooter
|
||||
|
||||
| 部件 | Prop | 默认值 | 描述 |
|
||||
| ------- | -------------------------------- | ------ | ----------------------------------- |
|
||||
| Header | `class`、默认插槽 | - | 标题区容器 |
|
||||
| Heading | `as`(默认 `h2`)、`id`、`class` | - | 注册为 dialog 标题 |
|
||||
| Body | `class`、默认插槽 | - | 可滚动正文(`touch-action: pan-y`) |
|
||||
| Footer | `class`、默认插槽 | - | 操作区 |
|
||||
|
||||
### DrawerHandle
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ---------- | ------------------------------------ |
|
||||
| `class` | `string \| Array \| Object` | - | CSS 类 |
|
||||
| 默认插槽 | - | 内置手柄条 | 自定义手柄视觉;省略时渲染默认手柄条 |
|
||||
|
||||
固定 `aria-hidden="true"`。
|
||||
|
||||
### DrawerCloseTrigger / DrawerClose
|
||||
|
||||
| 部件 | Prop | 描述 |
|
||||
| ------------ | -------------------------------- | ------------------------------------------- |
|
||||
| CloseTrigger | `variant`、`isDisabled`、`class` | 右上角 X,点击关闭 |
|
||||
| Close | `as`、`asChild`、`isDisabled` | 包裹任意控件以关闭;替代上游 `slot="close"` |
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React | Vue |
|
||||
| ------------------------ | ------------------------------ |
|
||||
| `Button slot="close"` | `DrawerClose as-child` |
|
||||
| Dialog render props | 作用域插槽 `{ close, isOpen }` |
|
||||
| `className` / `children` | `class` / 默认插槽 |
|
||||
| `onPress` | `@click` |
|
||||
| Content / Dialog 职责 | 保留分离 |
|
||||
|
||||
## 无障碍
|
||||
|
||||
- `role="dialog"`,标题经 `aria-labelledby` 关联真实 Heading
|
||||
- Handle `aria-hidden`
|
||||
- 拖动关闭与 ESC / 外部点击可独立配置
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Modal 模态框](./modal)
|
||||
- [AlertDialog 警告对话框](./alert-dialog)
|
||||
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const VARIANT_LABELS = {
|
||||
blur: "模糊",
|
||||
opaque: "不透明",
|
||||
transparent: "透明",
|
||||
} as const;
|
||||
const variants = ["opaque", "blur", "transparent"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="variant in variants" :key="variant">
|
||||
<Button variant="secondary">{{ VARIANT_LABELS[variant] }}</Button>
|
||||
<AlertDialogBackdrop :variant="variant">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>
|
||||
背景:{{ VARIANT_LABELS[variant] }}
|
||||
</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
{{
|
||||
variant === "opaque"
|
||||
? "不透明的深色背景会完全遮挡背后内容,让用户把注意力集中在对话框上。"
|
||||
: variant === "blur"
|
||||
? "模糊背景会柔和地虚化背后内容,同时保留一定的环境上下文。"
|
||||
: "透明背景会完整保留背后内容,适合重要性较低的确认场景。"
|
||||
}}
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,87 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex max-w-2xl flex-col gap-8">
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="text-lg font-semibold">使用 AlertDialogClose</h3>
|
||||
<p class="text-sm text-muted">
|
||||
在对话框内用
|
||||
<code>AlertDialogClose</code>
|
||||
包裹按钮,点击后会自动关闭对话框。
|
||||
</p>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">打开对话框</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>使用 AlertDialogClose</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>点击下方任一按钮都会自动关闭对话框。</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="text-lg font-semibold">使用作用域插槽 close</h3>
|
||||
<p class="text-sm text-muted">
|
||||
通过 Dialog 的作用域插槽获取
|
||||
<code>close</code>
|
||||
方法,从而完全控制关闭时机与方式,便于在关闭前加入校验等自定义逻辑。
|
||||
</p>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">打开对话框</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<template #default="{ close }">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="success" />
|
||||
<AlertDialogHeading>使用作用域插槽 close</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
下方按钮使用插槽提供的
|
||||
<code>close</code>
|
||||
方法。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<Button variant="tertiary" @click="close()">取消</Button>
|
||||
<Button @click="close()">确认</Button>
|
||||
</AlertDialogFooter>
|
||||
</template>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,149 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { useOverlayState } from "@heroui-vue/components";
|
||||
import {
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const isOpen = ref(false);
|
||||
const state = useOverlayState();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex max-w-md flex-col gap-8">
|
||||
<div class="flex flex-col gap-3">
|
||||
<h3 class="text-lg font-semibold text-foreground">配合 ref / v-model</h3>
|
||||
<p class="text-sm leading-relaxed text-pretty text-muted">
|
||||
使用 Vue 的
|
||||
<code class="text-foreground">ref</code>
|
||||
管理对话框开关,适合简单场景。
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
|
||||
>
|
||||
<div class="flex w-full items-center justify-between">
|
||||
<p class="text-xs text-muted">
|
||||
状态:
|
||||
<span class="font-mono font-medium text-foreground">
|
||||
{{ isOpen ? "打开" : "关闭" }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Button size="sm" variant="secondary" @click="isOpen = true">
|
||||
打开对话框
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="isOpen = !isOpen">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AlertDialogBackdrop v-model:is-open="isOpen">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>由 ref 控制</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
该警告对话框由 Vue 的
|
||||
<code>ref</code>
|
||||
控制。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<h3 class="text-lg font-semibold text-foreground">
|
||||
配合 useOverlayState()
|
||||
</h3>
|
||||
<p class="text-sm leading-relaxed text-pretty text-muted">
|
||||
使用
|
||||
<code class="text-foreground">useOverlayState</code>
|
||||
获得更简洁的 API,内置
|
||||
<code>open()</code>
|
||||
、
|
||||
<code>close()</code>
|
||||
、
|
||||
<code>toggle()</code>
|
||||
等方法。
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
|
||||
>
|
||||
<div class="flex w-full items-center justify-between">
|
||||
<p class="text-xs text-muted">
|
||||
状态:
|
||||
<span class="font-mono font-medium text-foreground">
|
||||
{{ state.isOpen.value ? "打开" : "关闭" }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Button size="sm" variant="secondary" @click="state.open()">
|
||||
打开对话框
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="state.toggle()">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AlertDialogBackdrop :state="state">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="success" />
|
||||
<AlertDialogHeading>由 useOverlayState() 控制</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
<code>useOverlayState</code>
|
||||
为常见操作提供专用方法,直接使用
|
||||
<code>state.open()</code>
|
||||
、
|
||||
<code>state.close()</code>
|
||||
或
|
||||
<code>state.toggle()</code>
|
||||
即可。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
<script setup lang="ts">
|
||||
import { IconArrowUp, IconSparkles } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const animations = [
|
||||
{
|
||||
name: "运动学缩放",
|
||||
icon: IconSparkles,
|
||||
description:
|
||||
"基于物理感的弹性缩放,模拟高阻尼弹簧:瞬态响应快、回落时间长,适合警告框与模态框。",
|
||||
backdropClass:
|
||||
"data-[entering]:duration-400 data-[entering]:ease-[cubic-bezier(0.16,1,0.3,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.7,0,0.84,0)]",
|
||||
containerClass:
|
||||
"data-[entering]:animate-in data-[entering]:fade-in-0 data-[entering]:zoom-in-95 data-[entering]:duration-400 data-[entering]:ease-[cubic-bezier(0.16,1,0.3,1)] data-[exiting]:animate-out data-[exiting]:fade-out-0 data-[exiting]:zoom-out-95 data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.7,0,0.84,0)]",
|
||||
},
|
||||
{
|
||||
name: "流体滑入",
|
||||
icon: IconArrowUp,
|
||||
description:
|
||||
"模拟在介质中运动并受流体阻力影响,避免机械式线性,更自然、更贴地。",
|
||||
backdropClass:
|
||||
"data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]",
|
||||
containerClass:
|
||||
"data-[entering]:animate-in data-[entering]:fade-in-0 data-[entering]:slide-in-from-bottom-4 data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:animate-out data-[exiting]:fade-out-0 data-[exiting]:slide-out-to-bottom-2 data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]",
|
||||
},
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="animation in animations" :key="animation.name">
|
||||
<Button variant="secondary">{{ animation.name }}</Button>
|
||||
<AlertDialogBackdrop :class="animation.backdropClass">
|
||||
<AlertDialogContainer :class="animation.containerClass">
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent">
|
||||
<component
|
||||
:is="animation.icon"
|
||||
class="size-5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>{{ animation.name }} 动画</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p class="mt-1">{{ animation.description }}</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">关闭</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>再试一次</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { IconAlertTriangle } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="danger">删除账户</Button>
|
||||
<AlertDialogBackdrop
|
||||
class="bg-linear-to-t from-red-950/90 via-red-950/50 to-transparent dark:from-red-950/95 dark:via-red-950/60"
|
||||
variant="blur"
|
||||
>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[420px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader class="items-center text-center">
|
||||
<AlertDialogIcon status="danger">
|
||||
<IconAlertTriangle class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>要永久删除账户吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
此操作无法撤销。你的数据、设置与内容将从服务器永久清除。醒目的红色背景用于强调该决定的严重性与不可逆性。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter class="flex-col-reverse">
|
||||
<AlertDialogClose as-child>
|
||||
<Button class="w-full">保留账户</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button class="w-full" variant="danger">永久删除</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { IconLockOpen } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">重置密码</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="warning">
|
||||
<IconLockOpen class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>要重置密码吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
我们会向你的邮箱发送重置链接。你需要设置新密码以恢复账户访问。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>发送重置链接</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,73 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const portalEl = ref<HTMLElement | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div>
|
||||
<p class="text-sm">
|
||||
将警告对话框渲染到自定义容器,而不是
|
||||
<code>document.body</code>
|
||||
</p>
|
||||
<p class="text-sm text-muted">
|
||||
为容器应用
|
||||
<code class="rounded px-1 py-0.5 text-xs">
|
||||
transform: translateZ(0)
|
||||
</code>
|
||||
可创建新的层叠上下文。
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
ref="portalEl"
|
||||
class="relative flex h-[380px] items-center justify-center overflow-hidden rounded bg-muted/20"
|
||||
style="transform: translate(0)"
|
||||
>
|
||||
<AlertDialog v-if="portalEl">
|
||||
<Button>打开警告对话框</Button>
|
||||
<AlertDialogBackdrop class="h-full" :to="portalEl">
|
||||
<AlertDialogContainer class="h-full max-h-full">
|
||||
<AlertDialogDialog class="h-full max-h-full sm:max-w-md">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>自定义传送门</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p class="text-sm text-muted">
|
||||
此段为示例占位文案,用于演示在自定义容器内渲染对话框时的滚动与排版效果。
|
||||
</p>
|
||||
<p class="text-sm text-muted">
|
||||
通过将浮层挂载到局部容器,可以配合裁剪、缩放或卡片布局,避免遮挡整个页面。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">退出登录</Button>
|
||||
<AlertDialogBackdrop
|
||||
class="bg-overlay/50 dark:bg-overlay/60"
|
||||
variant="blur"
|
||||
>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog
|
||||
class="relative overflow-hidden border border-border/80 bg-surface shadow-2xl ring-1 ring-accent/10 sm:max-w-[400px] dark:border-border/90 dark:bg-surface dark:ring-accent/15"
|
||||
>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-x-0 top-0 h-24 bg-linear-to-b from-accent/6 to-transparent dark:from-accent/10"
|
||||
/>
|
||||
<AlertDialogHeader class="relative">
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>确定要退出账户吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody class="relative">
|
||||
<p class="text-muted">
|
||||
您将在此设备上退出登录。除非已保存到云端,否则
|
||||
<strong class="text-foreground">Acme 工作区</strong>
|
||||
中未保存的工作可能会丢失。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">保持登录</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>退出登录</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,64 @@
|
||||
<script setup lang="ts">
|
||||
import { IconTrash } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
AlertDialogTrigger,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger
|
||||
class="group flex items-center gap-3 rounded-2xl bg-surface p-4 shadow-xs select-none hover:bg-surface-secondary"
|
||||
>
|
||||
<div
|
||||
class="flex size-12 shrink-0 items-center justify-center rounded-xl bg-danger-soft text-danger-soft-foreground"
|
||||
>
|
||||
<IconTrash class="size-6" aria-hidden="true" />
|
||||
</div>
|
||||
<div class="flex flex-1 flex-col gap-0.5">
|
||||
<p class="text-sm font-semibold">删除条目</p>
|
||||
<p class="text-xs text-muted">永久移除此条目</p>
|
||||
</div>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger">
|
||||
<IconTrash class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>要删除此条目吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
使用
|
||||
<code>AlertDialogTrigger</code>
|
||||
可在标准按钮之外自定义触发区域。此示例展示带图标与说明文字的卡片式触发器。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="danger">删除条目</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AlertDialog>
|
||||
<Button variant="danger">删除项目</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger" />
|
||||
<AlertDialogHeading>要永久删除项目吗?</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
此操作将永久删除
|
||||
<strong>我的精彩项目</strong>
|
||||
及其全部数据,且无法撤销。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="danger">删除项目</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,105 @@
|
||||
<script setup lang="ts">
|
||||
import { IconInfoCircle } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex max-w-sm flex-col gap-6">
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="text-lg font-semibold">isDismissable</h3>
|
||||
<p class="text-sm text-muted">
|
||||
控制是否允许通过点击遮罩关闭对话框。警告框通常需要明确操作,因此默认为
|
||||
<code>false</code>
|
||||
。对重要性较低的确认,可设为
|
||||
<code>true</code>
|
||||
。
|
||||
</p>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">打开警告对话框</Button>
|
||||
<AlertDialogBackdrop :is-dismissable="false">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="danger">
|
||||
<IconInfoCircle class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>isDismissable = false</AlertDialogHeading>
|
||||
<p class="text-sm leading-5 text-muted">
|
||||
点击遮罩不会关闭此对话框
|
||||
</p>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
尝试点击遮罩区域——对话框不会关闭,必须通过底部操作按钮关闭。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="text-lg font-semibold">isKeyboardDismissDisabled</h3>
|
||||
<p class="text-sm text-muted">
|
||||
控制是否允许通过 ESC 关闭。警告框通常需要明确操作,因此默认为
|
||||
<code>true</code>
|
||||
(禁用 ESC)。设为
|
||||
<code>false</code>
|
||||
时将允许 ESC 关闭。
|
||||
</p>
|
||||
<AlertDialog>
|
||||
<Button variant="secondary">打开警告对话框</Button>
|
||||
<AlertDialogBackdrop :is-keyboard-dismiss-disabled="true">
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent">
|
||||
<IconInfoCircle class="size-5" aria-hidden="true" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>
|
||||
isKeyboardDismissDisabled = true
|
||||
</AlertDialogHeading>
|
||||
<p class="text-sm leading-5 text-muted">已禁用 ESC 关闭</p>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>按下 ESC 不会有任何反应,必须通过操作按钮关闭此对话框。</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const PLACEMENT_LABELS = {
|
||||
auto: "自动",
|
||||
bottom: "底部",
|
||||
center: "居中",
|
||||
top: "顶部",
|
||||
} as const;
|
||||
const placements = ["auto", "top", "center", "bottom"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="placement in placements" :key="placement">
|
||||
<Button variant="secondary">{{ PLACEMENT_LABELS[placement] }}</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer :placement="placement">
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon status="accent" />
|
||||
<AlertDialogHeading>
|
||||
{{
|
||||
placement === "auto"
|
||||
? "自动定位"
|
||||
: `${PLACEMENT_LABELS[placement]}位置`
|
||||
}}
|
||||
</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>
|
||||
{{
|
||||
placement === "auto"
|
||||
? "在移动端默认靠近底部,在桌面端居中,以获得更合适的阅读与操作体验。"
|
||||
: `对话框将锚定在视口的「${PLACEMENT_LABELS[placement]}」区域。重要确认通常使用居中 placement 以吸引最多注意。`
|
||||
}}
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { IconRocket } from "@tabler/icons-vue";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const SIZE_LABELS = {
|
||||
cover: "通栏",
|
||||
lg: "大",
|
||||
md: "中",
|
||||
sm: "小",
|
||||
xs: "超小",
|
||||
} as const;
|
||||
const sizes = ["xs", "sm", "md", "lg", "cover"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="size in sizes" :key="size">
|
||||
<Button variant="secondary">{{ SIZE_LABELS[size] }}</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer :size="size">
|
||||
<AlertDialogDialog>
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon class="bg-default text-foreground">
|
||||
<IconRocket aria-hidden="true" class="size-5" />
|
||||
</AlertDialogIcon>
|
||||
<AlertDialogHeading>
|
||||
尺寸:{{ SIZE_LABELS[size] }}
|
||||
</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p v-if="size === 'cover'">
|
||||
此警告框使用
|
||||
<code>cover</code>
|
||||
尺寸:在移动端与桌面端保留边距铺满可视区域,仍保持圆角与标准内边距。
|
||||
</p>
|
||||
<p v-else>
|
||||
此警告框使用
|
||||
<code>{{ size }}</code>
|
||||
尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度。
|
||||
</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">取消</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button>确认</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogBackdrop,
|
||||
AlertDialogBody,
|
||||
AlertDialogClose,
|
||||
AlertDialogCloseTrigger,
|
||||
AlertDialogContainer,
|
||||
AlertDialogDialog,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogHeading,
|
||||
AlertDialogIcon,
|
||||
Button,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const examples = [
|
||||
{
|
||||
actions: { cancel: "保持登录", confirm: "退出登录" },
|
||||
body: "退出后需要重新登录才能访问账户,未保存的更改将丢失。",
|
||||
classNames: "bg-accent-soft text-accent-soft-foreground",
|
||||
header: "要退出当前账户吗?",
|
||||
status: "accent",
|
||||
trigger: "退出登录",
|
||||
},
|
||||
{
|
||||
actions: { cancel: "稍后再说", confirm: "标记完成" },
|
||||
body: "将把该任务标记为完成并通知所有成员,任务会移入已完成列表。",
|
||||
classNames: "bg-success-soft text-success-soft-foreground",
|
||||
header: "要完成此任务吗?",
|
||||
status: "success",
|
||||
trigger: "完成任务",
|
||||
},
|
||||
{
|
||||
actions: { cancel: "继续编辑", confirm: "放弃更改" },
|
||||
body: "你有未保存的更改,放弃后将永久丢失。确定要放弃吗?",
|
||||
classNames: "bg-warning-soft text-warning-soft-foreground",
|
||||
header: "要放弃未保存的更改吗?",
|
||||
status: "warning",
|
||||
trigger: "放弃更改",
|
||||
},
|
||||
{
|
||||
actions: { cancel: "取消", confirm: "删除账户" },
|
||||
body: "将永久删除你的账户并从服务器移除全部数据,此操作不可恢复。",
|
||||
classNames: "bg-danger-soft text-danger-soft-foreground",
|
||||
header: "要删除账户吗?",
|
||||
status: "danger",
|
||||
trigger: "删除账户",
|
||||
},
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<AlertDialog v-for="example in examples" :key="example.status">
|
||||
<Button :class="example.classNames">{{ example.trigger }}</Button>
|
||||
<AlertDialogBackdrop>
|
||||
<AlertDialogContainer>
|
||||
<AlertDialogDialog class="sm:max-w-[400px]">
|
||||
<AlertDialogCloseTrigger />
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogIcon :status="example.status" />
|
||||
<AlertDialogHeading>{{ example.header }}</AlertDialogHeading>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogBody>
|
||||
<p>{{ example.body }}</p>
|
||||
</AlertDialogBody>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose as-child>
|
||||
<Button variant="tertiary">{{ example.actions.cancel }}</Button>
|
||||
</AlertDialogClose>
|
||||
<AlertDialogClose as-child>
|
||||
<Button
|
||||
:variant="example.status === 'danger' ? 'danger' : 'primary'"
|
||||
>
|
||||
{{ example.actions.confirm }}
|
||||
</Button>
|
||||
</AlertDialogClose>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogDialog>
|
||||
</AlertDialogContainer>
|
||||
</AlertDialogBackdrop>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHandle,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const VARIANT_LABELS = {
|
||||
blur: "模糊",
|
||||
opaque: "不透明",
|
||||
transparent: "透明",
|
||||
} as const;
|
||||
const variants = ["opaque", "blur", "transparent"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<Drawer v-for="variant in variants" :key="variant">
|
||||
<Button variant="secondary">{{ VARIANT_LABELS[variant] }}</Button>
|
||||
<DrawerBackdrop :variant="variant">
|
||||
<DrawerContent>
|
||||
<DrawerDialog>
|
||||
<DrawerHandle />
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>背景:{{ VARIANT_LABELS[variant] }}</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
此抽屉使用
|
||||
<code>{{ variant }}</code>
|
||||
背景变体。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button class="w-full">关闭</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">打开抽屉</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>抽屉标题</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
这是一个从屏幕边缘滑入的抽屉,并通过流畅的 CSS
|
||||
过渡呈现动画效果。可拖动标题或页脚区域关闭。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>确认</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,128 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
useOverlayState,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const isOpen = ref(false);
|
||||
const state = useOverlayState();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex max-w-md flex-col gap-8">
|
||||
<div class="flex flex-col gap-3">
|
||||
<h3 class="text-lg font-semibold text-foreground">配合 ref</h3>
|
||||
<p class="text-sm leading-relaxed text-pretty text-muted">
|
||||
使用 Vue 的
|
||||
<code class="text-foreground">ref</code>
|
||||
管理抽屉开关。
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
|
||||
>
|
||||
<p class="text-xs text-muted">
|
||||
状态:
|
||||
<span class="font-mono font-medium text-foreground">
|
||||
{{ isOpen ? "打开" : "关闭" }}
|
||||
</span>
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<Button size="sm" variant="secondary" @click="isOpen = true">
|
||||
打开抽屉
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="isOpen = !isOpen">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<DrawerBackdrop v-model:is-open="isOpen">
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>由 ref 控制</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
该抽屉由 Vue 的
|
||||
<code>ref</code>
|
||||
控制。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">关闭</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<h3 class="text-lg font-semibold text-foreground">
|
||||
配合 useOverlayState()
|
||||
</h3>
|
||||
<p class="text-sm leading-relaxed text-pretty text-muted">
|
||||
使用
|
||||
<code class="text-foreground">useOverlayState</code>
|
||||
获得
|
||||
<code>open()</code>
|
||||
、
|
||||
<code>close()</code>
|
||||
、
|
||||
<code>toggle()</code>
|
||||
等方法。
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
|
||||
>
|
||||
<p class="text-xs text-muted">
|
||||
状态:
|
||||
<span class="font-mono font-medium text-foreground">
|
||||
{{ state.isOpen.value ? "打开" : "关闭" }}
|
||||
</span>
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<Button size="sm" variant="secondary" @click="state.open()">
|
||||
打开抽屉
|
||||
</Button>
|
||||
<Button size="sm" variant="tertiary" @click="state.toggle()">
|
||||
切换
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<DrawerBackdrop :state="state">
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>由 useOverlayState() 控制</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
<code>useOverlayState</code>
|
||||
为常见操作提供专用方法。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">关闭</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">打开筛选</Button>
|
||||
<DrawerBackdrop variant="blur">
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog class="border-l border-border/80 bg-surface">
|
||||
<DrawerHeader>
|
||||
<DrawerHeading class="text-foreground">筛选</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p class="text-sm text-muted">按状态、负责人或日期缩小结果范围。</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>应用</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
IconBell,
|
||||
IconHome,
|
||||
IconMail,
|
||||
IconMenu2,
|
||||
IconSearch,
|
||||
IconSettings,
|
||||
IconUser,
|
||||
} from "@tabler/icons-vue";
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const navItems = [
|
||||
{ icon: IconHome, label: "首页" },
|
||||
{ icon: IconSearch, label: "搜索" },
|
||||
{ icon: IconBell, label: "通知" },
|
||||
{ icon: IconMail, label: "消息" },
|
||||
{ icon: IconUser, label: "个人资料" },
|
||||
{ icon: IconSettings, label: "设置" },
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">
|
||||
<IconMenu2 aria-hidden="true" class="size-4" />
|
||||
菜单
|
||||
</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="left">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>导航</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<nav class="flex flex-col gap-1">
|
||||
<button
|
||||
v-for="item in navItems"
|
||||
:key="item.label"
|
||||
class="flex items-center gap-3 rounded-xl px-3 py-2.5 text-sm text-foreground transition-colors hover:bg-default"
|
||||
type="button"
|
||||
>
|
||||
<component
|
||||
:is="item.icon"
|
||||
class="size-5 text-muted"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</nav>
|
||||
</DrawerBody>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">重要操作</Button>
|
||||
<DrawerBackdrop :is-dismissable="false">
|
||||
<DrawerContent>
|
||||
<DrawerDialog>
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>确认操作</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
此抽屉无法通过点击外部或拖拽关闭。你必须使用下方按钮之一来完成操作。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>确认</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHandle,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const PLACEMENT_LABELS = {
|
||||
bottom: "底部",
|
||||
left: "左侧",
|
||||
right: "右侧",
|
||||
top: "顶部",
|
||||
} as const;
|
||||
const placements = ["bottom", "top", "left", "right"] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<Drawer v-for="placement in placements" :key="placement">
|
||||
<Button variant="secondary">{{ PLACEMENT_LABELS[placement] }}</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent :placement="placement">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHandle v-if="placement === 'bottom'" />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>
|
||||
{{ PLACEMENT_LABELS[placement] }}抽屉
|
||||
</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p>
|
||||
此抽屉从屏幕
|
||||
<strong>{{ PLACEMENT_LABELS[placement] }}</strong>
|
||||
边缘滑入。
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>完成</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
<DrawerHandle v-if="placement === 'top'" />
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHandle,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">条款与条件</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent>
|
||||
<DrawerDialog>
|
||||
<DrawerHandle />
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>条款与条件</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<p v-for="i in 20" :key="i" class="mb-3">
|
||||
段落 {{ i }}:Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
elit. Nullam pulvinar risus non risus hendrerit venenatis.
|
||||
Pellentesque sit amet hendrerit risus, sed porttitor quam.
|
||||
</p>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">拒绝</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>接受</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
Drawer,
|
||||
DrawerBackdrop,
|
||||
DrawerBody,
|
||||
DrawerClose,
|
||||
DrawerCloseTrigger,
|
||||
DrawerContent,
|
||||
DrawerDialog,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerHeading,
|
||||
Input,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer>
|
||||
<Button variant="secondary">编辑资料</Button>
|
||||
<DrawerBackdrop>
|
||||
<DrawerContent placement="right">
|
||||
<DrawerDialog>
|
||||
<DrawerCloseTrigger />
|
||||
<DrawerHeader>
|
||||
<DrawerHeading>编辑资料</DrawerHeading>
|
||||
</DrawerHeader>
|
||||
<DrawerBody>
|
||||
<form class="flex flex-col gap-4">
|
||||
<TextField class="w-full" name="name" type="text">
|
||||
<Label>姓名</Label>
|
||||
<Input placeholder="输入你的姓名" variant="secondary" />
|
||||
</TextField>
|
||||
<TextField class="w-full" name="email" type="email">
|
||||
<Label>邮箱</Label>
|
||||
<Input placeholder="输入你的邮箱" variant="secondary" />
|
||||
</TextField>
|
||||
<TextField class="w-full" name="bio">
|
||||
<Label>简介</Label>
|
||||
<Input placeholder="介绍一下你自己" variant="secondary" />
|
||||
</TextField>
|
||||
</form>
|
||||
</DrawerBody>
|
||||
<DrawerFooter>
|
||||
<DrawerClose as-child>
|
||||
<Button variant="secondary">取消</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose as-child>
|
||||
<Button>保存更改</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</DrawerDialog>
|
||||
</DrawerContent>
|
||||
</DrawerBackdrop>
|
||||
</Drawer>
|
||||
</template>
|
||||
Reference in New Issue
Block a user