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
110 lines
3.2 KiB
Markdown
110 lines
3.2 KiB
Markdown
---
|
||
title: CloseButton 关闭按钮
|
||
description: 用于关闭对话框、模态框或 dismiss 内容的按钮组件
|
||
component: close-button
|
||
group: 组件
|
||
---
|
||
|
||
## 用法
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { CloseButton } from "@heroui-vue/components";
|
||
</script>
|
||
```
|
||
|
||
<ComponentPreview name="close-button-default" />
|
||
|
||
## 示例
|
||
|
||
### 交互
|
||
|
||
<ComponentPreview name="close-button-interactive" />
|
||
|
||
### 自定义图标
|
||
|
||
<ComponentPreview name="close-button-with-custom-icon" />
|
||
|
||
## 自定义样式
|
||
|
||
### Tailwind CSS
|
||
|
||
<ComponentPreview name="close-button-custom-styles" />
|
||
|
||
### 全局 CSS
|
||
|
||
可使用 `@layer components` 指令自定义 CloseButton 组件类。
|
||
|
||
```css
|
||
@layer components {
|
||
.hv-close-button {
|
||
@apply bg-red-100 text-red-800 hover:bg-red-200;
|
||
}
|
||
|
||
.hv-close-button--custom {
|
||
@apply rounded-full border-2 border-red-300;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 样式参考
|
||
|
||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。
|
||
|
||
### CSS 类
|
||
|
||
CloseButton 组件使用以下 CSS 类:
|
||
|
||
#### 基础类 [!toc]
|
||
|
||
- `.hv-close-button` - 基础组件样式
|
||
|
||
#### 变体类 [!toc]
|
||
|
||
- `.hv-close-button--default` - 默认变体
|
||
|
||
### 交互状态
|
||
|
||
组件同时支持 CSS 伪类与 data 属性:
|
||
|
||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||
- **Active/Pressed**:`:active` 或 `[data-pressed="true"]`
|
||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||
- **Disabled**:`:disabled` 或 `[aria-disabled="true"]`
|
||
|
||
## API 参考
|
||
|
||
### CloseButton
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| ------------ | --------------------- | ------------ | -------------------------- |
|
||
| `variant` | `"default"` | `"default"` | 按钮视觉变体 |
|
||
| `isDisabled` | `boolean` | `false` | 是否禁用 |
|
||
| 默认插槽 | `string \| Component` | 内置关闭图标 | 显示内容(默认为关闭图标) |
|
||
|
||
### 原生按钮属性
|
||
|
||
CloseButton 是原生 `button`,`type` 固定为 `"button"`。常用属性包括:
|
||
|
||
| Prop | 类型 | 描述 |
|
||
| ------------------ | -------- | ------------------------------------ |
|
||
| `aria-label` | `string` | 屏幕阅读器的无障碍标签,默认 `Close` |
|
||
| `aria-labelledby` | `string` | 标注按钮的元素 ID |
|
||
| `aria-describedby` | `string` | 描述按钮的元素 ID |
|
||
|
||
### 作用域插槽状态
|
||
|
||
| 参数 | 类型 | 描述 |
|
||
| ---------------- | --------- | ---------------------- |
|
||
| `isHovered` | `boolean` | 是否悬停 |
|
||
| `isPressed` | `boolean` | 是否按下 |
|
||
| `isFocused` | `boolean` | 是否聚焦 |
|
||
| `isFocusVisible` | `boolean` | 是否显示键盘焦点指示器 |
|
||
| `isDisabled` | `boolean` | 是否禁用 |
|
||
|
||
`onPress` 与 React Aria 的 PressEvent 不直接等价;Vue 使用原生 `@click` 与键盘事件。默认关闭图标来自固定基线 `CloseIcon`,可通过插槽替换为任意图标组件。
|
||
|
||
## 相关组件
|
||
|
||
[Alert 警告](./alert) · [AlertDialog 警告对话框](./alert-dialog) · [Chip 标签](./chip)
|