docs: close documentation facts, structure and related-component mapping

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
This commit is contained in:
maoyingjie
2026-10-28 22:32:10 +08:00
parent 2c6d871354
commit 145a208687
76 changed files with 912 additions and 352 deletions
+76 -18
View File
@@ -37,7 +37,7 @@ import {
</template>
```
<ComponentPreview name="accordion-basic" />
<ComponentPreview name="accordion-basic" minHeight="400px" />
## 组件结构
@@ -76,37 +76,37 @@ Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字
### 表面样式
<ComponentPreview name="accordion-surface" />
<ComponentPreview name="accordion-surface" minHeight="400px" />
### 无分隔线
<ComponentPreview name="accordion-without-separator" />
<ComponentPreview name="accordion-without-separator" minHeight="400px" />
### 多项展开
<ComponentPreview name="accordion-multiple" />
<ComponentPreview name="accordion-multiple" minHeight="524px" />
### 禁用状态
<ComponentPreview name="accordion-disabled" />
<ComponentPreview name="accordion-disabled" minHeight="524px" />
### 受控组件
<ComponentPreview name="accordion-controlled" />
<ComponentPreview name="accordion-controlled" minHeight="400px" />
### 自定义指示器
<ComponentPreview name="accordion-custom-indicator" />
<ComponentPreview name="accordion-custom-indicator" minHeight="320px" />
### 渲染函数
上游 `render` 映射为 `as` 与透传属性。
<ComponentPreview name="accordion-render-function" />
<ComponentPreview name="accordion-render-function" minHeight="400px" />
### 常见问题布局
<ComponentPreview name="accordion-faq" />
<ComponentPreview name="accordion-faq" minHeight="720px" />
## 自定义样式
@@ -130,11 +130,40 @@ Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字
## 样式参考
- `.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` - 表面变体
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
Accordion 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/accordion.css)):
#### 基础类 [!toc]
- `.hv-accordion` - Accordion 根容器
- `.hv-accordion__item` - 单个 Accordion 项(含分隔线)
- `.hv-accordion__heading` - 标题包裹层
- `.hv-accordion__trigger` - 可点击的触发按钮
- `.hv-accordion__indicator` - 展开/收起指示图标
- `.hv-accordion__panel` - 可折叠面板容器(高度动画宿主)
- `.hv-accordion__body` / `.hv-accordion__body-inner` - 正文外层与内层包裹
#### 变体类 [!toc]
- `.hv-accordion--surface` - 表面变体(边框、背景与分隔线收口)
#### 状态类 [!toc]
- `.hv-accordion__trigger[aria-expanded="true"]` - 展开状态
- `.hv-accordion__trigger[aria-disabled="true"]` - 禁用状态
- `.hv-accordion__panel[data-expanded="true"]` / `.hv-accordion__indicator[data-expanded="true"]` - 面板与指示器的展开标记
### 交互状态
触发器以 CSS 伪类为主(组件不输出 `data-hovered` / `data-focus-visible` 标记,可通过 attrs 传入这些标记作为自定义样式钩子):
- **悬停**:触发器上 `:hover`(仅未展开时上色)
- **聚焦**:触发器上 `:focus-visible`(显示焦点环)
- **禁用**:触发器上 `:disabled` 或 `[aria-disabled="true"]`(同时输出 `[data-disabled="true"]` 标记)
- **展开**:触发器上 `[aria-expanded="true"]`
## API 参考
@@ -161,11 +190,40 @@ Accordion 复用 DisclosureGroup 的展开键协议(数组、字符串/数字
| `isDisabled` | `boolean` | `false` | 禁用该项 |
| `as` | `string` | `"div"` | 项根元素 |
### AccordionHeading / Trigger / Panel / Body / Indicator
### AccordionHeading
与 Disclosure 对应部件语义一致,使用 `hv-accordion__*` 样式;Trigger 为 `type="button"`,Panel 负责高度动画,Indicator 支持自定义图标插槽。
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------ | -------------- |
| `as` | `string` | `'h3'` | 标题根元素标签 |
| `level` | `number` | `3` | 语义标题级别 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
| 默认插槽 | - | - | 标题内容 |
### AccordionTrigger
| 属性 | 类型 | 默认值 | 描述 |
| -------------- | --------------------------- | ---------- | ------------------------------------------------ |
| `as` | `string` | `'button'` | 触发器根元素;为 `button` 时输出 `type="button"` |
| `asChild` | `boolean` | `false` | 将展开切换与状态合并到默认插槽中唯一的根元素 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
| 默认作用域插槽 | - | - | 提供 `isExpanded`、`isDisabled` |
### AccordionPanel / AccordionBody
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ------- | ---------------------------------------------------------- |
| `as` | `string` | `'div'` | 根元素;Panel 负责高度动画,Body 的 `class` 落在内层包裹上 |
| `class` | `string \| Array \| Object` | - | 额外的 CSS 类 |
| 默认插槽 | - | - | 面板 / 正文内容 |
### AccordionIndicator
| 属性 | 类型 | 默认值 | 描述 |
| -------------- | ---- | ------ | ------------------------------------------------------------------ |
| 默认作用域插槽 | - | - | 自定义指示图标;提供 `isExpanded`。缺省时渲染基线 ChevronDown 图标 |
与 Disclosure 对应部件语义一致,使用 `hv-accordion__*` 样式。
## 相关组件
- [Disclosure 折叠面板](./disclosure)
- [DisclosureGroup 折叠面板组](./disclosure-group)
[DisclosureGroup 折叠面板组](./disclosure-group) · [Disclosure 折叠面板](./disclosure)
+1 -2
View File
@@ -296,5 +296,4 @@ state.setOpen(true);
## 相关组件
- [Modal 模态框](./modal)
- [Button 按钮](./button)
[Button 按钮](./button) · [CloseButton 关闭按钮](./close-button)
+1 -1
View File
@@ -145,4 +145,4 @@ Alert 会把内部 `surfaceContext` 重置为 `default`,避免嵌套在其他
## 相关组件
[Button 按钮](./button) · [CloseButton 关闭按钮](./close-button) · [Spinner 加载指示器](./spinner)
[CloseButton 关闭按钮](./close-button) · [Button 按钮](./button) · [Spinner 加载指示器](./spinner)
+1 -1
View File
@@ -145,4 +145,4 @@ AvatarGroup 组件使用以下 CSS 类:
## 相关组件
[Avatar 头像](./avatar) · [Card 卡片](./card)
[Avatar 头像](./avatar) · [Badge 徽章](./badge) · [Chip 标签](./chip)
+6 -6
View File
@@ -123,7 +123,7 @@ Avatar 组件使用以下 CSS 类:
| Prop | 类型 | 默认值 | 描述 |
| ------------- | ---------------------------------- | ------- | ------------------------------------------ |
| `src` | `string` | - | 可选图片 URL,省略时显示回退 |
| `src` | `string` | - | 可选图片 URL,省略时显示回退 |
| `srcSet` | `string` | - | 响应式图片的 `srcset` 属性 |
| `sizes` | `string` | - | 响应式图片的 `sizes` 属性 |
| `alt` | `string` | - | 图片替代文本 |
@@ -136,11 +136,11 @@ Avatar 组件使用以下 CSS 类:
### AvatarFallback
| Prop | 类型 | 默认值 | 描述 |
| --------- | ------------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------- |
| Prop | 类型 | 默认值 | 描述 |
| --------- | ------------------------------------------------------------- | ------ | ------------------------------------------------------------------------- |
| `delayMs` | `number` | - | 显示 fallback 前的延迟(毫秒);省略或 `0` 时立即显示,正数延迟可动态更新 |
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | - | 覆盖父级颜色(替换而非叠加) |
| `class` | `string` | - | 附加 CSS 类 |
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | - | 覆盖父级颜色(替换而非叠加) |
| `class` | `string` | - | 附加 CSS 类 |
三个部件均支持 `as`(根/回退默认 `span`,图片默认 `img`)与 `asChild`(默认 `false`)。`asChild` 需要单个可接收属性的元素或组件;自定义组件应将 attrs 和事件透传到实际 DOM。Image 的默认插槽用于提供自定义图片,Root / Fallback 的默认插槽分别提供部件与回退内容。`referrerPolicy` 接受原生图片策略并透传。
@@ -150,4 +150,4 @@ Avatar 使用 Reka UI 的 `AvatarRoot` / `AvatarImage` / `AvatarFallback` 处理
## 相关组件
[AvatarGroup 头像组](./avatar-group) · [Card 卡片](./card)
[AvatarGroup 头像组](./avatar-group) · [Separator 分隔符](./separator) · [Badge 徽章](./badge)
+1 -1
View File
@@ -186,4 +186,4 @@ Badge 支持组合变体与颜色类(如 `.hv-badge--primary.hv-badge--accent`
## 相关组件
[Chip 标签](./chip) · [Avatar 头像](./avatar)
[Avatar 头像](./avatar) · [Chip 标签](./chip)
+1 -1
View File
@@ -173,4 +173,4 @@ Breadcrumbs 组件使用以下 CSS 类([查看源码样式](https://github.com
## 相关组件
[Link 链接](./link) · [Separator 分隔符](./separator)
[Link 链接](./link) · [Separator 分隔符](./separator) · [Tabs 标签页](./tabs)
+1 -3
View File
@@ -153,6 +153,4 @@ ButtonGroup 组件自动为按钮应用圆角:
## 相关组件
- [Button 按钮](./button)
- [ToggleButton 切换按钮](./toggle-button)
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
[Button 按钮](./button) · [Dropdown 下拉菜单](./dropdown) · [Chip 标签](./chip)
+50 -3
View File
@@ -89,21 +89,68 @@ Vue 使用 `asChild` 将按钮属性与交互合并到一个自定义原生 butt
### 全局 CSS
可使用 `@layer components` 指令自定义 Button 组件类;下面的选择器与语义变量都是当前样式表中真实存在的入口:
```css
@layer components {
/* 覆盖变体语义变量 */
.hv-button--primary {
--button-bg: oklch(0.6 0.2 300);
--button-bg-hover: oklch(0.55 0.2 300);
--button-bg-pressed: oklch(0.55 0.2 300);
--button-fg: white;
}
/* 或直接覆盖类规则 */
.hv-button--icon-only {
@apply rounded-lg;
}
}
```
## 样式参考
基础类为 `.hv-button`,变体为 `.hv-button--primary` 等;尺寸为 `.hv-button--sm` / `md` / `lg`。支持 `.hv-button--icon-only` 和 `.hv-button--full-width`。
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
Button 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/button.css)):
#### 基础与尺寸类 [!toc]
- `.hv-button` - 基础按钮样式
- `.hv-button--sm` - 小尺寸变体
- `.hv-button--md` - 中尺寸变体(默认)
- `.hv-button--lg` - 大尺寸变体
#### 变体类 [!toc]
- `.hv-button--primary`
- `.hv-button--secondary`
- `.hv-button--tertiary`
- `.hv-button--outline`
- `.hv-button--ghost`
- `.hv-button--danger`
- `.hv-button--danger-soft`
#### 修饰符类 [!toc]
- `.hv-button--icon-only`
- `.hv-button--icon-only.hv-button--sm`
- `.hv-button--icon-only.hv-button--lg`
- `.hv-button--full-width`
### 交互状态
保留 `data-hovered`、`data-pressed`、`data-focused`、`data-focus-visible`、`data-pending` 状态;键盘焦点样式与鼠标焦点区分。加载期间保留焦点并阻止重复点击,通过 aria-disabled 呈现半透明的原变体颜色。
按钮同时支持 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"]`(降低透明度,禁用指针事件)
- **Pending**:`[data-pending="true"]`(加载期间禁用指针事件)
加载期间保留焦点并阻止重复点击,通过 `aria-disabled` 呈现半透明的原变体颜色。
## API 参考
@@ -139,4 +186,4 @@ Vue 使用 `@click` 和默认作用域插槽。插槽提供 `isPending`、`isPre
## 相关组件
[Card 卡片](./card) · [Input 输入框](./input) · [Switch 开关](./switch)
[Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip) · [Form 表单](./form)
+8 -8
View File
@@ -261,12 +261,12 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部
年份选择器支持日期格式与窗口选项。独立部件直接从包根导入,不需要 React 上下文。
| Component | Prop | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------- |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标签(如 `{month: 'short'}`) |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局) |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法等) |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 跨度 | 滑动窗口中显示的年份数。同时设置 `minValue` 与 `maxValue` 时默认为完整范围 |
| Component | Prop | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标签(如 `{month: 'short'}`) |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局) |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法等) |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 完整范围 | 以焦点年为中心的滑动窗口年份数;缺省显示 min–max 完整范围(未设约束时为 1900–2099)。上游文档写“min–max 跨度或 `20`”,本实现没有 `20` 的回退分支 |
### CalendarCell 作用域插槽
@@ -298,12 +298,12 @@ Calendar 保留固定基线的主要属性与部件,以 Vue 模型、具名部
- `locale`、`dir` 优先于 ConfigProvider;`timeZone` 用于“今天”标记。显示历法与公开模型历法分离;默认上下界按公历 1900-01-01 至 2099-12-31 转换到显示历法,与上游部分历法的近似年份偏移算法有差异。
- 根为 `role="group"`,网格为语义 table/grid,CalendarCell 输出 td/gridcell + 原生 button。`class`、ARIA、DOM 事件落在真正可交互按钮;取消 Cell 的键盘或点击事件可阻止默认处理,祖先需使用捕获事件取消。`isDateDisabled` 完全禁用日期;`isDateUnavailable` 保留焦点但阻止选择。
- 左右/上下键移动日期,Home/End 到周边界,PageUp/PageDown 移动月份,Shift+PageUp/PageDown 移动年份;Enter/Space 选择。年份层为三列,方向键与 Home/End 移动,Escape 关闭并恢复触发器。
- Calendar 本身不产生原生命名表单输入,也不消费 Label/FieldError 的字段协议;表单字段与 Picker 后续共享 DateField 基建。RangeCalendar 与 TimeField 已有独立公共组件;DatePicker、DateRangePicker 尚未迁移。
- Calendar 本身不产生原生命名表单输入,也不消费 Label/FieldError 的字段协议;表单字段由 DateField 体系承载,DatePicker、DateRangePicker 复用同一套 DateField 部件。RangeCalendar、TimeField、DatePicker、DateRangePicker 均有独立公共组件。
- `weeksInMonth` 是行数下限,不裁掉真实月份日期。`visibleYears` 是以聚焦年份为中心的窗口;默认显示完整 min/max 年份范围。复杂 era 可通过年份插槽中的 `date` 传给 CalendarYearPickerCell,避免仅凭数字年份混淆。
- 键盘适配层针对安装版 Reka 缺少 week/day view、年份层及原生取消缺口使用本地日期视图算法;不运行 React,也不承诺完整 React Aria 类型或全部读屏行为等价。
## 相关组件
[DateField 日期字段](./date-field) · [Select 选择器](./select) · [Popover 弹出框](./popover)
[RangeCalendar 范围日历](./range-calendar) · [DateField 日期字段](./date-field) · [DatePicker 日期选择器](./date-picker)
Root 默认插槽还提供 `value`、`isDisabled`、`isReadOnly`、`isInvalid`、`focusedValue`、`visibleRange` 与 `isYearPickerOpen`。Cell 插槽还提供 `date`、`isOutsideVisibleRange`、`isToday`、`isHovered`、`isPressed`、`isFocused`、`isFocusVisible`。使用 `defaultFocusedValue`、`locale`、`dir`、`timeZone`、`isDateDisabled` 可显式设置初始视图、国际化和禁用规则。
+15 -2
View File
@@ -94,6 +94,13 @@ Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允
| CardContent | `.hv-card__content` | `card-content` | div |
| CardFooter | `.hv-card__footer` | `card-footer` | div |
#### 变体类 [!toc]
- `.hv-card--transparent` - 透明背景、无边框与无阴影(遮罩层与自定义背景场景)
- `.hv-card--default` - 默认表面(`bg-surface`)
- `.hv-card--secondary` - 次级表面(`bg-surface-secondary`)
- `.hv-card--tertiary` - 三级表面(`bg-surface-tertiary`)
## API 参考
### Card
@@ -106,7 +113,13 @@ Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允
### CardHeader / CardTitle / CardDescription / CardContent / CardFooter
各部件支持 `as`、默认插槽和原生属性。默认标签见上表。Vue 使用独立命名导出替代 `Card.Header` 等 React 部件访问方式。
| 属性 | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ---------------- | ------------------------------------------ |
| `as` | `string` | 见上表默认元素列 | 渲染的 HTML 元素 |
| `class` | `string \| Array \| Object` | — | 额外的 CSS 类,合并到部件根元素 |
| 默认插槽 | - | - | 部件内容;`$attrs`(ARIA、事件)透传根元素 |
各部件无业务状态或事件;类名与 `data-slot` 见样式参考表。Vue 使用独立命名导出替代 `Card.Header` 等 React 部件访问方式。
## 无障碍
@@ -118,4 +131,4 @@ Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
[Surface 表面](./surface) · [Avatar 头像](./avatar) · [Form 表单](./form)
+1 -1
View File
@@ -200,4 +200,4 @@ render 自定义根类型未支持;基线 div+data-custom 示例以 Vue 根属
## 相关组件
[Checkbox](./checkbox) · [CheckboxGroup](./checkbox-group) · [RadioGroup](./radio-group) · [Fieldset](./fieldset)
[Checkbox 复选框](./checkbox) · [Label 标签](./label) · [Fieldset 字段组](./fieldset)
+1 -1
View File
@@ -266,4 +266,4 @@ render 自定义根类型未支持;基线 div+data-custom 示例以 Vue 根属
## 相关组件
[Checkbox](./checkbox) · [CheckboxGroup](./checkbox-group) · [RadioGroup](./radio-group) · [Fieldset](./fieldset)
[Label 标签](./label) · [CheckboxGroup 复选框组](./checkbox-group) · [Description 描述](./description)
+1 -1
View File
@@ -157,4 +157,4 @@ Chip 支持组合变体与颜色类(如 `.hv-chip--secondary.hv-chip--accent`
## 相关组件
[Card 卡片](./card) · [Avatar 头像](./avatar)
[Avatar 头像](./avatar) · [CloseButton 关闭按钮](./close-button) · [Separator 分隔符](./separator)
+1 -1
View File
@@ -106,4 +106,4 @@ CloseButton 是原生 `button`,`type` 固定为 `"button"`。常用属性包
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
[Alert 警告](./alert) · [AlertDialog 警告对话框](./alert-dialog) · [Chip 标签](./chip)
+2
View File
@@ -178,4 +178,6 @@ Vue 版写作 `ColorAreaThumb`(对应上游 `ColorArea.Thumb`)。
## 相关组件
[ColorSwatch 颜色色块](./color-swatch) · [ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorField 颜色输入框](./color-field)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+49 -5
View File
@@ -266,23 +266,67 @@ color.toString("hex");
color.getChannelValue("red");
```
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 已公开;ColorPicker 尚未公开。
本页部件和 Props,以及 `ColorFieldRenderProps`、`ColorFieldRenderState`、`ColorFieldSlots`、`ColorFieldExpose`、`colorFieldVariants`、`colorInputGroupVariants`、`ColorFieldVariants`、`ColorInputGroupVariants` 均从包根公开。ColorInputGroup 与 ColorField 的对应部件共享实现。[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker) 均已公开。
## ColorField.Group Styling
使用 `.hv-color-input-group`、`__input`、`__prefix`、`__suffix` 定制各节点;primary/secondary/full-width 修饰符与上游视觉数值一致。根容器为 `.hv-color-field`。Group 负责 hover/focus-within/invalid/disabled 的样式,Input 自身去掉默认边框和焦点轮廓;焦点环展示在 Group。状态必须写在实际匹配 CSS 的节点。
根容器为 `.hv-color-field`,Group 为 `.hv-color-input-group`。Group 负责 hover/focus-within/invalid/disabled 的样式,Input 自身去掉默认边框和焦点轮廓;焦点环展示在 Group。状态必须写在实际匹配 CSS 的节点。primary/secondary/full-width 修饰符与上游视觉数值一致。
### Customizing the component classes
基础类驱动每个实例。使用 `@layer components` 一次性覆盖:
```css
@layer components {
.hv-color-input-group {
border-radius: var(--radius-field);
@apply inline-flex h-9 items-center overflow-hidden rounded-field border bg-field text-sm text-field-foreground shadow-field outline-none;
&:hover,
&[data-hovered="true"] {
@apply bg-field-hover;
}
&[data-focus-within="true"],
&:focus-within {
@apply status-focused-field;
}
&[data-invalid="true"] {
@apply status-invalid-field;
}
&[data-disabled="true"],
&[aria-disabled="true"] {
@apply status-disabled;
}
}
.hv-color-input-group__input {
font-variant-numeric: tabular-nums;
@apply flex min-w-0 flex-1 items-center rounded-none border-0 bg-transparent px-3 py-2 shadow-none outline-none;
}
.hv-color-input-group__prefix,
.hv-color-input-group__suffix {
@apply flex shrink-0 items-center text-field-placeholder;
}
}
```
### ColorField.Group CSS Classes
- `.hv-color-input-group` - 根容器样式
- `.hv-color-input-group__input` - Input 包装器样式(含 `min-w-0` 通道收窄)
- `.hv-color-input-group__prefix` - 前缀元素样式
- `.hv-color-input-group__suffix` - 后缀元素样式
- `.hv-color-input-group--primary` / `--secondary` / `--full-width` - 变体与宽度修饰符
### ColorField.Group Interactive States
- **Hover**:`:hover:not(:focus-within)` 或 `[data-hovered="true"]:not([data-focus-within="true"])`
- **Focus Within**:`[data-focus-within="true"]` 或 `:focus-within`
- **Invalid**:`[data-invalid="true"]`(与 `aria-invalid` 同步)
- **Disabled**:`[data-disabled="true"]` 或 `[aria-disabled="true"]`
## 相关组件
[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch) 与 [ColorPicker 颜色选择器](/components/color-picker)。
[ColorSwatch 颜色色块](./color-swatch) · [ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorPicker 颜色选择器](./color-picker)
+62 -56
View File
@@ -80,7 +80,11 @@ import {
<Label>选择颜色</Label>
</ColorPickerTrigger>
<ColorPickerPopover>
<ColorArea color-space="hsb" x-channel="saturation" y-channel="brightness">
<ColorArea
color-space="hsb"
x-channel="saturation"
y-channel="brightness"
>
<ColorAreaThumb />
</ColorArea>
<ColorSlider channel="hue" color-space="hsb">
@@ -173,84 +177,84 @@ ColorPicker 组件使用以下 CSS 类([查看源码样式](https://github.com
对应固定源的 [React Aria ColorPicker](https://react-spectrum.adobe.com/react-aria/ColorPicker.html):共享颜色 owner + `DialogTrigger`/`Popover` 组合。普通颜色值使用 `v-model`,输出本库 `Color`。
| Prop | 类型 | 默认值 | 描述 |
| -------------- | --------------------------------------------- | ---------- | -------------------------------------------------------------------- |
| `modelValue` | `string \| Color` | - | 当前接受颜色(`v-model`;受控) |
| `value` | `string \| Color` | - | 低优先级受控别名;`modelValue` 存在时优先 |
| `defaultValue` | `string \| Color` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值 |
| `open` | `boolean` | - | 受控展开;拒绝打开时仍发出 `update:open`/`openChange` |
| `isOpen` | `boolean` | - | 展开别名;`open` 与 `isOpen` 同时存在时 `open` 优先,不会双输入竞争 |
| `defaultOpen` | `boolean` | `false` | 非受控初始展开 |
| `isDisabled` | `boolean` | `false` | 禁用整个组合(库扩展,作用于自身子组件) |
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
| `isReadOnly` | `boolean` | `false` | 只读:保留展示与程序化赋值,阻止子控件编辑(库扩展) |
| `name` | `string` | - | Vue 扩展:单个隐藏输入提交完整精度颜色 |
| `form` | `string` | - | Vue 扩展:关联外部表单 id |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
| 默认作用域插槽 | `({ color, isOpen, close, isDisabled, isReadOnly }) => VNodeChild` | - | 根渲染状态 |
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ------------------------------------------------------------------ | ----------- | ------------------------------------------------------------------- |
| `modelValue` | `string \| Color` | - | 当前接受颜色(`v-model`;受控) |
| `value` | `string \| Color` | - | 低优先级受控别名;`modelValue` 存在时优先 |
| `defaultValue` | `string \| Color` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值 |
| `open` | `boolean` | - | 受控展开;拒绝打开时仍发出 `update:open`/`openChange` |
| `isOpen` | `boolean` | - | 展开别名;`open` 与 `isOpen` 同时存在时 `open` 优先,不会双输入竞争 |
| `defaultOpen` | `boolean` | `false` | 非受控初始展开 |
| `isDisabled` | `boolean` | `false` | 禁用整个组合(库扩展,作用于自身子组件) |
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
| `isReadOnly` | `boolean` | `false` | 只读:保留展示与程序化赋值,阻止子控件编辑(库扩展) |
| `name` | `string` | - | Vue 扩展:单个隐藏输入提交完整精度颜色 |
| `form` | `string` | - | Vue 扩展:关联外部表单 id |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
| 默认作用域插槽 | `({ color, isOpen, close, isDisabled, isReadOnly }) => VNodeChild` | - | 根渲染状态 |
事件:
| 事件 | 参数 | 时机 |
| --------------------- | ------- | -------------------------------------------------------------------- |
| `update:modelValue` / `change` | `Color` | 子控件提出不同颜色时一起触发(`v-model` 使用前者);受控父组件可拒绝提案 |
| `changeEnd` | `Color` | 有颜色提案的手势正常结束时传出最后提案;不表示父组件已接受,取消时不触发 |
| `update:open` / `update:isOpen` / `openChange` | `boolean` | 展开状态提案;受控拒绝时保持提案事件,不改变实际展开 |
| 事件 | 参数 | 时机 |
| ---------------------------------------------- | --------- | ------------------------------------------------------------------------ |
| `update:modelValue` / `change` | `Color` | 子控件提出不同颜色时一起触发(`v-model` 使用前者);受控父组件可拒绝提案 |
| `changeEnd` | `Color` | 有颜色提案的手势正常结束时传出最后提案;不表示父组件已接受,取消时不触发 |
| `update:open` / `update:isOpen` / `openChange` | `boolean` | 展开状态提案;受控拒绝时保持提案事件,不改变实际展开 |
受控拒绝、相同提案重试、外部替换与事务取消的行为与共享颜色 owner 一致:父组件不接受提案时坐标、滑块、字段文本、预览与表单值保持接受值,提案不会冒充已接受颜色,也不会经 hex 往返量化。
### ColorPickerTrigger
| Prop | 类型 | 默认值 | 描述 |
| --------------- | -------------------------------- | -------- | -------------------------------------------------------- |
| `as` | `string` | `"button"` | 自定义根元素标签 |
| `asChild` | `boolean` | `false` | 把触发器属性合并到默认插槽根节点 |
| `isDisabled` | `boolean` | `false` | 额外禁用;owner 禁用时同样禁用 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认作用域插槽 | `({ color, isDisabled }) => VNodeChild` | - | 触发器内容状态 |
| Prop | 类型 | 默认值 | 描述 |
| -------------- | --------------------------------------- | ---------- | -------------------------------- |
| `as` | `string` | `"button"` | 自定义根元素标签 |
| `asChild` | `boolean` | `false` | 把触发器属性合并到默认插槽根节点 |
| `isDisabled` | `boolean` | `false` | 额外禁用;owner 禁用时同样禁用 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认作用域插槽 | `({ color, isDisabled }) => VNodeChild` | - | 触发器内容状态 |
触发器渲染为真实 `button[type=button]`,不会意外提交外层表单;固定源的 Button render props(`isHovered`/`isPressed` 等)在 Vue 版收敛为 `color`/`isDisabled` 两个插槽状态,差异已记录。
### ColorPickerPopover
| Prop | 类型 | 默认值 | 描述 |
| --------------------------- | -------------------------- | --------------- | ---------------------------------------- |
| `placement` | `OverlayPlacement` | `"bottom left"` | 弹出层位置(RTL 下自动镜像) |
| `offset` | `number` | `8` | 与锚点的间距 |
| `crossOffset` | `number` | `0` | 交叉轴偏移 |
| `shouldFlip` | `boolean` | `true` | 视口碰撞时翻转 |
| `containerPadding` | `number` | `12` | 碰撞计算的容器留白 |
| `to` | `string \| HTMLElement` | - | 自定义 Teleport 目标 |
| `isNonModal` | `boolean` | `false` | 非模态:不锁定焦点与滚动 |
| `isDismissable` | `boolean` | `true` | 允许外部点击关闭 |
| `isKeyboardDismissDisabled` | `boolean` | `false` | 禁用 Esc 关闭 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认作用域插槽 | `({ isOpen, close }) => VNodeChild` | - | 弹层内容状态 |
| Prop | 类型 | 默认值 | 描述 |
| --------------------------- | ----------------------------------- | --------------- | ---------------------------- |
| `placement` | `OverlayPlacement` | `"bottom left"` | 弹出层位置(RTL 下自动镜像) |
| `offset` | `number` | `8` | 与锚点的间距 |
| `crossOffset` | `number` | `0` | 交叉轴偏移 |
| `shouldFlip` | `boolean` | `true` | 视口碰撞时翻转 |
| `containerPadding` | `number` | `12` | 碰撞计算的容器留白 |
| `to` | `string \| HTMLElement` | - | 自定义 Teleport 目标 |
| `isNonModal` | `boolean` | `false` | 非模态:不锁定焦点与滚动 |
| `isDismissable` | `boolean` | `true` | 允许外部点击关闭 |
| `isKeyboardDismissDisabled` | `boolean` | `false` | 禁用 Esc 关闭 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认作用域插槽 | `({ isOpen, close }) => VNodeChild` | - | 弹层内容状态 |
弹层内容通过 Teleport 渲染,Surface 默认上下文穿过 Teleport;嵌套的 `Select`/`ListBox` 等内层弹层各自独立处理 Esc、外部点击与焦点恢复,不会误关外层 ColorPicker。
### Render Props
| 插槽状态 | 类型 | 含义 |
| ------------------------------------------------------- | --------------- | ------------------------------------ |
| `color`(根) | `Color` | 当前接受颜色(组合不允许空值) |
| `isOpen` / `isDisabled` / `isReadOnly`(根) | `boolean` | 真实状态 |
| `close`(根 / 弹层) | `() => void` | 关闭弹层 |
| `color` / `isDisabled`(Trigger) | `Color \| null` / `boolean` | 触发器内容状态 |
| `isOpen`(Popover) | `boolean` | 弹层展开状态 |
| 插槽状态 | 类型 | 含义 |
| -------------------------------------------- | --------------------------- | ------------------------------ |
| `color`(根) | `Color` | 当前接受颜色(组合不允许空值) |
| `isOpen` / `isDisabled` / `isReadOnly`(根) | `boolean` | 真实状态 |
| `close`(根 / 弹层) | `() => void` | 关闭弹层 |
| `color` / `isDisabled`(Trigger) | `Color \| null` / `boolean` | 触发器内容状态 |
| `isOpen`(Popover) | `boolean` | 弹层展开状态 |
Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `color`(接受颜色)。不暴露颜色 owner、事务 token 或弹层内部状态。
### 展开与焦点
| 操作 | 行为 |
| ------------------- | ------------------------------------------------------------------------ |
| 触发器 click | 切换弹层;可取消的 `click`(`preventDefault`)会阻止打开 |
| `Esc` | 先恢复/丢弃子控件草稿,再关闭弹层并把焦点还给触发器 |
| 外部点击 | 关闭弹层;未结束的颜色事务立即取消,不补发虚假 `changeEnd` |
| `Tab` / `Shift+Tab` | 焦点在弹层内循环(模态);嵌套 Select 的内层选项可正常聚焦与选择 |
| 焦点恢复 | 关闭后焦点回到触发器;退出动画期间弹层保持不可交互 |
| 操作 | 行为 |
| ------------------- | ---------------------------------------------------------------- |
| 触发器 click | 切换弹层;可取消的 `click`(`preventDefault`)会阻止打开 |
| `Esc` | 先恢复/丢弃子控件草稿,再关闭弹层并把焦点还给触发器 |
| 外部点击 | 关闭弹层;未结束的颜色事务立即取消,不补发虚假 `changeEnd` |
| `Tab` / `Shift+Tab` | 焦点在弹层内循环(模态);嵌套 Select 的内层选项可正常聚焦与选择 |
| 焦点恢复 | 关闭后焦点回到触发器;退出动画期间弹层保持不可交互 |
### 表单
@@ -262,4 +266,6 @@ Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `color`
## 相关组件
[ColorArea 颜色区域](./color-area) · [ColorSlider 颜色滑块](./color-slider) · [ColorSwatch 颜色色块](./color-swatch)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+2
View File
@@ -281,4 +281,6 @@ ColorSlider 实现 ARIA slider 模式,提供:
## 相关组件
[ColorSwatch 颜色色块](./color-swatch) · [ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorPicker 颜色选择器](./color-picker)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+53 -51
View File
@@ -174,22 +174,22 @@ ColorSwatchPicker 组件使用以下 CSS 类([查看源码样式](https://gith
对应固定源的 [React Aria ColorSwatchPicker](https://react-spectrum.adobe.com/react-aria/ColorSwatchPicker.html)(`listbox` / `option` 语义,单项选择且不允许清空)。
| Prop | 类型 | 默认值 | 描述 |
| ------------ | ------------------------------------------ | ---------- | ------------------------------------------------------------------------ |
| `modelValue` | `string \| Color \| null` | - | 当前接受颜色(`v-model`;受控) |
| `value` | `string \| Color \| null` | - | 低优先级受控别名,与共享颜色模型一致 |
| `defaultValue` | `string \| Color \| null` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值,不会自动选中第一个候选 |
| `layout` | `"grid" \| "stack"` | `"grid"` | 布局方向(视觉 flex 布局,ARIA 方向固定为 vertical) |
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | swatch 尺寸 |
| `variant` | `"circle" \| "square"` | `"circle"` | swatch 形状 |
| `isDisabled` | `boolean` | `false` | 禁用整个选择器(库扩展) |
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
| `isReadOnly` | `boolean` | `false` | 只读:保留选择与焦点,阻止新的选择(库扩展) |
| `dir` | `"ltr" \| "rtl"` | - | 方向;影响水平方向键映射 |
| `as` | `string` | `"div"` | 自定义根元素标签;对应上游 `render` 的元素替换 |
| `aria-label` | `string` | - | 列表名称;省略且没有 `aria-labelledby` 时使用本地化默认名称 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
| 默认作用域插槽 | `({ color, isEmpty, isDisabled, isReadOnly, isFocused, layout }) => VNodeChild` | - | 根渲染状态 |
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ------------------------------------------------------------------------------- | ----------- | -------------------------------------------------------------- |
| `modelValue` | `string \| Color \| null` | - | 当前接受颜色(`v-model`;受控) |
| `value` | `string \| Color \| null` | - | 低优先级受控别名,与共享颜色模型一致 |
| `defaultValue` | `string \| Color \| null` | `"#000000"` | 非受控初值;未提供时使用固定源默认黑值,不会自动选中第一个候选 |
| `layout` | `"grid" \| "stack"` | `"grid"` | 布局方向(视觉 flex 布局,ARIA 方向固定为 vertical) |
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | swatch 尺寸 |
| `variant` | `"circle" \| "square"` | `"circle"` | swatch 形状 |
| `isDisabled` | `boolean` | `false` | 禁用整个选择器(库扩展) |
| `disabled` | `boolean` | `false` | `isDisabled` 别名 |
| `isReadOnly` | `boolean` | `false` | 只读:保留选择与焦点,阻止新的选择(库扩展) |
| `dir` | `"ltr" \| "rtl"` | - | 方向;影响水平方向键映射 |
| `as` | `string` | `"div"` | 自定义根元素标签;对应上游 `render` 的元素替换 |
| `aria-label` | `string` | - | 列表名称;省略且没有 `aria-labelledby` 时使用本地化默认名称 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
| 默认作用域插槽 | `({ color, isEmpty, isDisabled, isReadOnly, isFocused, layout }) => VNodeChild` | - | 根渲染状态 |
`change` 事件与 `update:modelValue` 一起在选择被接受时触发,参数为本库 `Color`,保留候选色自身的颜色空间与精度。选择比较使用固定源的 hexa 键(8 位 RGB + alpha):等价格式(hex/rgb/hsl)视为同一颜色,alpha 按 1/255 量化比较,灰色的色相在比较中折叠;接受值本身不会被反写或量化。
@@ -197,57 +197,57 @@ ColorSwatchPicker 组件使用以下 CSS 类([查看源码样式](https://gith
### ColorSwatchPicker.Item
| Prop | 类型 | 默认值 | 描述 |
| ------------ | -------------------------------- | ------ | -------------------------------------------------------- |
| `color` | `string \| Color \| null` | - | 候选颜色;省略或空字符串渲染透明色块(对应固定源 `#0000`) |
| `isDisabled` | `boolean` | `false` | 禁用该项(不可聚焦、不可选择、方向键跳过) |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| `aria-label` | `string` | - | 覆盖自动生成的项名称 |
| 默认作用域插槽 | `(state) => VNodeChild` | - | 项状态,见下方 Render Props |
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ------------------------- | ------- | ---------------------------------------------------------- |
| `color` | `string \| Color \| null` | - | 候选颜色;省略或空字符串渲染透明色块(对应固定源 `#0000`) |
| `isDisabled` | `boolean` | `false` | 禁用该项(不可聚焦、不可选择、方向键跳过) |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| `aria-label` | `string` | - | 覆盖自动生成的项名称 |
| 默认作用域插槽 | `(state) => VNodeChild` | - | 项状态,见下方 Render Props |
### ColorSwatchPicker.Swatch
| Prop | 类型 | 默认值 | 描述 |
| ----------- | ------------------------- | ------ | ------------------------------------------ |
| `color` | `string \| Color \| null` | - | 覆盖颜色;省略时使用所属项的颜色 |
| `colorName` | `string` | - | 颜色的可访问名称(覆盖自动生成的描述) |
| `as` | `string` | `"div"` | 自定义根元素标签 |
| Prop | 类型 | 默认值 | 描述 |
| ----------- | ------------------------- | ------- | -------------------------------------- |
| `color` | `string \| Color \| null` | - | 覆盖颜色;省略时使用所属项的颜色 |
| `colorName` | `string` | - | 颜色的可访问名称(覆盖自动生成的描述) |
| `as` | `string` | `"div"` | 自定义根元素标签 |
### ColorSwatchPicker.Indicator
| Prop | 类型 | 默认值 | 描述 |
| ---- | ---------------- | --------- | ------------------------ |
| `as` | `string` | `"span"` | 自定义根元素标签 |
| 默认作用域插槽 | `(state) => VNodeChild` | - | 替换默认勾选图标,接收项状态 |
| Prop | 类型 | 默认值 | 描述 |
| -------------- | ----------------------- | -------- | ---------------------------- |
| `as` | `string` | `"span"` | 自定义根元素标签 |
| 默认作用域插槽 | `(state) => VNodeChild` | - | 替换默认勾选图标,接收项状态 |
默认图标是固定源的勾选 SVG;`[data-light-color="true"]` 由色块相对亮度(> 0.5)决定,浅色背景使用黑色勾选。指示器始终渲染在 DOM 中,由 CSS 在选中时缩放显示。
### Render Props
| 插槽状态 | 类型 | 含义 |
| --------------------------------------------------- | --------- | -------------------------------------- |
| `color`(项) | `Color` | 该项的候选颜色 |
| `isSelected` / `isDisabled` / `isFocused` / `isFocusVisible` / `isPressed` / `isHovered` | `boolean` | 项的真实状态 |
| `color`(根) | `Color \| null` | 当前接受颜色 |
| `isEmpty` / `isDisabled` / `isReadOnly` / `isFocused` | `boolean` | 根的真实状态 |
| `layout`(根) | `"grid" \| "stack"` | 当前布局 |
| 插槽状态 | 类型 | 含义 |
| ---------------------------------------------------------------------------------------- | ------------------- | -------------- |
| `color`(项) | `Color` | 该项的候选颜色 |
| `isSelected` / `isDisabled` / `isFocused` / `isFocusVisible` / `isPressed` / `isHovered` | `boolean` | 项的真实状态 |
| `color`(根) | `Color \| null` | 当前接受颜色 |
| `isEmpty` / `isDisabled` / `isReadOnly` / `isFocused` | `boolean` | 根的真实状态 |
| `layout`(根) | `"grid" \| "stack"` | 当前布局 |
Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `focus()`(按入口规则聚焦项);Item 提供 `element`。不暴露颜色 owner、事务 token 或内部集合键。
### 选择与焦点
| 操作 | 行为 |
| ----------------------- | ----------------------------------------------------------------------- |
| 鼠标主键按下 | 选择该项;仅主键(`button === 0`)激活,右键/中键保留原生行为;可取消的 `mousedown`(`preventDefault`)会阻止选择 |
| `Enter` / `Space` | 选择当前聚焦项(按下即选中) |
| `Tab` / `Shift+Tab` | 整个列表是一个 tab 停靠点;进入时聚焦已选项或首/末可用项 |
| `↑` / `↓` | 只移动焦点不选择;grid 按几何在换行行间移动,stack 按顺序移动 |
| `←` / `→` | grid 按顺序移动(RTL 反向);stack 交给浏览器滚动 |
| `Home` / `End` | 聚焦首/末可用项 |
| `PageUp` / `PageDown` | 容器不可滚动时跳到首/末项,可滚动时按页移动 |
| `click`(`detail=0`) | 辅助技术/程序化的 click-only 激活选择当前项;正常鼠标/键盘的兼容 click 不重复提案 |
| 输入字符 | 按项名称前缀匹配并聚焦(名称差异见下) |
| 边界 | 不循环;到边界后保持当前项 |
| 操作 | 行为 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------- |
| 鼠标主键按下 | 选择该项;仅主键(`button === 0`)激活,右键/中键保留原生行为;可取消的 `mousedown`(`preventDefault`)会阻止选择 |
| `Enter` / `Space` | 选择当前聚焦项(按下即选中) |
| `Tab` / `Shift+Tab` | 整个列表是一个 tab 停靠点;进入时聚焦已选项或首/末可用项 |
| `↑` / `↓` | 只移动焦点不选择;grid 按几何在换行行间移动,stack 按顺序移动 |
| `←` / `→` | grid 按顺序移动(RTL 反向);stack 交给浏览器滚动 |
| `Home` / `End` | 聚焦首/末可用项 |
| `PageUp` / `PageDown` | 容器不可滚动时跳到首/末项,可滚动时按页移动 |
| `click`(`detail=0`) | 辅助技术/程序化的 click-only 激活选择当前项;正常鼠标/键盘的兼容 click 不重复提案 |
| 输入字符 | 按项名称前缀匹配并聚焦(名称差异见下) |
| 边界 | 不循环;到边界后保持当前项 |
焦点与选择分离:方向键只移动焦点,`aria-selected` 与指示器只反映接受颜色。父级拒绝提案后,选择样式、`aria-selected` 与 DOM 保持接受状态,同一手势可重试。窗口失焦或指针取消会清除按压状态与点击去重归属,恢复后可以立即重试。
@@ -265,4 +265,6 @@ Root 实例通过 `defineExpose` 提供 `element`(真实根 DOM)与 `focus()
## 相关组件
[ColorSwatch 颜色色块](./color-swatch) · [ColorField 颜色输入框](./color-field) · [ColorArea 颜色区域](./color-area)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+2
View File
@@ -152,4 +152,6 @@ ColorSwatch 组件使用以下 CSS 类([查看源码样式](https://github.com
## 相关组件
[ColorSwatchPicker 颜色色块选择器](./color-swatch-picker) · [ColorField 颜色输入框](./color-field) · [ColorArea 颜色区域](./color-area)
已公开 [ColorField 颜色输入框](/components/color-field)(含 ColorInputGroup)、[ColorArea 颜色区域](/components/color-area)、[ColorSlider 颜色滑块](/components/color-slider)、[ColorSwatch 颜色色块](/components/color-swatch)、[ColorSwatchPicker 颜色色块选择器](/components/color-swatch-picker) 与 [ColorPicker 颜色选择器](/components/color-picker)。颜色家族共用同一颜色 owner,Picker 的 Trigger/Popover 组合可嵌套上述任意子组件。
+7 -7
View File
@@ -213,12 +213,12 @@ DateField 使用 Vue 日期值、作用域插槽和共享字段协议。与固
#### Format Props
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------- | ------- | ----------------------------------------------------------- |
| `granularity` | `Granularity` | - | 显示的最小单位。日期默认为 `"day"`,时间默认为 `"minute"`。 |
| `hourCycle` | `12 \| 24` | - | 以 12 或 24 小时制显示时间;默认由语言环境决定。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区缩写。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------- | ------- | --------------------------------------------------------------------------- |
| `granularity` | `Granularity` | - | 显示的最小单位;未传时随值推断:纯日期默认 `"day"`,含时间默认 `"minute"`。 |
| `hourCycle` | `12 \| 24` | - | 以 12 或 24 小时制显示时间;默认由语言环境决定。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区缩写。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
#### State Props
@@ -464,7 +464,7 @@ DateFieldSuffix 接受标准 HTML `div` 属性:
## 相关组件
[TextField 文本输入框](./text-field) · [NumberField 数字输入框](./number-field) · [Select 选择器](./select)
[DatePicker 日期选择器](./date-picker) · [Calendar 日历](./calendar) · [Label 标签](./label)
## Vue 兼容说明
+12 -12
View File
@@ -187,7 +187,7 @@ DatePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态:
- **Open**:触发器上 `[data-open="true"]`
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。当前 `data-focus-visible` 在任何聚焦时置位(含鼠标点击聚焦),与键盘专属焦点环语义不完全一致;修复列入 HD 队列(HD-06-LINK-FOCUS)
- **Hover**:触发器上 `:hover`
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
- **Read only**:根容器上 `[data-readonly="true"]`
@@ -230,16 +230,16 @@ DatePicker 继承固定基线的日期字段与弹层能力,通过 Vue `v-mode
#### Format Props
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | ------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | `'day'` | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 Calendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 Calendar 翻页按可见范围或单步前进。 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | --------------------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 随值推断:纯日期 `day`、含时间 `minute` | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 Calendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 Calendar 翻页按可见范围或单步前进。 |
#### State & Form Props
@@ -313,7 +313,7 @@ DatePicker 继承固定基线的日期字段与弹层能力,通过 Vue `v-mode
## 相关组件
[Calendar 日历](./calendar) · [DateField 日期字段](./date-field) · [TimeField 时间字段](./time-field)
[Calendar 日历](./calendar) · [RangeCalendar 范围日历](./range-calendar) · [DateField 日期字段](./date-field)
## Vue 公共契约与差异
+12 -12
View File
@@ -199,7 +199,7 @@ DateRangePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态
- **Open**:触发器上 `[data-open="true"]`
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。当前 `data-focus-visible` 在任何聚焦时置位(含鼠标点击聚焦),与键盘专属焦点环语义不完全一致;修复列入 HD 队列(HD-06-LINK-FOCUS)
- **Hover**:触发器上 `:hover`
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
- **Read only**:根容器上 `[data-readonly="true"]`
@@ -244,16 +244,16 @@ DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹
#### Format Props
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | ------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 由接受值推断 | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 RangeCalendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 RangeCalendar 翻页按可见范围或单步前进。 |
| Prop | 类型 | 默认值 | 描述 |
| ------------------------- | ------------------------------------------------------------- | --------------------------------------- | ----------------------------------------------- |
| `granularity` | `'day' \| 'hour' \| 'minute' \| 'second'` | 随值推断:纯日期 `day`、含时间 `minute` | 显示的日期/时间粒度;只改变显示,不截断接受值。 |
| `hourCycle` | `12 \| 24` | 由 locale 决定 | 以 12 或 24 小时制显示时间。 |
| `hideTimeZone` | `boolean` | `false` | 是否隐藏时区名称。 |
| `shouldForceLeadingZeros` | `boolean` | - | 是否始终为月、日、小时等显示前导零。 |
| `locale` | `string` | ConfigProvider 或 `en-US` | 显示历法与格式。 |
| `dir` | `'ltr' \| 'rtl'` | ConfigProvider 或 `ltr` | 排列与方向键方向。 |
| `firstDayOfWeek` | `'sun' \| 'mon' \| 'tue' \| 'wed' \| 'thu' \| 'fri' \| 'sat'` | 由 locale 决定 | 覆盖内嵌 RangeCalendar 的一周起始日。 |
| `pageBehavior` | `'visible' \| 'single'` | `'visible'` | 内嵌 RangeCalendar 翻页按可见范围或单步前进。 |
#### State & Form Props
@@ -352,7 +352,7 @@ DateRangePicker 继承固定基线的双端点日期字段、范围日历与弹
## 相关组件
[DateField 日期字段](./date-field) · [RangeCalendar 范围日历](./range-calendar) · [DatePicker 日期选择器](./date-picker) · [TimeField 时间字段](./time-field)
[RangeCalendar 范围日历](./range-calendar) · [Calendar 日历](./calendar) · [DateField 日期字段](./date-field)
## Vue 公共契约与差异
+1 -1
View File
@@ -109,4 +109,4 @@ Description 组件通过以下方式增强无障碍性:
## 相关组件
[TextField 文本输入框](./text-field) · [Label 标签](./label) · [FieldError 字段错误](./field-error)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [TextArea 多行文本框](./textarea)
+3 -4
View File
@@ -33,7 +33,7 @@ import {
</template>
```
<ComponentPreview name="disclosure-group-basic" />
<ComponentPreview name="disclosure-group-basic" minHeight="580px" />
## 组件结构
@@ -57,7 +57,7 @@ import { Disclosure, DisclosureGroup } from "@heroui-vue/components";
可使用 `expandedKeys` 与 `update:expandedKeys` 配合 `useDisclosureGroupNavigation` 外部导航。
<ComponentPreview name="disclosure-group-controlled" />
<ComponentPreview name="disclosure-group-controlled" minHeight="580px" />
`useDisclosureGroupNavigation` 为公开 composable:提供 `currentIndex`、`isPrevDisabled`、`isNextDisabled`、`onPrevious`、`onNext`。单选替换集合,多选增量添加;不修改传入集合。
@@ -111,5 +111,4 @@ import { Disclosure, DisclosureGroup } from "@heroui-vue/components";
## 相关组件
- [Disclosure 折叠面板](./disclosure)
- [Accordion 手风琴](./accordion)
[Accordion 手风琴](./accordion) · [Disclosure 折叠面板](./disclosure) · [Button 按钮](./button)
+2 -3
View File
@@ -33,7 +33,7 @@ import {
</template>
```
<ComponentPreview name="disclosure-basic" />
<ComponentPreview name="disclosure-basic" minHeight="440px" />
## 组件结构
@@ -170,5 +170,4 @@ Body 提供基线内边距与内层包装。Indicator 默认为基线 Chevron
## 相关组件
- [DisclosureGroup 折叠面板组](./disclosure-group)
- [Accordion 手风琴](./accordion)
[Accordion 手风琴](./accordion) · [DisclosureGroup 折叠面板组](./disclosure-group) · [Button 按钮](./button)
+1 -2
View File
@@ -264,5 +264,4 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论。类名前缀 `hv-`。
## 相关组件
- [Modal 模态框](./modal)
- [AlertDialog 警告对话框](./alert-dialog)
[Modal 模态框](./modal) · [Button 按钮](./button) · [CloseButton 关闭按钮](./close-button)
+1 -3
View File
@@ -416,6 +416,4 @@ Dropdown 组件实现 ARIA 菜单模式,并提供:
## 相关组件
- [Button 按钮](./button)
- [Popover 弹出层](./popover)
- [Separator 分隔线](./separator)
[Button 按钮](./button) · [Popover 弹出框](./popover) · [Separator 分隔符](./separator)
+7 -9
View File
@@ -35,14 +35,10 @@ import { EmptyState } from "@heroui-vue/components";
默认插槽为空、仅包含注释或空白文本时,回退到源码默认文案 `No results found`。只要存在有效内容(文本、数字或元素),就渲染调用方内容,不额外包裹结构。
> 兼容说明:固定源的 React 实现用真值判断(`children || "No results found"`),数字 `0` 会回退默认文案、纯空白字符串原样渲染;本库把 `0` 视为有效内容照常渲染、纯空白回退默认文案。这是有意的 Vue 适配边界,两处与上游不同。
## 示例
### 默认回退
不提供内容时展示源码默认文案。
<ComponentPreview name="empty-state-default" />
### 自定义文案
<ComponentPreview name="empty-state-custom-content" />
@@ -53,14 +49,16 @@ import { EmptyState } from "@heroui-vue/components";
<ComponentPreview name="empty-state-conditional" />
### 自定义样式
### 集合为空
`class` 与 `$attrs` 合并到根元素,可叠加边框、背景、间距与对齐工具类。
把 `EmptyState` 放进集合组件的空槽(如 ListBox 的 `#empty`),作为搜索无结果或数据为空时的占位。过滤输入改变集合内容即可看到回退效果。
<ComponentPreview name="empty-state-custom-styles" />
<ComponentPreview name="empty-state-collection" />
## 自定义样式
`class` 与 `$attrs` 合并到根元素,可叠加边框、背景、间距与对齐工具类。
### Tailwind CSS
<ComponentPreview name="empty-state-custom-styles" />
+1 -1
View File
@@ -121,4 +121,4 @@ ErrorMessage 组件使用以下 CSS 类([查看源码样式](https://github.co
## 相关组件
[FieldError 字段错误](./field-error) · [Description 描述](./description) · [TagGroup 标签组](./tag-group)
[TagGroup 标签组](./tag-group)
+1 -1
View File
@@ -209,4 +209,4 @@ FieldError 组件通过以下方式确保无障碍性:
## 相关组件
[TextField 文本输入框](./text-field) · [Label 标签](./label) · [Description 描述](./description)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [TextArea 多行文本框](./textarea)
+1 -1
View File
@@ -127,4 +127,4 @@ Fieldset 不维护字段值或校验队列。请使用 Form + TextField / Search
## 相关组件
[TextField](./text-field) · [SearchField](./search-field) · [Input](./input)
[TextField 文本输入框](./text-field) · [Label 标签](./label) · [CheckboxGroup 复选框组](./checkbox-group)
+1 -1
View File
@@ -182,4 +182,4 @@ Form 与共享字段组件协作:
## 相关组件
[TextField](./text-field) · [Fieldset](./fieldset) · [FieldError](./field-error) · [Button](./button)
[Button 按钮](./button) · [Fieldset 字段组](./fieldset) · [TextField 文本输入框](./text-field)
+14 -8
View File
@@ -25,7 +25,7 @@ import { Header } from "@heroui-vue/components";
`Header` 是集合/分组标题部件,不是带 Logo、导航和用户菜单的应用顶栏。固定基线的 React Aria Components `Header` 渲染原生 `<header>` 元素(不是任意 heading 级别),常出现在 Dropdown、ListBox、ComboBox、Autocomplete 的分组中。
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。菜单 / ListBox 尚未迁移时,可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。在真实集合分组中,`Header` 自动充当分组标签:位于 `DropdownSection` / `MenuSection` 内时自动生成 id 并注册为分组的 `aria-labelledby` 目标(显式传入 `id` 时沿用并注册该 id,卸载时注销);位于 `ListBoxSection` 内时由分组扫描子节点取 `Header` 的 id 关联 `aria-labelledby`。脱离集合使用时它就是普通标题元素,也可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
<ComponentPreview name="header-semantic" />
@@ -46,6 +46,12 @@ import { Header } from "@heroui-vue/components";
## 示例
### 集合分组
在 `DropdownSection`(菜单分组)与 `ListBoxSection`(列表分组)中,`Header` 自动成为分组标签:菜单分组经注册表把 `Header` 的 id 关联到 `aria-labelledby`,列表分组扫描子节点取 `Header` 的 id 关联。查看示例 DOM 可见分组元素的 `aria-labelledby` 指向对应 `Header`。
<ComponentPreview name="header-collection-grouping" />
### 自定义 class
<ComponentPreview name="header-custom-class" />
@@ -82,16 +88,16 @@ import { Header } from "@heroui-vue/components";
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认插槽 | - | - | 标题内容 |
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。`id` 在 `MenuSection` / `DropdownSection` 内未显式传入时自动生成,并注册为该分组的 `aria-labelledby` 标签;其他场景不主动输出 id。
### 上游差异
| 上游 React 能力 | Vue 实现 |
| --------------------------- | ------------------------------------------ |
| `Header.Root` 对象子部件 | 独立具名导出 `Header` / `HeaderRoot` |
| RAC Collection 叶子节点 | 语义 HTML 封装;集合上下文由未来菜单族提供 |
| `className` / `children` | `class` / 默认插槽 |
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
| 上游 React 能力 | Vue 实现 |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| 具名导出 `Header`(无 `.Root` 对象子部件) | 具名导出 `Header` / `HeaderRoot`(同一实现) |
| RAC Collection 叶子节点(分组标题注册) | `MenuSection` 内自动注册 id 为分组标签;`ListBoxSection` 扫描子节点取 `Header` id 关联 `aria-labelledby` |
| `className` / `children` | `class` / 默认插槽 |
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
## 无障碍
+80 -1
View File
@@ -169,6 +169,85 @@ InputGroup 会自动反映父级 TextField 的无效状态。
<ComponentPreview name="input-group-with-textarea" />
### 用法示例
图标前缀加确认按钮后缀的完整组合:
```vue
<script setup lang="ts">
import { IconCheck, IconMail } from "@tabler/icons-vue";
import {
Button,
InputGroup,
InputGroupInput,
InputGroupPrefix,
InputGroupSuffix,
Label,
TextField,
} from "@heroui-vue/components";
</script>
<template>
<TextField>
<Label>邮箱</Label>
<InputGroup>
<InputGroupPrefix>
<IconMail class="size-4 text-muted" />
</InputGroupPrefix>
<InputGroupInput placeholder="name@email.com" />
<InputGroupSuffix>
<Button is-icon-only aria-label="确认" size="sm" variant="ghost">
<IconCheck class="size-4" />
</Button>
</InputGroupSuffix>
</InputGroup>
</TextField>
</template>
```
### 文本域用法示例
带字符计数与 500 字上限校验的反馈文本域:
```vue
<script setup lang="ts">
import { ref } from "vue";
import { IconMail } from "@tabler/icons-vue";
import {
Description,
FieldError,
InputGroup,
InputGroupPrefix,
InputGroupTextArea,
Label,
TextField,
} from "@heroui-vue/components";
const feedback = ref("");
</script>
<template>
<TextField full-width name="feedback" :is-invalid="feedback.length > 500">
<Label>你的反馈</Label>
<InputGroup full-width>
<InputGroupPrefix>
<IconMail class="size-4 text-muted" />
</InputGroupPrefix>
<InputGroupTextArea
v-model="feedback"
class="resize-none"
placeholder="分享你的想法、建议或问题……"
:rows="5"
/>
</InputGroup>
<Description class="flex w-full items-center justify-between px-1">
<span>最多 500 个字符。</span>
<span class="ms-auto">{{ feedback.length }}/500</span>
</Description>
<FieldError>反馈不能超过 500 个字符</FieldError>
</TextField>
</template>
```
## 自定义样式
### Tailwind CSS
@@ -294,4 +373,4 @@ InputGroup 会根据状态自动管理以下 data 属性:
## 相关组件
[Input 输入框](./input) · [Surface 表面](./surface) · [Button 按钮](./button)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [Label 标签](./label)
+71 -18
View File
@@ -51,7 +51,12 @@ import {
## 示例
### 尺寸变体
### 变体
InputOTP 组件支持两种视觉变体:
- **`primary`**(默认)- 标准样式带阴影,适用于大多数场景
- **`secondary`** - 低强调变体无阴影,适用于 Surface 组件内
<ComponentPreview name="input-otp-variants" />
@@ -103,23 +108,70 @@ import {
`inputClassName` 落在真实 `<input>` 上;视觉槽位用 `class` 落在 `InputOTPSlot` 根节点。二者不会合并到同一节点。
### 全局 CSS
可使用 `@layer components` 指令自定义 InputOTP 组件类;下面的类与状态选择器都来自当前样式表:
```css
@layer components {
.hv-input-otp {
@apply gap-3;
}
.hv-input-otp__slot {
@apply rounded-lg border-accent;
@apply size-12 rounded-xl border-2 font-bold;
}
.hv-input-otp__slot[data-active="true"] {
@apply border-accent ring-2 ring-accent/30;
}
.hv-input-otp__separator {
@apply h-1 w-2 rounded-full bg-border-strong;
}
}
```
## 样式参考
类名前缀为 `hv-`。
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
- `.hv-input-otp` / `.hv-input-otp--primary` / `.hv-input-otp--secondary`
- `.hv-input-otp__group` / `.hv-input-otp__slot` / `.hv-input-otp__slot-value`
- `.hv-input-otp__caret` / `.hv-input-otp__separator` / `.hv-input-otp__input`
### CSS 类
状态:`data-active`、`data-filled`、`data-disabled`、`data-invalid`、`data-complete`。
InputOTP 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/input-otp.css)):
#### 基础类 [!toc]
- `.hv-input-otp` - 基础容器
- `.hv-input-otp__group` - slot 组
- `.hv-input-otp__slot` - 单个输入 slot
- `.hv-input-otp__slot-value` - slot 内的字符
- `.hv-input-otp__caret` - 闪烁光标指示器
- `.hv-input-otp__separator` - 组之间的视觉分隔符
- `.hv-input-otp__input` - 真实 `<input>` 的透明覆盖层(Reka PinInput 多 input 底座的适配类,替代上游 `input-otp` 库的 `__container`)
#### 变体类 [!toc]
- `.hv-input-otp--primary` - 标准变体(默认)
- `.hv-input-otp--secondary` - 低强调变体
#### 状态类 [!toc]
- `.hv-input-otp__slot[data-active="true"]` - 当前激活的 slot
- `.hv-input-otp__slot[data-filled="true"]` - 含字符的 slot
- `.hv-input-otp__slot[data-disabled="true"]` - 禁用的 slot
- `.hv-input-otp__slot[data-invalid="true"]` - 无效的 slot
- `.hv-input-otp[data-disabled="true"]` / `[data-invalid="true"]` - 根容器的禁用与错误标记
### 交互状态
组件同时支持 CSS 伪类与 data 属性:
- **Hover**:slot 上 `:hover` 或 `[data-hovered="true"]`
- **Active**:slot 上 `[data-active="true"]`(当前聚焦)
- **Filled**:slot 上 `[data-filled="true"]`(含字符)
- **Disabled**:根与 slot 上 `[data-disabled="true"]`
- **Invalid**:根与 slot 上 `[data-invalid="true"]`(slot 另输出 `[data-readonly]`)
## API 参考
@@ -161,14 +213,17 @@ import {
### 上游差异
| 上游 React 能力 | Vue 实现 |
| ----------------------------- | ------------------------------------------ |
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
| `onComplete` 跨过长度阈值 | `complete` 仅在首次填满触发 |
| `pattern` 整串校验 | 单字符过滤(同样接受导出常量) |
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
| 上游 React 能力 | Vue 实现 |
| ------------------------------------ | ------------------------------------------------------------------------------------- |
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
| `onComplete` 跨过长度阈值 | `complete` 仅在首次填满触发 |
| `pattern` 整串校验 | 单字符过滤(同样接受导出常量) |
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
| `validationDetails`(ValidityState) | 未提供;校验结果为 `string \| string[]` 文本 |
| `textAlign` / `pasteTransformer` | 未提供(能力缺口,见 HD 队列后续能力卡) |
| `autoFocus` / `containerClassName` | 未提供专门 prop;`containerClassName` 被上游公共类型显式 Omit,`autoFocus` 属能力缺口 |
## 字段与表单
@@ -187,6 +242,4 @@ Slot 的 keydown/paste 用户处理器在底座编辑前的 capture 边界协调
## 相关组件
- [TextField 文本输入框](./text-field)
- [Label 标签](./label)
- [FieldError 字段错误](./field-error)
[Input 输入框](./input) · [Form 表单](./form) · [Surface 表面](./surface)
+3 -3
View File
@@ -16,7 +16,7 @@ import { Input } from "@heroui-vue/components";
<ComponentPreview name="input-basic" />
::: info 字段组合
校验、标签与错误消息由 TextField 体系负责。TextField 尚未迁移,当前请使用原生 label、aria-describedby 和 aria-invalid 关联。
校验、标签与错误消息请参阅 [TextField 文本字段](/components/text-field)。
:::
## 示例
@@ -91,8 +91,8 @@ Input 接受标准 HTML input 属性,以及以下 props:
`update:modelValue` 传递字符串;`@input` / `@change` 保留原生事件。`focus()` 可通过模板引用调用。原生表单 reset 还原非受控初始值;受控值由父组件管理。
不把 React 的 `value` + `onChange` 直接复制为 Vue 状态 API。`className` 改为 `class`。TextField 上下文的自动继承尚未实现。
不把 React 的 `value` + `onChange` 直接复制为 Vue 状态 API。`className` 改为 `class`。Input 作为 TextField 的控件自动接入其字段上下文(id、name、aria-describedby、禁用/只读/必填等状态继承)。
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
[TextField 文本输入框](./text-field) · [TextArea 多行文本框](./textarea) · [Label 标签](./label)
-4
View File
@@ -136,7 +136,3 @@ Kbd 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-
| | | `end` | |
上游文档表格曾写作 `Kbd.Key` 与 `title`/`children`;实际实现与全部演示使用 `KbdAbbr` 的 `keyValue` 与 `KbdContent`。本库按实现迁移,并同时导出 `kbdKeysMap`、`kbdKeysLabelMap` 与 `KbdKey` 类型。
## 相关组件
[Button 按钮](./button) · [Link 链接](./link)
+1 -1
View File
@@ -127,4 +127,4 @@ Label 基于原生 HTML `<label>`,并遵循 WAI-ARIA 最佳实践:
## 相关组件
[TextField 文本输入框](./text-field) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Fieldset 字段组](./fieldset)
+1 -1
View File
@@ -203,4 +203,4 @@ import { RouterLink } from "vue-router";
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
[Breadcrumbs 面包屑](./breadcrumbs)
+4
View File
@@ -234,3 +234,7 @@ Item 和 ItemIndicator 的默认插槽共享以下状态:
列表使用 role=listbox / option / group,支持单一 Tab 入口、方向键、Home/End、按视口移动的 PageUp/PageDown、Enter/Space、首字母搜索与 IME 避让。多选支持 Ctrl/Command+A 和 Shift 范围选择。横向导航遵循 dir,禁用项不可激活;只读项仍可聚焦。
node SSR 输出选中状态、名称和描述;虚拟列表首屏为滚动容器,挂载后按测量显示可见行。读屏、触屏和完整视觉比较的已验证范围见仓库验证报告,不声明已经完整兼容 React Aria。
## 相关组件
[Select 选择器](./select) · [ComboBox 组合框](./combo-box) · [Avatar 头像](./avatar)
-5
View File
@@ -187,8 +187,3 @@ Meter 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/
| `style` | `StyleValue` | - | 与计算宽度合并 |
渲染为 `div[data-slot="meter-fill"]`,宽度为 `percentage%`。
## 相关组件
- [ProgressBar 进度条](./progress-bar)
- [ProgressCircle 环形进度条](./progress-circle)
+1 -1
View File
@@ -304,4 +304,4 @@ ModalDialog 的 ARIA/DOM 事件落在实际 role=dialog 的节点。isDismissabl
## 相关组件
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
[Button 按钮](./button) · [Tooltip 工具提示](./tooltip) · [Select 选择器](./select)
+1 -3
View File
@@ -379,9 +379,7 @@ NumberFieldDecrementButton 支持原生 button 属性、事件、`isDisabled`
## 相关组件
- [Input 输入框](./input)
- [TextField 文本输入框](./text-field)
- [FieldError 字段错误](./field-error)
[Label 标签](./label) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
## Vue 适配说明
+1 -3
View File
@@ -291,6 +291,4 @@ Pagination 使用以下 CSS 类:
## 相关组件
- [Button 按钮](./button)
- [Breadcrumbs 面包屑](./breadcrumbs)
- [Separator 分隔符](./separator)
[Button 按钮](./button) · [Link 链接](./link)
+1 -1
View File
@@ -176,4 +176,4 @@ PopoverContent 的 isNonModal 默认 false,也可在 Popover Root 设置默认
## 相关组件
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
[Button 按钮](./button) · [Tooltip 工具提示](./tooltip) · [Select 选择器](./select)
-5
View File
@@ -199,8 +199,3 @@ ProgressBar 使用以下 CSS 类([查看源码样式](https://github.com/herou
| `style` | `StyleValue` | - | 与计算宽度合并 |
渲染为 `div[data-slot="progress-bar-fill"]`。确定进度时宽度为 `percentage%`;不确定进度时不设置宽度,由 CSS 动画驱动。
## 相关组件
- [ProgressCircle 环形进度条](./progress-circle)
- [Meter 计量条](./meter)
-5
View File
@@ -197,8 +197,3 @@ ProgressCircle 组件使用以下 CSS 类([查看源码样式](https://github.
| `class` | `string \| Array \| Object` | - | 合并到 `circle` |
渲染为 `circle[data-slot="progress-circle-fill-circle"]`。
## 相关组件
- [ProgressBar 进度条](./progress-bar)
- [Meter 计量条](./meter)
+14 -14
View File
@@ -207,7 +207,7 @@ RadioGroup 使用以下 CSS 类([查看源码样式](https://github.com/heroui
| `modelValue` | `string \| undefined` | 非受控 | 当前值,使用 v-model |
| `defaultValue` | `string \| undefined` | `undefined` | 非受控初始值副本 |
| `name` / `form` / `id` | `string` | - / - / 自动 | 统一原生提交键、表单归属及组 ID |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 组视觉样式;Checkbox 成员可显式覆盖 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 组视觉样式;Radio 成员可显式覆盖 |
| `isDisabled` / `disabled` | `boolean` | `false` | 合并 Fieldset 禁用,后代不能解除 |
| `isReadOnly` | `boolean` | `false` | 阻止成员点击、空格和方向键修改 |
| `isRequired` / `isInvalid` | `boolean` | `false` | 要求至少一项可用选择 / 错误展示 |
@@ -232,14 +232,14 @@ Radio 必须在 RadioGroup 中使用。不为未选中的 Radio 输出 data-sele
### 事件与暴露
| 接口 | 行为 |
| ------------------------------ | ---------------------------------------------------------------------- |
| `update:modelValue` / `change` | 发出新的数组或标量;不修改传入数组;父级拒绝后恢复所有原生 checked |
| `focus()` / `element` | 聚焦选中可用成员或首个可用成员;空组聚焦组根。element 是组 HTMLElement |
| 接口 | 行为 |
| ------------------------------ | ------------------------------------------------------------------------ |
| `update:modelValue` / `change` | 发出新的标量值(`string`);不修改传入值;父级拒绝后恢复所有原生 checked |
| `focus()` / `element` | 聚焦选中可用成员或首个可用成员;空组聚焦组根。element 是组 HTMLElement |
CheckboxGroup 按原生约定提交同名重复条目,通过 FormData.getAll(name) 获取;RadioGroup 只提交一个选中可用值。未指定 name 不产生提交值。每个成员 value 必须唯一;重复或动态改成重复值会抛出明确错误。不为移除的选择自动选择别的成员;模型保留调用者的值,FormData 只包含实际存在的可用成员。
RadioGroup 按原生约定只提交一个选中可用值,通过 FormData.get(name) 获取;不同于 CheckboxGroup 的同名重复条目。未指定 name 不产生提交值。每个成员 value 必须唯一;重复或动态改成重复值会抛出明确错误。不为移除的选择自动选择别的成员;模型保留调用者的值,FormData 只包含实际存在的可用成员。
required 检查整个组,不能让每个 Checkbox 都变成必选;native 无效提交聚焦第一个可用成员,空组聚焦根。只读保留提交值并跳过必填/自定义约束。reset 尊重 preventDefault,受控值不覆盖,非受控恢复初始副本。动态 name/form 会更新提交和 reset 归属。
required 检查整个组,不能让每个 Radio 都变成必选;native 无效提交聚焦第一个可用成员,空组聚焦根。只读保留提交值并跳过必填/自定义约束。reset 尊重 preventDefault,受控值不覆盖,非受控恢复初始副本。动态 name/form 会更新提交和 reset 归属。
Label 在组中渲染 span 并注册 aria-labelledby;不要手写 for 指向组 div。每个成员独立隔离 Description/FieldError,同时合并组描述和当前组错误。后端错误使用 Form.validationErrors 按 name 映射,编辑后忽略当前响应,新对象可恢复错误。暂不提供异步 validate 或完整 validationDetails。
@@ -251,15 +251,15 @@ Label 在组中渲染 span 并注册 aria-labelledby;不要手写 for 指向
| Control | span,默认插槽 | class/style/DOM 属性与事件 |
| Indicator | span,默认作用域插槽 | 装饰 aria-hidden;自定义内容替换基线指示器 |
具名导出使用 RadioContent、RadioControl、RadioIndicator;不使用 React 对象式子部件。class 均支持字符串、数组和对象。默认图形精确来自基线,文档自定义图标使用 Tabler。Content 输出 selected/indeterminate/hovered/pressed/focus-visible 状态标记供定制样式使用。
具名导出使用 RadioContent、RadioControl、RadioIndicator;不使用 React 对象式子部件。class 均支持字符串、数组和对象。默认图形精确来自基线,文档自定义图标使用 Tabler。Content 输出 selected/hovered/pressed/focus-visible 状态标记供定制样式使用(indeterminate 状态标记仅 Checkbox 输出)。
### 作用域插槽状态
| 参数 | 类型 | 说明 |
| ---------------------------------------------------------- | --------- | ------------------------------ |
| `isSelected` / `isIndeterminate` | `boolean` | 选中 / 半选(半选仅 Checkbox) |
| `isDisabled` / `isReadOnly` / `isRequired` / `isInvalid` | `boolean` | 当前状态 |
| `isHovered` / `isPressed` / `isFocused` / `isFocusVisible` | `boolean` | 单成员交互状态 |
| 参数 | 类型 | 说明 |
| ---------------------------------------------------------- | --------- | -------------------------------------------------- |
| `isSelected` / `isIndeterminate` | `boolean` | 选中 / 半选(Radio 的 isIndeterminate 恒为 false) |
| `isDisabled` / `isReadOnly` / `isRequired` / `isInvalid` | `boolean` | 当前状态 |
| `isHovered` / `isPressed` / `isFocused` / `isFocusVisible` | `boolean` | 单成员交互状态 |
组作用域提供 value、validationErrors、isDisabled/isReadOnly/isRequired/isInvalid,以及 state.value/state.setValue;单成员另提供 state.isSelected/state.setSelected/state.toggle。不把组值和单成员状态混用。
@@ -269,4 +269,4 @@ render 自定义根类型未支持;基线 div+data-custom 示例以 Vue 根属
## 相关组件
[Checkbox](./checkbox) · [CheckboxGroup](./checkbox-group) · [RadioGroup](./radio-group) · [Fieldset](./fieldset)
[Fieldset 字段组](./fieldset) · [Surface 表面](./surface) · [Description 描述](./description)
+7 -7
View File
@@ -270,12 +270,12 @@ RangeCalendar 保留固定基线的主要属性,通过 Vue 模型、具名部
年份选择器复用公共 CalendarYearPicker 部件,支持以下格式化属性。
| 组件 | 属性 | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------------------------- |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标题(如 `{month: 'short'}`)。 |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局)。 |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法系统等)。 |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 跨度或 `20` | 滑动窗口中显示的年份数量。当同时设置 `minValue` 与 `maxValue` 时,默认为二者之间的完整范围。 |
| 组件 | 属性 | 类型 | 默认值 | 描述 |
| ---------------------------------- | -------------- | ---------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CalendarYearPickerTriggerHeading` | `format` | `Intl.DateTimeFormatOptions` | - | 自定义月/年标题(如 `{month: 'short'}`)。 |
| `CalendarYearPickerTriggerHeading` | `offset` | `{months?: number}` | - | 相对聚焦日期偏移标题(多月布局)。 |
| `CalendarYearPickerGrid` | `format` | `Intl.DateTimeFormatOptions` | `{year: 'numeric'}` | 自定义年份单元格标签(纪元、历法系统等)。 |
| `CalendarYearPickerGrid` | `visibleYears` | `number` | min–max 完整范围 | 滑动窗口中显示的年份数量;缺省显示 min–max 完整范围(未设约束时为 1900–2099),传入数字时以焦点年为中心。上游文档写“或 `20`”,本实现没有该回退分支 |
### RangeCalendarCell 作用域插槽
@@ -303,7 +303,7 @@ RangeCalendar 保留固定基线的主要属性,通过 Vue 模型、具名部
## 相关组件
[Calendar 日历](./calendar) · [DateField 日期字段](./date-field) · [TimeField 时间字段](./time-field)
[Calendar 日历](./calendar) · [DateField 日期字段](./date-field) · [DatePicker 日期选择器](./date-picker)
## Vue 公共契约与差异
-4
View File
@@ -160,7 +160,3 @@ const { attributes } = useScrollShadow({ containerRef: element });
</div>
</template>
```
## 相关组件
[ScrollShadow 滚动阴影](./scroll-shadow) · [Tabs 标签页](./tabs)
+1 -1
View File
@@ -269,4 +269,4 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
## 相关组件
[TextField](./text-field) · [InputGroup](./input-group) · [FieldError](./field-error)
[Label 标签](./label) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
+1 -1
View File
@@ -345,4 +345,4 @@ Select 组件使用以下 CSS 类([查看源码样式](https://github.com/hero
## 相关组件
[ListBox](/components/list-box)、[Popover](/components/popover)、[Fieldset](/components/fieldset)、[Label](/components/label)、[FieldError](/components/field-error)
[ListBox 列表框](./list-box) · [Popover 弹出框](./popover) · [Label 标签](./label)
+1 -1
View File
@@ -102,4 +102,4 @@ Separator 使用以下 CSS 类([查看源码样式](https://github.com/heroui-
## 相关组件
[Surface 表面](./surface) · [Card 卡片](./card)
[Card 卡片](./card) · [Chip 标签](./chip) · [Avatar 头像](./avatar)
+1 -1
View File
@@ -182,4 +182,4 @@ Skeleton 支持三种动画类型,视觉效果各不相同:
## 相关组件
[Card 卡片](./card) · [Spinner 加载指示器](./spinner)
[Card 卡片](./card) · [Avatar 头像](./avatar)
+4
View File
@@ -233,3 +233,7 @@ React 的 `render` 通过 Vue 的 `as`、属性绑定和插槽表达。
- 尊重 reduced-motion;数据和 ARIA 首屏可直接 SSR。完整读屏、触屏设备和 Nuxt 验收状态见验证报告。
实现差异:Reka 2.11 的 Collection Thumb 无法在服务端提供显式索引,也没有单项禁用;本组件采用原生输入与轨道局部指针适配,未引入第二套底座库。来源是固定版本英文正文和中文演示,完整差异与验证见仓库的 SLIDER-01 报告。
## 相关组件
[Label 标签](./label) · [Form 表单](./form) · [Description 描述](./description)
-4
View File
@@ -88,7 +88,3 @@ Spinner 使用以下 CSS 类:
| `class` | `string` | - | 额外的 CSS 类名 |
根节点默认 `role="status"` 与 `aria-label="Loading"`,可通过 attrs 覆盖。内部 SVG 标记 `aria-hidden`,使用 `currentColor` 渐变;嵌入 Button 时保持所选尺寸(如 `size="sm"` 为 16px),不被 Button 的普通 SVG 规则覆盖。
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
+1 -1
View File
@@ -104,4 +104,4 @@ const surface = inject(surfaceContextKey, undefined);
## 相关组件
[Card 卡片](./card) · [Input 输入框](./input) · [Button 按钮](./button)
[CheckboxGroup 复选框组](./checkbox-group) · [Fieldset 字段组](./fieldset) · [InputOTP 验证码输入](./input-otp)
+82 -5
View File
@@ -29,7 +29,11 @@ import {
```vue
<Switch>
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
<SwitchControl>
<SwitchThumb>
<SwitchIcon /> <!-- 可选:滑块内图标 -->
</SwitchThumb>
</SwitchControl>
启用通知
</SwitchContent>
<Description>允许接收通知</Description>
@@ -38,6 +42,25 @@ import {
请把 SwitchControl 与标签文本放入 SwitchContent;Description 作为其兄弟节点。Vue 底座使用原生 button 承载 role="switch",不是 React Aria 的 label 结构。
要对多个 Switch 进行分组,请使用 `SwitchGroup` 组件:
```vue
<SwitchGroup>
<Switch v-model:checked="option1">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
选项一
</SwitchContent>
</Switch>
<Switch v-model:checked="option2">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
选项二
</SwitchContent>
</Switch>
</SwitchGroup>
```
## 示例
### 尺寸
@@ -104,17 +127,71 @@ Vue 使用 `asChild` 合并根容器属性,默认插槽必须只有一个自
### 全局 CSS
若要自定义组件类,可使用 `@layer components` 指令;下面的类名与状态选择器都来自当前样式表:
```css
@layer components {
.hv-switch {
@apply inline-flex items-center gap-3;
}
.hv-switch__control {
border-radius: 12px;
@apply h-5 w-8 bg-gray-400 data-[selected=true]:bg-blue-500;
}
.hv-switch__thumb {
@apply bg-white shadow-sm;
}
.hv-switch__content {
@apply flex flex-col gap-1;
}
.hv-switch__icon {
@apply h-3 w-3 text-current;
}
}
```
## 样式参考
保留字段根容器、Content、Control、Thumb、Icon 的组合结构和 data-slot;类名前缀为 `hv-`。选中状态使用 `data-selected="true"`,禁用使用 `data-disabled="true"`。尺寸与滑块比例移植自基线 CSS。
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
### CSS 类
#### Switch 类 [!toc]
Switch 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/switch.css)):
- `.hv-switch` - Switch 根容器(字段)
- `.hv-switch__content` - 包裹控件与标签文本的可点击 label
- `.hv-switch__control` - Switch 轨道
- `.hv-switch__thumb` - 可移动的滑块
- `.hv-switch__icon` - 滑块内可选图标
- `.hv-switch--sm` - 小尺寸变体
- `.hv-switch--md` - 中尺寸变体(默认)
- `.hv-switch--lg` - 大尺寸变体
#### SwitchGroup 类 [!toc]
SwitchGroup 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/switch-group.css)):
- `.hv-switch-group` - Switch 组容器
- `.hv-switch-group__items` - Switch 项容器
- `.hv-switch-group--horizontal` - 横向布局
- `.hv-switch-group--vertical` - 纵向布局(默认)
### 交互状态
该 Switch 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制:
- **已选中**:根上 `[data-selected="true"]` 或 `[aria-checked="true"]`(滑块位置与背景色变化)
- **悬停**:`:hover` 或 SwitchContent 上 `[data-hovered="true"]`(作用于 Control 轨道)
- **聚焦**:`:focus-visible` 或 SwitchContent 上 `[data-focus-visible="true"]`(在轨道上显示焦点环)
- **禁用**:根上 `[data-disabled="true"]`(降低透明度,包括帮助文本)
- **按压**:`:active` 或 SwitchContent 上 `[data-pressed="true"]`
只读与错误另有根上 `[data-readonly]`、`[data-invalid]` 标记。选中且禁用的组合配色由 `[data-selected="true"][data-disabled="true"]` 等复合规则提供。
## API 参考
@@ -172,8 +249,8 @@ SwitchGroup 是布局容器,每个 Switch 独立维护值;请提供 aria-lab
### 当前差异
`disabled` / `required` / `defaultChecked` 作为兼容别名保留。`change` 事件传递 boolean;React Aria 的 PressEvent 仍不等价于 DOM click。根组件的 class/style/data-* 作用于字段容器,ARIA 与 DOM 事件作用于 Content 按钮;Content 上的显式属性可覆盖默认透传。`asChild` 替代 React render prop。FieldError 当前仅接入 Switch 字段,尚未提供完整 TextField / Form 体系。
`disabled` / `required` / `defaultChecked` 作为兼容别名保留。`change` 事件传递 boolean;React Aria 的 PressEvent 仍不等价于 DOM click。根组件的 class/style/data-* 作用于字段容器,ARIA 与 DOM 事件作用于 Content 按钮;Content 上的显式属性可覆盖默认透传。`asChild` 替代 React render prop。Label / Description / FieldError 通过共享字段上下文接入 Switch;Form 的 `validationErrors` 按 name 映射、reset 与 `validationBehavior` 继承均已接入。
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
[Label 标签](./label) · [Description 描述](./description) · [Button 按钮](./button)
+1 -2
View File
@@ -338,5 +338,4 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
## 相关组件
- [Pagination 分页](./pagination)
- [Button 按钮](./button)
[Pagination 分页](./pagination) · [Checkbox 复选框](./checkbox) · [Chip 标签](./chip)
+17 -9
View File
@@ -13,7 +13,8 @@ group: 组件
import { Tabs } from "@heroui-vue/components";
```
<ComponentPreview name="tabs-basic" />
<ComponentPreview
isBgSolid name="tabs-basic" />
## 组件结构
@@ -54,37 +55,44 @@ import {
### 垂直布局
<ComponentPreview name="tabs-vertical" />
<ComponentPreview
isBgSolid name="tabs-vertical" />
### 溢出
当标签列表超出可用空间时,`TabsListContainer` 会自动渲染滚动箭头与渐隐边缘,使用户可以导航到被隐藏的标签。水平与垂直方向均支持此行为。
<ComponentPreview name="tabs-overflow" />
<ComponentPreview
isBgSolid name="tabs-overflow" />
### 禁用 Tab
<ComponentPreview name="tabs-disabled" />
<ComponentPreview
isBgSolid name="tabs-disabled" />
### 带分隔线
在每个 `<TabsTab>` 内(第一项除外)添加 `<TabsSeparator />`,用于在标签之间显示分隔线。
<ComponentPreview name="tabs-with-separator" />
<ComponentPreview
isBgSolid name="tabs-with-separator" />
### 次要类型
<ComponentPreview name="tabs-secondary" />
<ComponentPreview
isBgSolid name="tabs-secondary" />
### 次要类型(垂直)
<ComponentPreview name="tabs-secondary-vertical" />
<ComponentPreview
isBgSolid name="tabs-secondary-vertical" />
### 对齐方式
标签内容默认居中。使用 `align` 可将其对齐到 `start` 或 `end`,这在垂直的侧边栏式导航中尤其有用。单个标签仍可通过 `TabsTab` 上的 `class` 覆盖。
<ComponentPreview name="tabs-vertical-alignment" />
<ComponentPreview
isBgSolid name="tabs-vertical-alignment" />
### 渲染函数
@@ -237,4 +245,4 @@ RAC 的集合 render-prop API 不作逐字复制,列表用 v-for,DOM render
## 相关组件
[ScrollShadow 滚动阴影](./scroll-shadow) · [Tabs 标签页](./tabs)
[Breadcrumbs 面包屑](./breadcrumbs)
+1 -1
View File
@@ -282,4 +282,4 @@ TagGroup 组件使用以下 CSS 类([查看源码样式](https://github.com/he
## 相关组件
[Chip 标签](./chip) · [Description 描述](./description) · [ErrorMessage 错误消息](./error-message) · [Label 标签](./label)
[Label 标签](./label) · [Description 描述](./description) · [ErrorMessage 错误消息](./error-message)
+1 -1
View File
@@ -236,4 +236,4 @@ const hasError = ref(false);
## 相关组件
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Label 标签](./label) · [FieldError 字段错误](./field-error)
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Fieldset 字段组](./fieldset)
+1 -1
View File
@@ -125,4 +125,4 @@ TextArea 接受所有标准 HTML `<textarea>` 属性,以及以下属性:
## 相关组件
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [InputGroup 输入框组](./input-group)
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [Label 标签](./label)
+1 -1
View File
@@ -442,7 +442,7 @@ TimeFieldSuffix 接受标准 HTML `div` 属性:
## 相关组件
[DateField](/components/date-field) · [Calendar](/components/calendar)
[Label 标签](./label) · [FieldError 字段错误](./field-error) · [Description 描述](./description)
## Vue 兼容说明
+1 -2
View File
@@ -351,5 +351,4 @@ React 对象部件改具名导出,ReactNode 改 VNodeChild,onPress 改 DOM c
## 相关组件
- [Button 按钮](./button)
- [Spinner 加载指示器](./spinner)
[Button 按钮](./button) · [Alert 警告](./alert) · [CloseButton 关闭按钮](./close-button)
+1 -4
View File
@@ -173,7 +173,4 @@ ToggleButtonGroup 组件使用以下 CSS 类:
## 相关组件
- [ToggleButton 切换按钮](./toggle-button)
- [ButtonGroup 按钮组](./button-group)
- [CheckboxGroup 复选框组](./checkbox-group)
- [RadioGroup 单选框组](./radio-group)
[ToggleButton 切换按钮](./toggle-button) · [ButtonGroup 按钮组](./button-group) · [Button 按钮](./button)
+2 -4
View File
@@ -93,7 +93,7 @@ ToggleButton 组件使用以下 CSS 类:
- **悬停**`:hover` 或 `[data-hovered="true"]`
- **激活/按下**:`:active` 或 `[data-pressed="true"]`(包含缩放变换)
- **聚焦**:`:focus-visible` 或 `[data-focus-visible="true"]`(显示焦点环)
- **禁用**:`:disabled` 或 `[data-disabled="true"]`(降低透明度,禁用指针事件)
- **禁用**:`:disabled` 或 `[aria-disabled="true"]`(降低透明度,禁用指针事件;组件同时输出 `[data-disabled="true"]` 标记,但基线样式选择器是前两者)
## API 参考
@@ -134,6 +134,4 @@ ToggleButton 组件使用以下 CSS 类:
## 相关组件
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
- [ButtonGroup 按钮组](./button-group)
- [Switch 开关](./switch)
[Button 按钮](./button) · [Switch 开关](./switch) · [Checkbox 复选框](./checkbox)
+1 -4
View File
@@ -92,7 +92,4 @@ Toolbar 使用以下 CSS 类:
## 相关组件
- [ButtonGroup 按钮组](./button-group)
- [ToggleButtonGroup 切换按钮组](./toggle-button-group)
- [Separator 分隔符](./separator)
- [Tabs 标签页](./tabs)
[ButtonGroup 按钮组](./button-group) · [ToggleButtonGroup 切换按钮组](./toggle-button-group) · [Separator 分隔符](./separator)
+1 -1
View File
@@ -178,4 +178,4 @@ showArrow 选择带箭头的默认偏移(7px,否则 3px),仍需显式放
## 相关组件
[Modal 模态框](./modal) · [Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip)
[Button 按钮](./button) · [Popover 弹出框](./popover)
-4
View File
@@ -187,7 +187,3 @@ Typography 组件使用以下 CSS 类([查看源码样式](https://github.com/
| 默认插槽 | - | - | 常规 HTML 富文本内容。 |
`TypographyProse` 固定渲染 `div`,内部标题、段落、列表、引用、代码块、链接、图片等使用基线排版规则。`$attrs` 透传至该 `div`。
## 相关组件
[Card 卡片](./card) · [Kbd 键盘按键](./kbd)
@@ -0,0 +1,47 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import {
EmptyState,
Input,
Label,
ListBox,
ListBoxItem,
} from "@heroui-vue/components";
const query = ref("");
const files = [
{ id: "design", textValue: "设计规范" },
{ id: "budget", textValue: "预算表" },
{ id: "report", textValue: "季度报告" },
];
const items = computed(() => {
const keyword = query.value.trim();
return keyword
? files.filter((item) => item.textValue.includes(keyword))
: files;
});
</script>
<template>
<div class="flex w-[240px] flex-col gap-2">
<Label for="empty-state-collection-search">搜索文件</Label>
<Input
id="empty-state-collection-search"
v-model="query"
placeholder="输入关键词过滤"
/>
<ListBox
:items="items"
aria-label="文件列表"
class="rounded-3xl p-2 shadow-surface"
selection-mode="none"
>
<template #default="{ item }">
<ListBoxItem :id="item.id" :text-value="item.textValue">
{{ item.textValue }}
</ListBoxItem>
</template>
<template #empty>
<EmptyState>没有匹配的文件。</EmptyState>
</template>
</ListBox>
</div>
</template>
@@ -0,0 +1,95 @@
<script setup lang="ts">
import {
Button,
DropdownItem,
DropdownMenu,
DropdownPopover,
DropdownRoot,
DropdownSection,
DropdownTrigger,
Header,
ListBox,
ListBoxItem,
ListBoxSection,
} from "@heroui-vue/components";
const viewItems = [
{ id: "grid", label: "网格" },
{ id: "list", label: "列表" },
{ id: "detail", label: "详情" },
];
const sortItems = [
{ id: "name", label: "按名称" },
{ id: "date", label: "按日期" },
];
const todayItems = [
{ id: "standup", label: "站会纪要" },
{ id: "review", label: "代码评审" },
];
const weekItems = [
{ id: "plan", label: "周计划" },
{ id: "retro", label: "周回顾" },
];
</script>
<template>
<div class="flex flex-wrap items-start justify-center gap-8">
<DropdownRoot>
<DropdownTrigger>
<Button variant="secondary">视图设置</Button>
</DropdownTrigger>
<DropdownPopover>
<DropdownMenu aria-label="视图设置" class="min-w-[160px]">
<DropdownSection>
<Header>视图</Header>
<DropdownItem
v-for="item in viewItems"
:id="item.id"
:key="item.id"
:text-value="item.label"
>
{{ item.label }}
</DropdownItem>
</DropdownSection>
<DropdownSection>
<Header>排序</Header>
<DropdownItem
v-for="item in sortItems"
:id="item.id"
:key="item.id"
:text-value="item.label"
>
{{ item.label }}
</DropdownItem>
</DropdownSection>
</DropdownMenu>
</DropdownPopover>
</DropdownRoot>
<ListBox
aria-label="会议记录"
class="w-[180px] rounded-3xl p-2 shadow-surface"
selection-mode="none"
>
<ListBoxSection>
<Header>今天</Header>
<ListBoxItem
v-for="item in todayItems"
:id="item.id"
:key="item.id"
:text-value="item.label"
>
{{ item.label }}
</ListBoxItem>
</ListBoxSection>
<ListBoxSection>
<Header>本周</Header>
<ListBoxItem
v-for="item in weekItems"
:id="item.id"
:key="item.id"
:text-value="item.label"
>
{{ item.label }}
</ListBoxItem>
</ListBoxSection>
</ListBox>
</div>
</template>