145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
268 lines
11 KiB
Markdown
268 lines
11 KiB
Markdown
---
|
||
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) · [Button 按钮](./button) · [CloseButton 关闭按钮](./close-button)
|