Files
heroui-vue/apps/docs/components/close-button.md
T

110 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
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`,可通过插槽替换为任意图标组件。
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)