diff --git a/apps/docs/.vitepress/theme/Layout.vue b/apps/docs/.vitepress/theme/Layout.vue index 28f20de..bc6250d 100644 --- a/apps/docs/.vitepress/theme/Layout.vue +++ b/apps/docs/.vitepress/theme/Layout.vue @@ -53,15 +53,20 @@ const groups = [ { title: "Card 卡片", url: "/components/card" }, { title: "Chip 标签", url: "/components/chip" }, { title: "CloseButton 关闭按钮", url: "/components/close-button" }, + { title: "Description 描述", url: "/components/description" }, + { title: "FieldError 字段错误", url: "/components/field-error" }, { title: "Input 输入框", url: "/components/input" }, { title: "InputGroup 输入框组", url: "/components/input-group" }, { title: "Kbd 键盘按键", url: "/components/kbd" }, + { title: "Label 标签", url: "/components/label" }, { title: "Link 链接", url: "/components/link" }, { title: "Separator 分隔符", url: "/components/separator" }, { title: "Skeleton 骨架屏", url: "/components/skeleton" }, { title: "Spinner 加载指示器", url: "/components/spinner" }, { title: "Surface 表面", url: "/components/surface" }, { title: "Switch 开关", url: "/components/switch" }, + { title: "TextArea 多行文本框", url: "/components/textarea" }, + { title: "TextField 文本输入框", url: "/components/text-field" }, ], }, ]; diff --git a/apps/docs/components.md b/apps/docs/components.md index 8d81b81..e82ea3f 100644 --- a/apps/docs/components.md +++ b/apps/docs/components.md @@ -11,12 +11,17 @@ description: 已迁移组件及文档 - [Card 卡片](./components/card) - [Chip 标签](./components/chip) - [CloseButton 关闭按钮](./components/close-button) +- [Description 描述](./components/description) +- [FieldError 字段错误](./components/field-error) - [Input 输入框](./components/input) - [InputGroup 输入框组](./components/input-group) - [Kbd 键盘按键](./components/kbd) +- [Label 标签](./components/label) - [Link 链接](./components/link) - [Separator 分隔符](./components/separator) - [Skeleton 骨架屏](./components/skeleton) - [Spinner 加载指示器](./components/spinner) - [Surface 表面](./components/surface) - [Switch 开关](./components/switch) +- [TextArea 多行文本框](./components/textarea) +- [TextField 文本输入框](./components/text-field) diff --git a/apps/docs/components/description.md b/apps/docs/components/description.md new file mode 100644 index 0000000..b001c6d --- /dev/null +++ b/apps/docs/components/description.md @@ -0,0 +1,112 @@ +--- +title: Description 描述 +description: 为表单字段及其他组件提供补充说明文本 +component: description +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 示例 + +### 搭配表单字段 + +```vue + + + +``` + +### 与 TextField 配合 + +```vue + + + +``` + +使用 [TextField](/components/text-field) 时,`aria-describedby` 会自动合并到控件;支持多个描述与动态 id。 + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +可使用 `@layer components` 指令自定义 Description 组件类。 + +```css +@layer components { + .hv-description { + @apply text-muted; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +Description 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/description.css)): + +#### 基础类 [!toc] + +- `.hv-description` - 基础描述样式,使用 `muted` 文本颜色 + +## API 参考 + +### Description + +| Prop | 类型 | 默认值 | 描述 | +| -------- | --------------------------- | ------ | --------------------------------- | +| `id` | `string` | 自动 | 显式 id;未指定时生成并与控件关联 | +| 默认插槽 | `Component` | - | 描述内容 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +## 无障碍 + +Description 组件通过以下方式增强无障碍性: + +- 使用屏幕阅读器可识别的语义化 HTML(`p`) +- 在 TextField 内自动注册到控件的 `aria-describedby` +- 支持多个描述、外部 `aria-describedby` 合并与卸载清理 + +任意用户 Vue 包装组件不能被 TextField 静态展开做 SSR 预规划;需要首屏 SSR 关联时请显式设置控件 `aria-describedby` 与描述 id。 + +## 相关组件 + +[TextField 文本输入框](./text-field) · [Label 标签](./label) · [FieldError 字段错误](./field-error) diff --git a/apps/docs/components/field-error.md b/apps/docs/components/field-error.md new file mode 100644 index 0000000..d5b5ed9 --- /dev/null +++ b/apps/docs/components/field-error.md @@ -0,0 +1,212 @@ +--- +title: FieldError 字段错误 +description: 展示表单字段校验错误消息 +component: field-error +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +FieldError 组件展示表单字段的校验错误消息。当父字段标记为无效时自动显示,并提供平滑的透明度过渡。 + +## 示例 + +### 基础校验 + +```vue + + + +``` + +### 动态错误信息 + +使用 **FieldError** 作用域插槽读取当前字段错误。`is-invalid` 只负责展示;阻止提交请使用 `validate` 或 Form 的 `validation-errors`。下面示例用 `validate` + `validation-behavior="aria"`,输入时即可看到动态消息: + +```vue + + + +``` + +上游 `FieldError` 的 render 函数 `(validation) => …` 在 Vue 中为 **FieldError** 的作用域插槽 `#default="{ validationErrors, isInvalid }"`。当前未提供完整 React Aria `validationDetails` 对象。 + +### 自定义校验逻辑 + +```vue + + + +``` + +也可以用 `validate` 做同步提交拦截: + +```vue + + + + + +``` + +### 多条错误信息 + +默认插槽展示合并后的错误文本;需要逐条渲染时使用 FieldError 作用域插槽。下面示例的 `validate` 会返回多条错误: + +```vue + + + +``` + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +可使用 `@layer components` 指令自定义 FieldError 组件类。 + +```css +@layer components { + .hv-field-error { + @apply font-medium text-danger; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +FieldError 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/field-error.css)): + +#### 基础类 [!toc] + +- `.hv-field-error` - 基础错误样式,danger 色 +- 仅在存在 `data-visible` 属性时显示 +- 长消息自动换行(`wrap-break-word`) + +## API 参考 + +### FieldError + +| Prop | 类型 | 默认值 | 描述 | +| -------- | --------------------------- | ------ | ---------------------------------------------------- | +| `id` | `string` | 自动 | 显式 id;未指定时生成并关联到控件 `aria-describedby` | +| 默认插槽 | `Component` | - | 错误消息;作用域提供 `validationErrors`、`isInvalid` | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +字段无效时渲染;默认展示错误数组(空格连接)。在 Switch 等 toggle 字段内也可使用。 + +## 无障碍 + +FieldError 组件通过以下方式确保无障碍性: + +- 使用 `role="alert"` 播报错误 +- 语义化 HTML 支持屏幕阅读器 +- 提供视觉与程序化错误指示(`aria-describedby` 关联) +- 根据校验状态自动管理可见性 + +当前不提供完整 React Aria `validationDetails` 对象;第三方契约请勿据此宣称完全兼容。 + +## 相关组件 + +[TextField 文本输入框](./text-field) · [Label 标签](./label) · [Description 描述](./description) diff --git a/apps/docs/components/label.md b/apps/docs/components/label.md new file mode 100644 index 0000000..ec6da56 --- /dev/null +++ b/apps/docs/components/label.md @@ -0,0 +1,130 @@ +--- +title: Label 标签 +description: 渲染与表单控件关联的无障碍标签。 +component: label +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 示例 + +### 带必填指示符 + +```vue + + + +``` + +### 禁用状态 + +```vue + + + +``` + +### 无效状态 + +```vue + + + +``` + +在 TextField 内使用时,`is-required` / `is-disabled` / `is-invalid` 会自动继承字段状态,无需重复标注。 + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +若要自定义组件类,可使用 `@layer components` 指令。 + +```css +@layer components { + .hv-label { + @apply font-semibold text-foreground; + } + + .hv-label--required::after { + @apply text-accent; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +Label 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/label.css)): + +#### 基础类 [!toc] + +- `.hv-label` — 基础标签文本样式 + +#### 状态修饰类 [!toc] + +- `.hv-label--required` 或 `[data-required="true"] > .hv-label` — 显示必填星号 +- `.hv-label--disabled` 或 `[data-disabled="true"] .hv-label` — 禁用状态样式 +- `.hv-label--invalid` 或 `[data-invalid="true"] .hv-label` — 无效状态样式(危险/红色文本) + +**说明:** 必填星号会基于 role 与 `data-slot` 智能应用,并排除 `role="group"` / `radiogroup` / `checkboxgroup` 以及 `data-slot="radio"` / `checkbox` 的元素,避免分组内重复星号。 + +## API 参考 + +### Label + +| Prop | 类型 | 默认值 | 描述 | +| ------------ | --------------------------- | ------- | ------------------------------------- | +| `for` | `string` | - | 标签所关联元素的 id(Vue 使用 `for`) | +| `isRequired` | `boolean` | `false` | 是否显示必填指示符 | +| `isDisabled` | `boolean` | `false` | 标签是否处于禁用状态 | +| `isInvalid` | `boolean` | `false` | 标签是否处于无效状态 | +| 默认插槽 | `Component` | - | 标签内容 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +在 TextField 内且未显式传 `for` 时,自动关联当前控件 id。Switch 等 toggle 字段内渲染为非交互 `span`,避免嵌套交互。 + +## 无障碍 + +Label 基于原生 HTML `