feat: add Disclosure DisclosureGroup and Accordion

This commit is contained in:
maoyingjie
2026-10-22 18:25:08 +08:00
parent 73bd7da5fa
commit b086d7f30d
63 changed files with 5597 additions and 4 deletions
+171
View File
@@ -0,0 +1,171 @@
---
title: Accordion 手风琴
description: 用于在紧凑空间中组织信息的可折叠内容面板
component: accordion
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import {
Accordion,
AccordionBody,
AccordionHeading,
AccordionIndicator,
AccordionItem,
AccordionPanel,
AccordionTrigger,
} from "@heroui-vue/components";
</script>
<template>
<Accordion>
<AccordionItem>
<AccordionHeading>
<AccordionTrigger>
标题
<AccordionIndicator />
</AccordionTrigger>
</AccordionHeading>
<AccordionPanel>
<AccordionBody>内容</AccordionBody>
</AccordionPanel>
</AccordionItem>
</Accordion>
</template>
```
<ComponentPreview name="accordion-basic" />
## 组件结构
```vue
<script setup lang="ts">
import {
Accordion,
AccordionBody,
AccordionHeading,
AccordionIndicator,
AccordionItem,
AccordionPanel,
AccordionTrigger,
} from "@heroui-vue/components";
</script>
<template>
<Accordion>
<AccordionItem>
<AccordionHeading>
<AccordionTrigger>
<AccordionIndicator />
</AccordionTrigger>
</AccordionHeading>
<AccordionPanel>
<AccordionBody />
</AccordionPanel>
</AccordionItem>
</Accordion>
</template>
```
Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字 key),部件与布局按手风琴基线独立。
## 示例
### 表面样式
<ComponentPreview name="accordion-surface" />
### 无分隔线
<ComponentPreview name="accordion-without-separator" />
### 多项展开
<ComponentPreview name="accordion-multiple" />
### 禁用状态
<ComponentPreview name="accordion-disabled" />
### 受控组件
<ComponentPreview name="accordion-controlled" />
### 自定义指示器
<ComponentPreview name="accordion-custom-indicator" />
### 渲染函数
上游 `render` 映射为 `as` 与透传属性。
<ComponentPreview name="accordion-render-function" />
### 常见问题布局
<ComponentPreview name="accordion-faq" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="accordion-custom-styles" />
### 全局 CSS
```css
@layer components {
.hv-accordion {
@apply rounded-xl bg-gray-50;
}
.hv-accordion__trigger {
@apply font-semibold text-lg;
}
}
```
## 样式参考
- `.hv-accordion` - 根容器
- `.hv-accordion__item` - 单项与分隔线
- `.hv-accordion__heading` / `.hv-accordion__trigger` / `.hv-accordion__indicator`
- `.hv-accordion__panel` / `.hv-accordion__body` / `.hv-accordion__body-inner`
- `.hv-accordion--surface` - 表面变体
## API 参考
### Accordion
| 属性 | 类型 | 默认值 | 描述 |
| ------------------------ | --------------------------- | ----------- | -------------------- |
| `expandedKeys` | `Array<string \| number>` | - | 受控展开 key |
| `defaultExpandedKeys` | `Array<string \| number>` | `[]` | 初始展开 key |
| `allowsMultipleExpanded` | `boolean` | `false` | 是否允许多项同时展开 |
| `isDisabled` | `boolean` | `false` | 禁用整个 Accordion |
| `variant` | `"default" \| "surface"` | `"default"` | 视觉变体 |
| `hideSeparator` | `boolean` | `false` | 隐藏项之间的分隔线 |
| `as` | `string` | `"div"` | 根元素 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
### AccordionItem
| 属性 | 类型 | 默认值 | 描述 |
| ----------------- | ------------------ | ------- | -------------------- |
| `id` | `string \| number` | - | 该项唯一标识(组键) |
| `expanded` | `boolean` | - | 受控展开状态 |
| `defaultExpanded` | `boolean` | `false` | 初始展开 |
| `isDisabled` | `boolean` | `false` | 禁用该项 |
| `as` | `string` | `"div"` | 项根元素 |
### AccordionHeading / Trigger / Panel / Body / Indicator
与 Disclosure 对应部件语义一致,使用 `hv-accordion__*` 样式;Trigger 为 `type="button"`,Panel 负责高度动画,Indicator 支持自定义图标插槽。
## 相关组件
- [Disclosure 折叠面板](./disclosure)
- [DisclosureGroup 折叠面板组](./disclosure-group)