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
4.9 KiB
4.9 KiB
title, description, component, group
| title | description | component | group |
|---|---|---|---|
| ButtonGroup 按钮组 | 将相关按钮组合在一起,保持一致的样式与间距 | button-group | 组件 |
用法
<script setup lang="ts">
import { ButtonGroup, Button } from "@heroui-vue/components";
</script>
组件结构
<script setup lang="ts">
import {
ButtonGroup,
Button,
ButtonGroupSeparator,
} from "@heroui-vue/components";
</script>
<template>
<ButtonGroup>
<Button>First</Button>
<Button>
<ButtonGroupSeparator />
Second
</Button>
<Button>
<ButtonGroupSeparator />
Third
</Button>
</ButtonGroup>
</template>
ButtonGroup 将多个 Button 组合在一起,应用一致的样式、间距与自动圆角处理。它通过 provide/inject 向直接子按钮传递
size、variant与isDisabled属性。
示例
变体
尺寸
方向
使用 orientation 属性可水平或垂直排列按钮。
带图标
宽度充满
禁用状态
无分隔线
省略按钮中的 <ButtonGroupSeparator /> 组件即可。
自定义样式
Tailwind CSS
全局 CSS
可使用 @layer components 指令自定义 ButtonGroup 组件类。
@layer components {
.hv-button-group {
@apply gap-2 rounded-lg;
}
.hv-button-group__separator {
@apply opacity-25;
}
}
样式参考
HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。
CSS 类
ButtonGroup 组件使用以下 CSS 类:
基础类 [!toc]
.hv-button-group- 按钮组根容器.hv-button-group--full-width- 全宽修饰符.hv-button-group__separator- 按钮之间的分隔元素
ButtonGroup 组件自动为按钮应用圆角:
- 第一个按钮圆角左/起始边
- 最后一个按钮圆角右/结束边
- 中间按钮无圆角
- 单个按钮四边全圆角
在每个 Button 内(第一个除外)添加 <ButtonGroupSeparator /> 以显示分隔线。
API 参考
ButtonGroup
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
variant |
'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft' |
- | 应用于组内所有直接子按钮的视觉变体 |
size |
'sm' | 'md' | 'lg' |
- | 应用于组内所有直接子按钮的尺寸 |
orientation |
'horizontal' | 'vertical' |
'horizontal' |
按钮组方向 |
fullWidth |
boolean |
false |
是否占满容器宽度 |
isDisabled |
boolean |
false |
是否禁用组内所有直接子按钮(单个按钮可覆盖) |
as |
string |
'div' |
渲染的根元素 |
class |
string |
- | 附加 CSS 类 |
ButtonGroupSeparator
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
class |
string |
- | 附加 CSS 类 |
说明
- ButtonGroup 通过 provide/inject 向直接子 Button 传递
size、variant与isDisabled属性 - 仅直接子按钮接收 ButtonGroup 属性 - 嵌套在其他组件(如 Modal、Dropdown 等)内的 Button 即使位于 ButtonGroup 后代也不会继承组属性
- 单个 Button 可通过自身属性覆盖组的默认值
- 组件自动处理按钮之间的圆角
- 在每个 Button 内(第一个除外)添加
<ButtonGroupSeparator />,可在按钮之间显示分隔线 - 组内按钮移除 active/pressed 缩放变换,外观更统一