fix(demos): restore form, overlay and toast demos to the pinned cn baseline

HD-02 scope, all against heroui ce90ea3 cn sources:

- card: add the text-primary class to the coin icons (source parity);
  card-with-form drops the added required validation and inline business
  note, restores the plain href="#" forgot-password link and the baseline
  alert("表单提交成功!") submit feedback (autocomplete kept: no visible
  impact, allowed by the task card)
- input-group-with-textarea: restore the four Tooltips and the Enter Kbd
  hint; drop the stale "Tooltip 组件尚未迁移" note from input-group.md
- alert-dialog: restore the h-px top light line in custom-styles and the
  truncated/missing description text in sizes/custom-portal/
  custom-animations (+ controlled); align the fluid-slide icon with the
  modal mapping (IconArrowBarUp for gravity-ui:arrow-up-from-line)
- toast: restore the upstream demo layout shells (variants/simple/
  custom-indicator/custom-queue) and the action button default variant:
  ToastActionButton now falls back to the Button defaults (primary/md)
  like upstream ToastActionButton, so variants' actions render primary,
  danger stays danger and default stays tertiary; toast.md defaults fixed
- submit demos: restore baseline feedback and structure — alert() for
  card/fieldset/form/checkbox/checkbox-group/switch/select/combo-box/
  autocomplete and console.log for search/number/time field form examples;
  modal-with-form returns to the close-only footer (no submit/result row);
  drop the added inline status/result rows and the max-w-full/
  max-sm:min-w-0 width guards from the restored demos
- radio-group-validation: add the missing text-muted to the result line;
  label.md invalid example gives the real control its invalid state and
  matches the baseline input shape

Tests re-pinned to the baseline contracts (alert/console/close behavior,
four tooltips + Kbd, positional modal footer); full suite 110 files /
1617 tests, typecheck, build:docs and the m35-m36 tarball contract pass.
This commit is contained in:
maoyingjie
2026-10-28 14:10:10 +08:00
parent e9760810b8
commit 53e76f676d
53 changed files with 531 additions and 572 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ Fieldset 复合组件暴露以下 CSS 选择器:
三个部件使用对应 BEM 基础类,class 接受字符串、数组和对象。命名导出替代 React 对象式子部件;原生属性直接传递,不使用 nativeProps 对象。根元素固定为语义化原生元素,暂不提供 React render 根元素替换。 三个部件使用对应 BEM 基础类,class 接受字符串、数组和对象。命名导出替代 React 对象式子部件;原生属性直接传递,不使用 nativeProps 对象。根元素固定为语义化原生元素,暂不提供 React render 根元素替换。
Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例展示实际 FormData 与成功反馈,不执行后台保存。 Fieldset 不维护字段值或校验队列。请使用 Form + TextField / SearchField,提交与 reset 沿用原生表单;示例以 `alert` 给出成功反馈,不执行后台保存。
## 相关组件 ## 相关组件
+24 -24
View File
@@ -80,32 +80,32 @@ import { Form, Button } from "@heroui-vue/components";
Form 复用本库共享字段上下文与浏览器 Constraint Validation API。`FormRoot` 是同一组件别名;原生属性、ARIA、class、style 与 DOM 监听器透传到实际 form。 Form 复用本库共享字段上下文与浏览器 Constraint Validation API。`FormRoot` 是同一组件别名;原生属性、ARIA、class、style 与 DOM 监听器透传到实际 form。
| Prop / 事件 | 类型 | 默认值 | 描述 | | Prop / 事件 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- | | --------------------------- | ------------------------------------ | --------------------- | ----------------------------------------------------------------------------- |
| `action` | `string` | - | 提交表单数据的 URL;保留浏览器传统提交 | | `action` | `string` | - | 提交表单数据的 URL;保留浏览器传统提交 |
| `class` | Vue class 绑定 | - | 应用于 form 元素的布局与样式 | | `class` | Vue class 绑定 | - | 应用于 form 元素的布局与样式 |
| 默认插槽 | `() => VNodeChild` | - | 表单内容(字段、按钮等) | | 默认插槽 | `() => VNodeChild` | - | 表单内容(字段、按钮等) |
| `enctype` | `string` | - | 原生编码类型,如 `multipart/form-data` | | `enctype` | `string` | - | 原生编码类型,如 `multipart/form-data` |
| `method` | `string` | - | 原生提交方法,如 `get` / `post` | | `method` | `string` | - | 原生提交方法,如 `get` / `post` |
| `@invalid` | `(event: Event) => void` | - | 每个无效控件每次检查通知一次;`preventDefault()` 取消默认焦点,不放行无效提交 | | `@invalid` | `(event: Event) => void` | - | 每个无效控件每次检查通知一次;`preventDefault()` 取消默认焦点,不放行无效提交 |
| `@reset` | `(event: Event) => void` | - | 原生重置事件;可 `preventDefault()` 取消 | | `@reset` | `(event: Event) => void` | - | 原生重置事件;可 `preventDefault()` 取消 |
| `@submit` | `(event: SubmitEvent) => void` | - | 校验通过或显式跳过校验时调用;使用 `.prevent` 接管提交 | | `@submit` | `(event: SubmitEvent) => void` | - | 校验通过或显式跳过校验时调用;使用 `.prevent` 接管提交 |
| `target` | `string` | - | 提交后显示响应的位置 | | `target` | `string` | - | 提交后显示响应的位置 |
| `validationBehavior` | `'native' \| 'aria'` | `'native'` | 默认字段校验策略;字段可覆盖 | | `validationBehavior` | `'native' \| 'aria'` | `'native'` | 默认字段校验策略;字段可覆盖 |
| `validationErrors` | `Record<string, string \| string[]>` | `{}` | 按字段名映射的服务端错误;编辑该字段后忽略当前响应中的错误 | | `validationErrors` | `Record<string, string \| string[]>` | `{}` | 按字段名映射的服务端错误;编辑该字段后忽略当前响应中的错误 |
| `aria-label` | `string` | - | 表单的无障碍名称 | | `aria-label` | `string` | - | 表单的无障碍名称 |
| `aria-labelledby` | `string` | - | 标注表单的元素 ID | | `aria-labelledby` | `string` | - | 标注表单的元素 ID |
| `novalidate` / `noValidate` | `boolean` | `false`(调用方意图) | 为 `true` 或空属性时跳过本库提交检查;实际 DOM 始终有 novalidate,见下文 | | `novalidate` / `noValidate` | `boolean` | `false`(调用方意图) | 为 `true` 或空属性时跳过本库提交检查;实际 DOM 始终有 novalidate,见下文 |
| `render`(上游) | Vue attrs / 默认插槽替代 | - | 添加原生属性直接透传;不移植 React DOMRenderFunction | | `render`(上游) | Vue attrs / 默认插槽替代 | - | 添加原生属性直接透传;不移植 React DOMRenderFunction |
公开类型包含 `FormProps`、`FormRootProps`、`FormSlots`、`FormExpose`。实例能力是 Vue 扩展: 公开类型包含 `FormProps`、`FormRootProps`、`FormSlots`、`FormExpose`。实例能力是 Vue 扩展:
| 实例成员 | 类型 | 说明 | | 实例成员 | 类型 | 说明 |
| --- | --- | --- | | ------------------ | ------------------------------ | -------------------------------------------------------------------------------------- |
| `element` | `HTMLFormElement \| undefined` | 挂载后实际 form | | `element` | `HTMLFormElement \| undefined` | 挂载后实际 form |
| `checkValidity()` | `() => boolean` | 按 native/aria 策略检查并产生 invalid;不自动聚焦 | | `checkValidity()` | `() => boolean` | 按 native/aria 策略检查并产生 invalid;不自动聚焦 |
| `reportValidity()` | `() => boolean` | 检查并聚焦首个无效字段,除非调用方取消;错误由 FieldError 展示,不重复调用原生气泡校验 | | `reportValidity()` | `() => boolean` | 检查并聚焦首个无效字段,除非调用方取消;错误由 FieldError 展示,不重复调用原生气泡校验 |
| `reset()` | `() => void` | 调用原生 form.reset(),遵守取消与既有受控值协议 | | `reset()` | `() => void` | 调用原生 form.reset(),遵守取消与既有受控值协议 |
### Form Validation ### Form Validation
@@ -174,7 +174,7 @@ Form 与共享字段组件协作:
- 错误通过 FieldError 与真实控件的 ARIA 描述关联。 - 错误通过 FieldError 与真实控件的 ARIA 描述关联。
- `validationBehavior="aria"` 保留错误语义但不阻止提交。 - `validationBehavior="aria"` 保留错误语义但不阻止提交。
三个预览沿用固定源的字段、文案、校验与布局;为适应窄屏增加 `max-w-full`,提交结果用页内 `status` 替代上游 `alert`,reset 同时清除该反馈。React 专属机制按上述 Vue 方式适配。当前仅支持浏览器客户端;未将完整读屏矩阵或逐像素比较视为已完成。 三个预览沿用固定源的字段、文案、校验、布局与提交反馈:有效提交以 `alert` 展示表单数据,`reset` 重置字段与校验错误。React 专属机制按上述 Vue 方式适配。当前仅支持浏览器客户端;未将完整读屏矩阵或逐像素比较视为已完成。
## 相关案例 ## 相关案例
-2
View File
@@ -167,8 +167,6 @@ InputGroup 会自动反映父级 TextField 的无效状态。
多行输入请使用 **InputGroupTextArea**,并搭配前缀与后缀。当存在 textarea 时,容器高度会自动适应内容,并将前缀/后缀与顶部对齐。 多行输入请使用 **InputGroupTextArea**,并搭配前缀与后缀。当存在 textarea 时,容器高度会自动适应内容,并将前缀/后缀与顶部对齐。
上游示例中的 Tooltip 由原生 `title` 与 `aria-label` 适配(Tooltip 组件尚未迁移)。
<ComponentPreview name="input-group-with-textarea" /> <ComponentPreview name="input-group-with-textarea" />
## 自定义样式 ## 自定义样式
+1 -1
View File
@@ -52,7 +52,7 @@ import { Label, Input } from "@heroui-vue/components";
<template> <template>
<Label for="password" is-invalid>密码</Label> <Label for="password" is-invalid>密码</Label>
<Input id="password" type="password" /> <Input id="password" invalid />
</template> </template>
``` ```
+1 -1
View File
@@ -392,7 +392,7 @@ NumberFieldDecrementButton 支持原生 button 属性、事件、`isDisabled`
- FormData 只提交一份未格式化的完整数值,显示货币或百分比不改变提交值。native 校验阻止无效提交;aria 只展示状态。reset 尊重取消,非受控恢复初值,受控保留父值。validate 为同步函数;不提供 RAC validationDetails。 - FormData 只提交一份未格式化的完整数值,显示货币或百分比不改变提交值。native 校验阻止无效提交;aria 只展示状态。reset 尊重取消,非受控恢复初值,受控保留父值。validate 为同步函数;不提供 RAC validationDetails。
- React render prop 对应默认作用域插槽;class/style 函数改用 Vue 绑定,不支持 React PressEvent。渲染函数示例用 data-custom 透传表达相同默认 div 的自定义属性,不宣称支持任意 React render 回调。 - React render prop 对应默认作用域插槽;class/style 函数改用 Vue 绑定,不支持 React PressEvent。渲染函数示例用 data-custom 透传表达相同默认 div 的自定义属性,不宣称支持任意 React render 回调。
- 增减按钮的 click 可取消;支持指针按住重复、释放/取消/移出清理及键盘激活。默认图标移植上游公共图标,自定义图标示例使用 Tabler Vue。任意非原生交互 asChild 根的键盘语义由调用方负责。 - 增减按钮的 click 可取消;支持指针按住重复、释放/取消/移出清理及键盘激活。默认图标移植上游公共图标,自定义图标示例使用 Tabler Vue。任意非原生交互 asChild 根的键盘语义由调用方负责。
- 校验示例的百分比模型按 0–1 判断(原演示将模型与 0–100 混用);表单示例仅本地模拟提交,反馈与定时器清理不代表真实业务请求。 - 校验示例的百分比模型按 0–1 判断(原演示将模型与 0–100 混用);表单示例与基线一致,仅本地模拟提交并将提交值输出到控制台,定时器清理不代表真实业务请求。
- SSR 关联预规划支持直接部件、原生包装及 NumberFieldGroup。自定义 Vue 包装内部的 ID 请显式指定;完整读屏、触屏及 Nuxt 验收以验证报告为准。 - SSR 关联预规划支持直接部件、原生包装及 NumberFieldGroup。自定义 Vue 包装内部的 ID 请显式指定;完整读屏、触屏及 Nuxt 验收以验证报告为准。
- 上游 Input API 表还列有 variant,但固定实现只从根生成样式;Vue 同样使用根 variant,自定义 Input 外观通过 class/style,不暴露无效的叶子 variant 参数。 - 上游 Input API 表还列有 variant,但固定实现只从根生成样式;Vue 同样使用根 variant,自定义 Input 外观通过 class/style,不暴露无效的叶子 variant 参数。
+1 -1
View File
@@ -103,7 +103,7 @@ SearchField 组件支持两种视觉变体:
### 表单示例 ### 表单示例
完整的表单集成示例,包含校验、实际 FormData 和模拟提交反馈;没有后台搜索请求。 完整的表单集成示例,包含校验与模拟提交(提交值输出到控制台);没有后台搜索请求。
<ComponentPreview name="search-field-form-example" /> <ComponentPreview name="search-field-form-example" />
+1 -1
View File
@@ -341,7 +341,7 @@ Select 组件使用以下 CSS 类([查看源码样式](https://github.com/hero
- 关闭态从已知 ListBox/Section/Item 插槽预规划元数据;不执行任意包装组件的 setup/render。不透明包装请提供 Select 的 `items`,否则首次打开前未知选项只能显示 key,且无法提交未知选项。 - 关闭态从已知 ListBox/Section/Item 插槽预规划元数据;不执行任意包装组件的 setup/render。不透明包装请提供 Select 的 `items`,否则首次打开前未知选项只能显示 key,且无法提交未知选项。
- 唯一原生 select 提交层保留字符串边界,多选使用重复 name;类型区分只用于组件值与事件。浏览器自动填充通过选中 option 的索引恢复原始 key,不把内部编码放进 FormData。 - 唯一原生 select 提交层保留字符串边界,多选使用重复 name;类型区分只用于组件值与事件。浏览器自动填充通过选中 option 的索引恢复原始 key,不把内部编码放进 FormData。
- 支持原生必填、重置、Fieldset 与 Form 错误关联;跨浏览器自动填充与实际屏幕阅读器播报仍需专项验收,不声明等同 React Aria 全部能力。 - 支持原生必填、重置、Fieldset 与 Form 错误关联;跨浏览器自动填充与实际屏幕阅读器播报仍需专项验收,不声明等同 React Aria 全部能力。
- 样式及 19 个中文示例来自固定 HeroUI 基线;React 渲染函数改为 Vue 插槽,文档的表单成功反馈使用内联状态,图标扩展示例使用 Tabler。 - 样式及 19 个中文示例来自固定 HeroUI 基线;React 渲染函数改为 Vue 插槽,表单成功反馈与基线一致使用 `alert`,图标扩展示例使用 Tabler。
## 相关组件 ## 相关组件
+1 -1
View File
@@ -452,7 +452,7 @@ TimeFieldSuffix 接受标准 HTML `div` 属性:
- `locale` / `dir` 默认读取 ConfigProvider(否则 en-US / ltr);可显式覆盖。`form` 支持外部表单,`autoComplete` 默认 off;`disabled` 是 isDisabled 的原生别名。Root 暴露 `element` / `focus()`。 - `locale` / `dir` 默认读取 ConfigProvider(否则 en-US / ltr);可显式覆盖。`form` 支持外部表单,`autoComplete` 默认 off;`disabled` 是 isDisabled 的原生别名。Root 暴露 `element` / `focus()`。
- React `render` 改为 `as` 和原生 attrs;children render prop 改默认作用域插槽。class/style 函数不直接移植,使用插槽状态和 Vue 绑定。没有声明继承全部 RAC props;Reka 的 step/stepSnapping 不作为额外公共 API。 - React `render` 改为 `as` 和原生 attrs;children render prop 改默认作用域插槽。class/style 函数不直接移植,使用插槽状态和 Vue 绑定。没有声明继承全部 RAC props;Reka 的 step/stepSnapping 不作为额外公共 API。
- Group 支持 `variant`、`fullWidth`、`as`;Input、InputContainer、Segment、Prefix、Suffix 支持 `as` 和原生 attrs,Segment 还要求 `segment`。Input 的视觉变体由 Group 设置。取消按键需在实际 Segment 上使用 `@keydown.prevent`(可按需 stop);Root 的冒泡监听晚于分段编辑,不能撤销已经完成的子处理。 - Group 支持 `variant`、`fullWidth`、`as`;Input、InputContainer、Segment、Prefix、Suffix 支持 `as` 和原生 attrs,Segment 还要求 `segment`。Input 的视觉变体由 Group 设置。取消按键需在实际 Segment 上使用 `@keydown.prevent`(可按需 stop);Root 的冒泡监听晚于分段编辑,不能撤销已经完成的子处理。
- 表单示例在模拟提交后显示实际提交值并清空;替代上游控制台反馈,保留 1500ms 加载流程并在卸载时清理计时器。 - 表单示例与基线一致:模拟提交(1500ms 加载)后将实际提交值输出到控制台并清空输入,卸载时清理计时器。
- 当前仅支持浏览器客户端。未开展完整系统 IME、读屏、真机或逐像素自动对比专项。 - 当前仅支持浏览器客户端。未开展完整系统 IME、读屏、真机或逐像素自动对比专项。
Enter 在实际 Segment 上触发所属原生表单的 `requestSubmit()`(支持外部 form),遵守原生约束校验和 `@keydown.prevent`。blur 不重复发送已经接受的值。 Enter 在实际 Segment 上触发所属原生表单的 `requestSubmit()`(支持外部 form),遵守原生约束校验和 `@keydown.prevent`。blur 不重复发送已经接受的值。
+7 -7
View File
@@ -274,13 +274,13 @@ Toast 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/
### ToastActionButton ### ToastActionButton
| Prop / 事件 | 类型 | 默认值 | 描述 | | Prop / 事件 | 类型 | 默认值 | 描述 |
| ---------------------------- | ------------ | ------------- | --------------------------------------------------------------- | | ---------------------------- | ------------ | ----------- | --------------------------------------------------------------- |
| `variant` | Button 变体 | `'secondary'` | 按钮变体 | | `variant` | Button 变体 | `'primary'` | 按钮变体(与上游一致,回落到 Button 默认变体) |
| `size` | Button 尺寸 | `'sm'` | 按钮尺寸 | | `size` | Button 尺寸 | `'md'` | 按钮尺寸(与上游一致,回落到 Button 默认尺寸) |
| `isDisabled` | `boolean` | `false` | 禁用 | | `isDisabled` | `boolean` | `false` | 禁用 |
| `@click` | `MouseEvent` | — | 默认命令式动作先调用用户处理,再关闭;preventDefault 可阻止关闭 | | `@click` | `MouseEvent` | — | 默认命令式动作先调用用户处理,再关闭;preventDefault 可阻止关闭 |
| 其余 Button props / 默认插槽 | 见 Button | — | 透传给基础 Button;自定义插槽中的按钮可调用 close | | 其余 Button props / 默认插槽 | 见 Button | — | 透传给基础 Button;自定义插槽中的按钮可调用 close |
### ToastCloseButton ### ToastCloseButton
@@ -1,5 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { IconArrowUp, IconSparkles } from "@tabler/icons-vue"; import {
IconArrowBarUp as ArrowUpFromLine,
IconSparkles,
} from "@tabler/icons-vue";
import { import {
AlertDialog, AlertDialog,
AlertDialogBackdrop, AlertDialogBackdrop,
@@ -28,9 +31,9 @@ const animations = [
}, },
{ {
name: "流体滑入", name: "流体滑入",
icon: IconArrowUp, icon: ArrowUpFromLine,
description: description:
"模拟在介质中运动并受流体阻力影响,避免机械式线性,更自然、更贴地。", "模拟在介质中运动并受流体阻力影响,避免机械式线性,更自然、更贴地,适合底部抽屉或 Toast。",
backdropClass: backdropClass:
"data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]", "data-[entering]:duration-500 data-[entering]:ease-[cubic-bezier(0.25,1,0.5,1)] data-[exiting]:duration-200 data-[exiting]:ease-[cubic-bezier(0.5,0,0.75,0)]",
containerClass: containerClass:
@@ -50,10 +50,17 @@ const portalEl = ref<HTMLElement | null>(null);
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogBody> <AlertDialogBody>
<p class="text-sm text-muted"> <p class="text-sm text-muted">
此段为示例占位文案,用于演示在自定义容器内渲染对话框时的滚动与排版效果。 此段为示例占位文案,用于演示在自定义容器内渲染对话框时的滚动与排版效果。实际项目中请替换为真实说明内容。
</p> </p>
<p class="text-sm text-muted"> <p class="text-sm text-muted">
通过将浮层挂载到局部容器,可以配合裁剪、缩放或卡片布局,避免遮挡整个页面。 通过将浮层挂载到局部容器,可以配合裁剪、缩放或卡片布局,避免遮挡整个页面,同时仍保持焦点管理与无障碍行为。
</p>
<p class="text-sm text-muted">
若容器存在
<code>transform</code>
或
<code>filter</code>
等属性,请注意浏览器会为其创建新的包含块,从而影响定位与层级关系。
</p> </p>
</AlertDialogBody> </AlertDialogBody>
<AlertDialogFooter> <AlertDialogFooter>
@@ -29,6 +29,10 @@ import {
aria-hidden="true" aria-hidden="true"
class="pointer-events-none absolute inset-x-0 top-0 h-24 bg-linear-to-b from-accent/6 to-transparent dark:from-accent/10" class="pointer-events-none absolute inset-x-0 top-0 h-24 bg-linear-to-b from-accent/6 to-transparent dark:from-accent/10"
/> />
<div
aria-hidden="true"
class="pointer-events-none absolute inset-x-8 top-0 h-px bg-linear-to-r from-transparent via-accent/35 to-transparent dark:via-accent/45"
/>
<AlertDialogHeader class="relative"> <AlertDialogHeader class="relative">
<AlertDialogIcon status="accent" /> <AlertDialogIcon status="accent" />
<AlertDialogHeading>确定要退出账户吗?</AlertDialogHeading> <AlertDialogHeading>确定要退出账户吗?</AlertDialogHeading>
+3 -2
View File
@@ -45,12 +45,13 @@ const sizes = ["xs", "sm", "md", "lg", "cover"] as const;
<p v-if="size === 'cover'"> <p v-if="size === 'cover'">
此警告框使用 此警告框使用
<code>cover</code> <code>cover</code>
尺寸:在移动端与桌面端保留边距铺满可视区域,仍保持圆角与标准内边距。 尺寸:在移动端与桌面端保留边距(移动端约 16px、桌面端约
40px)铺满可视区域,仍保持圆角与标准内边距,适合需要最大宽度又保留对话框气质的关键确认。
</p> </p>
<p v-else> <p v-else>
此警告框使用 此警告框使用
<code>{{ size }}</code> <code>{{ size }}</code>
尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度。 尺寸。在移动端各尺寸都会接近全宽以便阅读;在桌面端则对应不同的最大宽度,以适配不同信息量。
</p> </p>
</AlertDialogBody> </AlertDialogBody>
<AlertDialogFooter> <AlertDialogFooter>
+2 -9
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { import {
Autocomplete, Autocomplete,
AutocompleteClearButton, AutocompleteClearButton,
@@ -41,13 +40,10 @@ const countries = [
{ id: "germany", name: "Germany" }, { id: "germany", name: "Germany" },
]; ];
const message = ref<string | null>(null);
function onSubmit(event: Event) { function onSubmit(event: Event) {
event.preventDefault(); event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement); // The Form guard already blocks invalid submits, so a reached handler is valid.
void formData; alert("表单提交成功!");
message.value = "表单提交成功!";
} }
</script> </script>
@@ -144,8 +140,5 @@ function onSubmit(event: Event) {
<FieldError /> <FieldError />
</Autocomplete> </Autocomplete>
<Button type="submit">提交</Button> <Button type="submit">提交</Button>
<p v-if="message" role="status" class="text-sm text-muted">
{{ message }}
</p>
</Form> </Form>
</template> </template>
+1 -1
View File
@@ -12,7 +12,7 @@ import {
</script> </script>
<template> <template>
<Card class="w-[400px]"> <Card class="w-[400px]">
<IconCoin role="img" aria-label="美元图标" class="size-6" /> <IconCoin role="img" aria-label="美元图标" class="text-primary size-6" />
<CardHeader> <CardHeader>
<CardTitle>成为 Acme 创作者!</CardTitle> <CardTitle>成为 Acme 创作者!</CardTitle>
<CardDescription> <CardDescription>
+7 -20
View File
@@ -10,10 +10,12 @@ import {
Link, Link,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { Input, Label } from "@heroui-vue/components"; import { Input, Label } from "@heroui-vue/components";
import { ref, useId } from "vue"; import { useId } from "vue";
const id = useId(); const id = useId();
const submitted = ref(false); function onSubmit(event: Event) {
const message = ref(""); event.preventDefault();
alert("表单提交成功!");
}
</script> </script>
<template> <template>
<Card class="w-full max-w-md"> <Card class="w-full max-w-md">
@@ -21,7 +23,7 @@ const message = ref("");
<CardTitle>登录</CardTitle> <CardTitle>登录</CardTitle>
<CardDescription>输入账号信息以访问您的账户</CardDescription> <CardDescription>输入账号信息以访问您的账户</CardDescription>
</CardHeader> </CardHeader>
<form class="flex flex-col" @submit.prevent="submitted = true"> <form class="flex flex-col" @submit="onSubmit">
<CardContent> <CardContent>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<div class="flex flex-col gap-1"> <div class="flex flex-col gap-1">
@@ -33,7 +35,6 @@ const message = ref("");
autocomplete="email" autocomplete="email"
placeholder="email@example.com" placeholder="email@example.com"
variant="secondary" variant="secondary"
required
/> />
</div> </div>
<div class="flex flex-col gap-1"> <div class="flex flex-col gap-1">
@@ -45,28 +46,14 @@ const message = ref("");
autocomplete="current-password" autocomplete="current-password"
placeholder="••••••••" placeholder="••••••••"
variant="secondary" variant="secondary"
required
/> />
</div> </div>
</div> </div>
</CardContent> </CardContent>
<CardFooter class="mt-4 flex flex-col gap-2"> <CardFooter class="mt-4 flex flex-col gap-2">
<Button class="w-full" type="submit">登录</Button> <Button class="w-full" type="submit">登录</Button>
<Link <Link class="text-center text-sm" href="#">忘记密码?</Link>
class="text-center text-sm"
href="#"
@click.prevent="message = '请联系账户管理员重置密码。'"
>
忘记密码?
</Link>
</CardFooter> </CardFooter>
<p
v-if="submitted || message"
role="status"
class="mt-2 text-sm text-muted"
>
{{ message || "表单提交成功!此示例不会发送账号信息。" }}
</p>
</form> </form>
</Card> </Card>
</template> </template>
+1 -1
View File
@@ -62,7 +62,7 @@ import {
<IconCoin <IconCoin
role="img" role="img"
aria-label="美元图标" aria-label="美元图标"
class="size-8 shrink-0" class="text-primary size-8 shrink-0"
/> />
<div class="flex flex-col gap-1"> <div class="flex flex-col gap-1">
<span class="text-xs font-medium text-muted uppercase"> <span class="text-xs font-medium text-muted uppercase">
+4 -9
View File
@@ -6,15 +6,13 @@ import {
Checkbox, Checkbox,
Button, Button,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) { function submit(event: Event) {
const data = new FormData(event.currentTarget as HTMLFormElement); const data = new FormData(event.currentTarget as HTMLFormElement);
result.value = alert(
"表单提交数据:\n" + `表单提交数据:\n${Array.from(data)
Array.from(data)
.map(([key, value]) => `${key}: ${value}`) .map(([key, value]) => `${key}: ${value}`)
.join("\n"); .join("\n")}`,
);
} }
</script> </script>
<template> <template>
@@ -46,8 +44,5 @@ function submit(event: Event) {
</Checkbox> </Checkbox>
</div> </div>
<Button class="mt-4" size="sm" type="submit" variant="primary">提交</Button> <Button class="mt-4" size="sm" type="submit" variant="primary">提交</Button>
<pre v-if="result" role="status" class="whitespace-pre-wrap text-sm">{{
result
}}</pre>
</form> </form>
</template> </template>
@@ -10,11 +10,10 @@ import {
Button, Button,
Form, Form,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) { function submit(event: Event) {
const data = new FormData(event.currentTarget as HTMLFormElement); const data = new FormData(event.currentTarget as HTMLFormElement);
result.value = "已选偏好:" + data.getAll("preferences").join(", "); const values = data.getAll("preferences");
alert(`已选偏好:${values.join(", ")}`);
} }
</script> </script>
<template> <template>
@@ -48,6 +47,5 @@ function submit(event: Event) {
<FieldError>请至少选择一种通知方式。</FieldError> <FieldError>请至少选择一种通知方式。</FieldError>
</CheckboxGroup> </CheckboxGroup>
<Button type="submit">提交</Button> <Button type="submit">提交</Button>
<p v-if="result" role="status" class="text-sm">{{ result }}</p>
</Form> </Form>
</template> </template>
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { import {
Button, Button,
ComboBox, ComboBox,
@@ -36,10 +35,8 @@ function validate(value: string | number | (string | number)[] | null) {
return true; return true;
} }
const message = ref("");
function onSubmit() { function onSubmit() {
message.value = "表单提交成功!"; alert("表单提交成功!");
} }
</script> </script>
@@ -67,6 +64,5 @@ function onSubmit() {
<FieldError /> <FieldError />
</ComboBox> </ComboBox>
<Button class="w-fit" type="submit">提交</Button> <Button class="w-fit" type="submit">提交</Button>
<p v-if="message" class="text-sm text-muted" role="status">{{ message }}</p>
</Form> </Form>
</template> </template>
+1 -7
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { import {
Button, Button,
ComboBox, ComboBox,
@@ -16,11 +15,9 @@ import {
Surface, Surface,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const message = ref("");
function onSubmit(event: Event) { function onSubmit(event: Event) {
event.preventDefault(); event.preventDefault();
message.value = "表单提交成功!"; alert("表单提交成功!");
} }
</script> </script>
@@ -64,9 +61,6 @@ function onSubmit(event: Event) {
<FieldError /> <FieldError />
</ComboBox> </ComboBox>
<Button type="submit">提交</Button> <Button type="submit">提交</Button>
<p v-if="message" class="text-sm text-muted" role="status">
{{ message }}
</p>
</Form> </Form>
</Surface> </Surface>
</template> </template>
+2 -9
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { import {
Button, Button,
ComboBox, ComboBox,
@@ -15,12 +14,9 @@ import {
ListBoxItemIndicator, ListBoxItemIndicator,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const submitted = ref(false); function submit() {
function submit(event: Event) {
// The Form guard already blocks invalid submits, so a reached handler is valid. // The Form guard already blocks invalid submits, so a reached handler is valid.
void new FormData(event.currentTarget as HTMLFormElement); alert("表单提交成功!");
submitted.value = true;
} }
</script> </script>
@@ -63,8 +59,5 @@ function submit(event: Event) {
<FieldError /> <FieldError />
</ComboBox> </ComboBox>
<Button type="submit">提交</Button> <Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-muted">
表单提交成功!
</p>
</Form> </Form>
</template> </template>
+3 -11
View File
@@ -14,19 +14,14 @@ import {
TextField, TextField,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { IconDeviceFloppy } from "@tabler/icons-vue"; import { IconDeviceFloppy } from "@tabler/icons-vue";
import { ref } from "vue";
const result = ref("");
function validateName(value: string) { function validateName(value: string) {
return value.length < 3 ? "姓名至少需要 3 个字符" : null; return value.length < 3 ? "姓名至少需要 3 个字符" : null;
} }
function validateBio(value: string) { function validateBio(value: string) {
return value.length < 10 ? "简介至少需要 10 个字符" : null; return value.length < 10 ? "简介至少需要 10 个字符" : null;
} }
function submit(event: Event) { function submit() {
const data = Object.fromEntries( alert("表单提交成功!");
new FormData(event.currentTarget as HTMLFormElement),
);
result.value = `表单提交成功!${JSON.stringify(data)}`;
} }
</script> </script>
<template> <template>
@@ -57,11 +52,8 @@ function submit(event: Event) {
<IconDeviceFloppy aria-hidden="true" /> <IconDeviceFloppy aria-hidden="true" />
保存更改 保存更改
</Button> </Button>
<Button type="reset" variant="secondary" @click="result = ''"> <Button type="reset" variant="secondary">取消</Button>
取消
</Button>
</FieldsetActions> </FieldsetActions>
</Fieldset> </Fieldset>
<p v-if="result" class="text-sm text-muted" role="status">{{ result }}</p>
</Form> </Form>
</template> </template>
+3 -11
View File
@@ -14,19 +14,14 @@ import {
TextField, TextField,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { IconDeviceFloppy } from "@tabler/icons-vue"; import { IconDeviceFloppy } from "@tabler/icons-vue";
import { ref } from "vue";
const result = ref("");
function validateName(value: string) { function validateName(value: string) {
return value.length < 3 ? "姓名至少需要 3 个字符" : null; return value.length < 3 ? "姓名至少需要 3 个字符" : null;
} }
function validateBio(value: string) { function validateBio(value: string) {
return value.length < 10 ? "简介至少需要 10 个字符" : null; return value.length < 10 ? "简介至少需要 10 个字符" : null;
} }
function submit(event: Event) { function submit() {
const data = Object.fromEntries( alert("表单提交成功!");
new FormData(event.currentTarget as HTMLFormElement),
);
result.value = `表单提交成功!${JSON.stringify(data)}`;
} }
const shell = const shell =
"rounded-xl border border-border/70 bg-linear-to-b from-neutral-50/90 to-white p-4 ring-1 ring-black/5 dark:from-neutral-900/80 dark:to-neutral-900 dark:ring-white/10"; "rounded-xl border border-border/70 bg-linear-to-b from-neutral-50/90 to-white p-4 ring-1 ring-black/5 dark:from-neutral-900/80 dark:to-neutral-900 dark:ring-white/10";
@@ -67,11 +62,8 @@ const fieldClass =
<IconDeviceFloppy aria-hidden="true" /> <IconDeviceFloppy aria-hidden="true" />
保存更改 保存更改
</Button> </Button>
<Button type="reset" variant="secondary" @click="result = ''"> <Button type="reset" variant="secondary">取消</Button>
取消
</Button>
</FieldsetActions> </FieldsetActions>
</Fieldset> </Fieldset>
<p v-if="result" class="text-sm text-muted" role="status">{{ result }}</p>
</Form> </Form>
</template> </template>
+4 -14
View File
@@ -15,24 +15,19 @@ import {
Surface, Surface,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { IconDeviceFloppy } from "@tabler/icons-vue"; import { IconDeviceFloppy } from "@tabler/icons-vue";
import { ref } from "vue";
const result = ref("");
function validateName(value: string) { function validateName(value: string) {
return value.length < 3 ? "姓名至少需要 3 个字符" : null; return value.length < 3 ? "姓名至少需要 3 个字符" : null;
} }
function validateBio(value: string) { function validateBio(value: string) {
return value.length < 10 ? "简介至少需要 10 个字符" : null; return value.length < 10 ? "简介至少需要 10 个字符" : null;
} }
function submit(event: Event) { function submit() {
const data = Object.fromEntries( alert("表单提交成功!");
new FormData(event.currentTarget as HTMLFormElement),
);
result.value = `表单提交成功!${JSON.stringify(data)}`;
} }
</script> </script>
<template> <template>
<div class="flex items-center justify-center rounded-3xl bg-surface p-6"> <div class="flex items-center justify-center rounded-3xl bg-surface p-6">
<Surface class="w-full min-w-[380px] max-sm:min-w-0"> <Surface class="w-full min-w-[380px]">
<Form @submit.prevent="submit"> <Form @submit.prevent="submit">
<Fieldset class="w-full"> <Fieldset class="w-full">
<FieldsetLegend>个人资料设置</FieldsetLegend> <FieldsetLegend>个人资料设置</FieldsetLegend>
@@ -60,14 +55,9 @@ function submit(event: Event) {
<IconDeviceFloppy aria-hidden="true" /> <IconDeviceFloppy aria-hidden="true" />
保存更改 保存更改
</Button> </Button>
<Button type="reset" variant="tertiary" @click="result = ''"> <Button type="reset" variant="tertiary">取消</Button>
取消
</Button>
</FieldsetActions> </FieldsetActions>
</Fieldset> </Fieldset>
<p v-if="result" class="text-sm text-muted" role="status">
{{ result }}
</p>
</Form> </Form>
</Surface> </Surface>
</div> </div>
+2 -14
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { IconCheck } from "@tabler/icons-vue"; import { IconCheck } from "@tabler/icons-vue";
import { import {
Button, Button,
@@ -11,7 +10,6 @@ import {
TextField, TextField,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const result = ref("");
function onSubmit(event: Event) { function onSubmit(event: Event) {
event.preventDefault(); event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement); const formData = new FormData(event.currentTarget as HTMLFormElement);
@@ -19,7 +17,7 @@ function onSubmit(event: Event) {
formData.forEach((value, key) => { formData.forEach((value, key) => {
data[key] = value.toString(); data[key] = value.toString();
}); });
result.value = `表单提交数据:${JSON.stringify(data, null, 2)}`; alert(`表单提交数据:${JSON.stringify(data, null, 2)}`);
} }
function validateEmail(value: string) { function validateEmail(value: string) {
return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value) return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)
@@ -35,11 +33,7 @@ function validatePassword(value: string) {
</script> </script>
<template> <template>
<Form <Form class="flex w-96 flex-col gap-4" @submit="onSubmit">
class="flex w-96 max-w-full flex-col gap-4"
@submit="onSubmit"
@reset="result = ''"
>
<TextField is-required name="email" type="email" :validate="validateEmail"> <TextField is-required name="email" type="email" :validate="validateEmail">
<Label>邮箱</Label> <Label>邮箱</Label>
<Input placeholder="john@example.com" /> <Input placeholder="john@example.com" />
@@ -64,11 +58,5 @@ function validatePassword(value: string) {
</Button> </Button>
<Button type="reset" variant="secondary">重置</Button> <Button type="reset" variant="secondary">重置</Button>
</div> </div>
<pre
v-if="result"
role="status"
aria-label="提交结果"
class="whitespace-pre-wrap break-all text-xs"
>{{ result }}</pre>
</Form> </Form>
</template> </template>
+1 -1
View File
@@ -4,7 +4,7 @@ import { Button, Form, Input, Label, TextField } from "@heroui-vue/components";
<template> <template>
<Form <Form
class="flex w-80 max-w-full flex-col gap-3 rounded-xl border border-border/80 bg-surface p-4 shadow-sm" class="flex w-80 flex-col gap-3 rounded-xl border border-border/80 bg-surface p-4 shadow-sm"
@submit.prevent @submit.prevent
> >
<TextField is-required name="email" type="email"> <TextField is-required name="email" type="email">
+2 -15
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { IconCheck } from "@tabler/icons-vue"; import { IconCheck } from "@tabler/icons-vue";
import { import {
Button, Button,
@@ -11,7 +10,6 @@ import {
TextField, TextField,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const result = ref("");
function onSubmit(event: Event) { function onSubmit(event: Event) {
event.preventDefault(); event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement); const formData = new FormData(event.currentTarget as HTMLFormElement);
@@ -19,7 +17,7 @@ function onSubmit(event: Event) {
formData.forEach((value, key) => { formData.forEach((value, key) => {
data[key] = value.toString(); data[key] = value.toString();
}); });
result.value = `表单提交数据:${JSON.stringify(data, null, 2)}`; alert(`表单提交数据:${JSON.stringify(data, null, 2)}`);
} }
function validateEmail(value: string) { function validateEmail(value: string) {
return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value) return /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)
@@ -35,12 +33,7 @@ function validatePassword(value: string) {
</script> </script>
<template> <template>
<Form <Form class="flex w-96 flex-col gap-4" data-custom="foo" @submit="onSubmit">
class="flex w-96 max-w-full flex-col gap-4"
data-custom="foo"
@submit="onSubmit"
@reset="result = ''"
>
<TextField is-required name="email" type="email" :validate="validateEmail"> <TextField is-required name="email" type="email" :validate="validateEmail">
<Label>邮箱</Label> <Label>邮箱</Label>
<Input placeholder="john@example.com" /> <Input placeholder="john@example.com" />
@@ -65,11 +58,5 @@ function validatePassword(value: string) {
</Button> </Button>
<Button type="reset" variant="secondary">重置</Button> <Button type="reset" variant="secondary">重置</Button>
</div> </div>
<pre
v-if="result"
role="status"
aria-label="提交结果"
class="whitespace-pre-wrap break-all text-xs"
>{{ result }}</pre>
</Form> </Form>
</template> </template>
+53 -30
View File
@@ -6,8 +6,12 @@ import {
InputGroupPrefix, InputGroupPrefix,
InputGroupSuffix, InputGroupSuffix,
InputGroupTextArea, InputGroupTextArea,
Kbd,
KbdAbbr,
Spinner, Spinner,
TextField, TextField,
Tooltip,
TooltipContent,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { import {
IconArrowUp, IconArrowUp,
@@ -53,45 +57,64 @@ function handleSubmit() {
:rows="5" :rows="5"
/> />
<InputGroupSuffix class="flex w-full items-center gap-1.5 px-3 py-0"> <InputGroupSuffix class="flex w-full items-center gap-1.5 px-3 py-0">
<Button <Tooltip :delay="0">
is-icon-only
aria-label="附加文件"
size="sm"
title="添加文件等"
variant="tertiary"
>
<IconPlus aria-hidden="true" />
</Button>
<Button
is-icon-only
aria-label="连接应用"
size="sm"
title="连接应用"
variant="tertiary"
>
<IconPlugConnected aria-hidden="true" />
</Button>
<div class="ms-auto flex items-center gap-1.5">
<Button <Button
is-icon-only is-icon-only
aria-label="语音输入" aria-label="附加文件"
size="sm" size="sm"
title="语音输入" variant="tertiary"
variant="ghost"
> >
<IconMicrophone aria-hidden="true" /> <IconPlus aria-hidden="true" />
</Button> </Button>
<TooltipContent>
<p class="text-xs">添加文件等</p>
</TooltipContent>
</Tooltip>
<Tooltip :delay="0">
<Button <Button
is-icon-only is-icon-only
aria-label="发送提示" aria-label="连接应用"
:is-disabled="!value.trim()" size="sm"
:is-pending="isSubmitting" variant="tertiary"
title="发送"
@click="handleSubmit"
> >
<Spinner v-if="isSubmitting" color="current" size="sm" /> <IconPlugConnected aria-hidden="true" />
<IconArrowUp v-else aria-hidden="true" />
</Button> </Button>
<TooltipContent>
<p class="text-xs">连接应用</p>
</TooltipContent>
</Tooltip>
<div class="ms-auto flex items-center gap-1.5">
<Tooltip :delay="0">
<Button
is-icon-only
aria-label="语音输入"
size="sm"
variant="ghost"
>
<IconMicrophone aria-hidden="true" />
</Button>
<TooltipContent>
<p class="text-xs">语音输入</p>
</TooltipContent>
</Tooltip>
<Tooltip :delay="0">
<Button
is-icon-only
aria-label="发送提示"
:is-disabled="!value.trim()"
:is-pending="isSubmitting"
@click="handleSubmit"
>
<Spinner v-if="isSubmitting" color="current" size="sm" />
<IconArrowUp v-else aria-hidden="true" />
</Button>
<TooltipContent class="flex items-center gap-1">
<p class="text-xs">发送</p>
<Kbd class="h-4 rounded-sm px-1">
<KbdAbbr key-value="enter" />
</Kbd>
</TooltipContent>
</Tooltip>
</div> </div>
</InputGroupSuffix> </InputGroupSuffix>
</InputGroup> </InputGroup>
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue"; import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue";
import { import {
Description, Description,
@@ -14,7 +13,9 @@ import {
Separator, Separator,
Surface, Surface,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const message = ref(""); function onAction(key: string | number) {
alert(`已选项目:${key}`);
}
const actions = [ const actions = [
{ {
id: "new-file", id: "new-file",
@@ -33,56 +34,53 @@ const actions = [
]; ];
</script> </script>
<template> <template>
<div class="space-y-3"> <Surface class="w-[256px] rounded-3xl shadow-surface">
<Surface class="w-[256px] rounded-3xl shadow-surface"> <ListBox
<ListBox aria-label="文件操作"
aria-label="文件操作" class="w-full p-2"
class="w-full p-2" selection-mode="none"
selection-mode="none" @action="onAction"
@action="message = `已选项目:${$event}`" :disabled-keys="['delete-file']"
:disabled-keys="['delete-file']" >
> <ListBoxSection>
<ListBoxSection> <Header>操作</Header>
<Header>操作</Header> <ListBoxItem
<ListBoxItem v-for="action in actions"
v-for="action in actions" :key="action.id"
:key="action.id" :id="action.id"
:id="action.id" :text-value="action.title"
:text-value="action.title" >
> <div class="flex h-8 items-start justify-center pt-px">
<div class="flex h-8 items-start justify-center pt-px"> <component :is="action.icon" class="size-4 shrink-0 text-muted" />
<component :is="action.icon" class="size-4 shrink-0 text-muted" /> </div>
</div> <div class="flex flex-col">
<div class="flex flex-col"> <Label>{{ action.title }}</Label>
<Label>{{ action.title }}</Label> <Description>{{ action.description }}</Description>
<Description>{{ action.description }}</Description> </div>
</div> <Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" variant="light"> <KbdAbbr key-value="command" />
<KbdAbbr key-value="command" /> <KbdContent>{{ action.shortcut }}</KbdContent>
<KbdContent>{{ action.shortcut }}</KbdContent> </Kbd>
</Kbd> </ListBoxItem>
</ListBoxItem> </ListBoxSection>
</ListBoxSection> <Separator />
<Separator /> <ListBoxSection>
<ListBoxSection> <Header>危险区域</Header>
<Header>危险区域</Header> <ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger"> <div class="flex h-8 items-start justify-center pt-px">
<div class="flex h-8 items-start justify-center pt-px"> <IconTrash class="size-4 shrink-0 text-danger" />
<IconTrash class="size-4 shrink-0 text-danger" /> </div>
</div> <div class="flex flex-col">
<div class="flex flex-col"> <Label>删除文件</Label>
<Label>删除文件</Label> <Description>移至废纸篓</Description>
<Description>移至废纸篓</Description> </div>
</div> <Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" variant="light"> <KbdAbbr key-value="command" />
<KbdAbbr key-value="command" /> <KbdAbbr key-value="shift" />
<KbdAbbr key-value="shift" /> <KbdContent>D</KbdContent>
<KbdContent>D</KbdContent> </Kbd>
</Kbd> </ListBoxItem>
</ListBoxItem> </ListBoxSection>
</ListBoxSection> </ListBox>
</ListBox> </Surface>
</Surface>
<p v-if="message" role="status" class="text-sm text-muted">{{ message }}</p>
</div>
</template> </template>
+51 -53
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue";
import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue"; import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue";
import { import {
Description, Description,
@@ -14,7 +13,9 @@ import {
Separator, Separator,
Surface, Surface,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const message = ref(""); function onAction(key: string | number) {
alert(`已选项目:${key}`);
}
const actions = [ const actions = [
{ {
id: "new-file", id: "new-file",
@@ -33,55 +34,52 @@ const actions = [
]; ];
</script> </script>
<template> <template>
<div class="space-y-3"> <Surface class="w-[256px] rounded-3xl shadow-surface">
<Surface class="w-[256px] rounded-3xl shadow-surface"> <ListBox
<ListBox aria-label="文件操作"
aria-label="文件操作" class="w-full p-2"
class="w-full p-2" selection-mode="none"
selection-mode="none" @action="onAction"
@action="message = `已选项目:${$event}`" >
> <ListBoxSection>
<ListBoxSection> <Header>操作</Header>
<Header>操作</Header> <ListBoxItem
<ListBoxItem v-for="action in actions"
v-for="action in actions" :key="action.id"
:key="action.id" :id="action.id"
:id="action.id" :text-value="action.title"
:text-value="action.title" >
> <div class="flex h-8 items-start justify-center pt-px">
<div class="flex h-8 items-start justify-center pt-px"> <component :is="action.icon" class="size-4 shrink-0 text-muted" />
<component :is="action.icon" class="size-4 shrink-0 text-muted" /> </div>
</div> <div class="flex flex-col">
<div class="flex flex-col"> <Label>{{ action.title }}</Label>
<Label>{{ action.title }}</Label> <Description>{{ action.description }}</Description>
<Description>{{ action.description }}</Description> </div>
</div> <Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" variant="light"> <KbdAbbr key-value="command" />
<KbdAbbr key-value="command" /> <KbdContent>{{ action.shortcut }}</KbdContent>
<KbdContent>{{ action.shortcut }}</KbdContent> </Kbd>
</Kbd> </ListBoxItem>
</ListBoxItem> </ListBoxSection>
</ListBoxSection> <Separator />
<Separator /> <ListBoxSection>
<ListBoxSection> <Header>危险区域</Header>
<Header>危险区域</Header> <ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger"> <div class="flex h-8 items-start justify-center pt-px">
<div class="flex h-8 items-start justify-center pt-px"> <IconTrash class="size-4 shrink-0 text-danger" />
<IconTrash class="size-4 shrink-0 text-danger" /> </div>
</div> <div class="flex flex-col">
<div class="flex flex-col"> <Label>删除文件</Label>
<Label>删除文件</Label> <Description>移至废纸篓</Description>
<Description>移至废纸篓</Description> </div>
</div> <Kbd class="ms-auto" variant="light">
<Kbd class="ms-auto" variant="light"> <KbdAbbr key-value="command" />
<KbdAbbr key-value="command" /> <KbdAbbr key-value="shift" />
<KbdAbbr key-value="shift" /> <KbdContent>D</KbdContent>
<KbdContent>D</KbdContent> </Kbd>
</Kbd> </ListBoxItem>
</ListBoxItem> </ListBoxSection>
</ListBoxSection> </ListBox>
</ListBox> </Surface>
</Surface>
<p v-if="message" role="status" class="text-sm text-muted">{{ message }}</p>
</div>
</template> </template>
+53 -71
View File
@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, useId } from "vue";
import { import {
Button, Button,
Input, Input,
@@ -17,78 +16,61 @@ import {
ModalIcon, ModalIcon,
Surface, Surface,
TextField, TextField,
useOverlayState,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { IconMail as Envelope } from "@tabler/icons-vue"; import { IconMail as Envelope } from "@tabler/icons-vue";
const state = useOverlayState();
const formId = useId();
const result = ref<Record<string, FormDataEntryValue>>();
function submit(event: SubmitEvent) {
result.value = Object.fromEntries(
new FormData(event.currentTarget as HTMLFormElement),
);
state.close();
}
</script> </script>
<template> <template>
<div> <Modal>
<Modal :state="state"> <Button variant="secondary">打开联系表单</Button>
<Button variant="secondary">打开联系表单</Button> <ModalBackdrop>
<ModalBackdrop> <ModalContainer placement="auto">
<ModalContainer placement="auto"> <ModalDialog class="sm:max-w-md">
<ModalDialog class="sm:max-w-md"> <ModalCloseTrigger></ModalCloseTrigger>
<ModalCloseTrigger></ModalCloseTrigger> <ModalHeader>
<ModalHeader> <ModalIcon class="bg-accent-soft text-accent-soft-foreground">
<ModalIcon class="bg-accent-soft text-accent-soft-foreground"> <Envelope aria-hidden="true" class="size-5"></Envelope>
<Envelope aria-hidden="true" class="size-5"></Envelope> </ModalIcon>
</ModalIcon> <ModalHeading>联系我们</ModalHeading>
<ModalHeading>联系我们</ModalHeading> <p class="mt-1.5 text-sm leading-5 text-muted">
<p class="mt-1.5 text-sm leading-5 text-muted"> 填写下方表单,我们会尽快回复。在移动端弹出键盘时,模态框会自动适配。
填写下方表单,我们会尽快回复。在移动端弹出键盘时,模态框会自动适配。 </p>
</p> </ModalHeader>
</ModalHeader> <ModalBody class="p-6">
<ModalBody class="p-6"> <Surface variant="default">
<Surface variant="default"> <form class="flex flex-col gap-4">
<form <TextField class="w-full" name="name" type="text">
:id="formId" <Label>姓名</Label>
class="flex flex-col gap-4" <Input placeholder="输入你的姓名"></Input>
@submit.prevent="submit" </TextField>
> <TextField class="w-full" name="email" type="email">
<TextField class="w-full" name="name" type="text"> <Label>邮箱</Label>
<Label>姓名</Label> <Input placeholder="输入你的邮箱"></Input>
<Input placeholder="输入你的姓名"></Input> </TextField>
</TextField> <TextField class="w-full" name="phone" type="tel">
<TextField class="w-full" name="email" type="email"> <Label>电话</Label>
<Label>邮箱</Label> <Input placeholder="输入你的电话号码"></Input>
<Input placeholder="输入你的邮箱"></Input> </TextField>
</TextField> <TextField class="w-full" name="company">
<TextField class="w-full" name="phone" type="tel"> <Label>公司</Label>
<Label>电话</Label> <Input placeholder="输入公司名称"></Input>
<Input placeholder="输入你的电话号码"></Input> </TextField>
</TextField> <TextField class="w-full" name="message">
<TextField class="w-full" name="company"> <Label>留言</Label>
<Label>公司</Label> <Input placeholder="输入留言内容"></Input>
<Input placeholder="输入公司名称"></Input> </TextField>
</TextField> </form>
<TextField class="w-full" name="message"> </Surface>
<Label>留言</Label> </ModalBody>
<Input placeholder="输入留言内容"></Input> <ModalFooter>
</TextField> <ModalClose as-child>
</form> <Button variant="secondary">取消</Button>
</Surface> </ModalClose>
</ModalBody> <ModalClose as-child>
<ModalFooter> <Button>发送消息</Button>
<ModalClose as-child> </ModalClose>
<Button variant="secondary">取消</Button> </ModalFooter>
</ModalClose> </ModalDialog>
<Button type="submit" :form="formId">发送消息</Button> </ModalContainer>
</ModalFooter> </ModalBackdrop>
</ModalDialog> </Modal>
</ModalContainer>
</ModalBackdrop>
</Modal>
<p v-if="result" role="status" class="mt-3 text-sm text-muted">
已记录表单:{{ result }}
</p>
</div>
</template> </template>
+4 -10
View File
@@ -14,8 +14,7 @@ import {
Spinner, Spinner,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
const value = ref<number | null>(null), const value = ref<number | null>(null),
isSubmitting = ref(false), isSubmitting = ref(false);
feedback = ref("");
const STOCK_AVAILABLE = 3; const STOCK_AVAILABLE = 3;
const isOutOfStock = computed( const isOutOfStock = computed(
() => value.value !== null && value.value > STOCK_AVAILABLE, () => value.value !== null && value.value > STOCK_AVAILABLE,
@@ -30,12 +29,11 @@ function submit() {
) )
return; return;
isSubmitting.value = true; isSubmitting.value = true;
feedback.value = ""; // Simulate API call
// Local demonstration only; no order or network request is created.
timer = setTimeout(() => { timer = setTimeout(() => {
console.log("Order submitted:", { quantity: value.value });
value.value = null; value.value = null;
isSubmitting.value = false; isSubmitting.value = false;
feedback.value = "模拟提交成功";
}, 1500); }, 1500);
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
@@ -43,10 +41,7 @@ onBeforeUnmount(() => {
}); });
</script> </script>
<template> <template>
<Form <Form class="flex w-[280px] flex-col gap-4" @submit.prevent="submit">
class="flex w-[280px] max-w-full flex-col gap-4"
@submit.prevent="submit"
>
<NumberField <NumberField
v-model="value" v-model="value"
is-required is-required
@@ -79,6 +74,5 @@ onBeforeUnmount(() => {
</template> </template>
<template v-else>下单</template> <template v-else>下单</template>
</Button> </Button>
<p v-if="feedback" role="status">{{ feedback }}</p>
</Form> </Form>
</template> </template>
+1 -1
View File
@@ -9,7 +9,7 @@ import {
} from "@heroui-vue/components"; } from "@heroui-vue/components";
</script> </script>
<template> <template>
<div class="w-[400px] max-w-full space-y-4"> <div class="w-[400px] space-y-4">
<NumberField fullWidth :defaultValue="1024" :minValue="0" name="width"> <NumberField fullWidth :defaultValue="1024" :minValue="0" name="width">
<Label>宽度</Label> <Label>宽度</Label>
<NumberFieldGroup> <NumberFieldGroup>
+1 -1
View File
@@ -52,6 +52,6 @@ function submit(event: Event) {
<FieldError>请先选择订阅套餐再继续。</FieldError> <FieldError>请先选择订阅套餐再继续。</FieldError>
</RadioGroup> </RadioGroup>
<Button class="mt-2 w-fit" type="submit">Submit</Button> <Button class="mt-2 w-fit" type="submit">Submit</Button>
<p v-if="result" role="status" class="text-sm">{{ result }}</p> <p v-if="result" role="status" class="text-sm text-muted">{{ result }}</p>
</Form> </Form>
</template> </template>
@@ -15,20 +15,17 @@ import { Form } from "@heroui-vue/components";
import { computed, onBeforeUnmount, ref } from "vue"; import { computed, onBeforeUnmount, ref } from "vue";
const value = ref(""); const value = ref("");
const isSubmitting = ref(false); const isSubmitting = ref(false);
const result = ref("");
const isInvalid = computed( const isInvalid = computed(
() => value.value.length > 0 && value.value.length < 3, () => value.value.length > 0 && value.value.length < 3,
); );
let timer: ReturnType<typeof setTimeout> | undefined; let timer: ReturnType<typeof setTimeout> | undefined;
onBeforeUnmount(() => clearTimeout(timer)); onBeforeUnmount(() => clearTimeout(timer));
function submit(event: Event) { function submit() {
if (value.value.length < 3 || isSubmitting.value) return; if (value.value.length < 3 || isSubmitting.value) return;
const query = new FormData(event.currentTarget as HTMLFormElement).get(
"search",
);
isSubmitting.value = true; isSubmitting.value = true;
// Simulate API call
timer = setTimeout(() => { timer = setTimeout(() => {
result.value = `已模拟提交搜索:${query}`; console.log("Search submitted:", { query: value.value });
value.value = ""; value.value = "";
isSubmitting.value = false; isSubmitting.value = false;
}, 1500); }, 1500);
@@ -65,6 +62,5 @@ function submit(event: Event) {
</template> </template>
<template v-else>搜索</template> <template v-else>搜索</template>
</Button> </Button>
<p v-if="result" role="status" class="text-sm text-muted">{{ result }}</p>
</Form> </Form>
</template> </template>
+4 -6
View File
@@ -14,12 +14,13 @@ import {
Button, Button,
Surface, Surface,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { ref } from "vue"; function submit() {
const submitted = ref(false); alert("表单提交成功!");
}
</script> </script>
<template> <template>
<Surface class="w-[320px] rounded-3xl p-6"> <Surface class="w-[320px] rounded-3xl p-6">
<Form class="flex w-full flex-col gap-4" @submit.prevent="submitted = true"> <Form class="flex w-full flex-col gap-4" @submit.prevent="submit">
<Select <Select
is-required is-required
class="w-full" class="w-full"
@@ -105,9 +106,6 @@ const submitted = ref(false);
<FieldError /> <FieldError />
</Select> </Select>
<Button type="submit">提交</Button> <Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-success">
表单提交成功!
</p>
</Form> </Form>
</Surface> </Surface>
</template> </template>
+4 -9
View File
@@ -13,14 +13,12 @@ import {
FieldError, FieldError,
Button, Button,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { ref } from "vue"; function submit() {
const submitted = ref(false); alert("表单提交成功!");
}
</script> </script>
<template> <template>
<Form <Form class="flex w-[256px] flex-col gap-4" @submit.prevent="submit">
class="flex w-[256px] flex-col gap-4"
@submit.prevent="submitted = true"
>
<Select is-required class="w-full" name="state" placeholder="请选择"> <Select is-required class="w-full" name="state" placeholder="请选择">
<Label>州</Label> <Label>州</Label>
<SelectTrigger> <SelectTrigger>
@@ -94,8 +92,5 @@ const submitted = ref(false);
<FieldError /> <FieldError />
</Select> </Select>
<Button type="submit">提交</Button> <Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-success">
表单提交成功!
</p>
</Form> </Form>
</template> </template>
+9 -21
View File
@@ -7,13 +7,13 @@ import {
SwitchGroup, SwitchGroup,
Button, Button,
} from "@heroui-vue/components"; } from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) { function submit(event: Event) {
const values = [...new FormData(event.target as HTMLFormElement).entries()]; const data = new FormData(event.currentTarget as HTMLFormElement);
result.value = values.length alert(
? "表单提交内容:" + values.map(([k, v]) => `${k}: ${v}`).join(",") `表单提交内容:\n${Array.from(data)
: "未选择任何选项"; .map(([key, value]) => `${key}: ${value}`)
.join("\n")}`,
);
} }
</script> </script>
<template> <template>
@@ -38,20 +38,8 @@ function submit(event: Event) {
</SwitchContent> </SwitchContent>
</Switch> </Switch>
</SwitchGroup> </SwitchGroup>
<div class="flex gap-2"> <Button class="mt-4" size="sm" type="submit" variant="primary">
<Button class="mt-4" size="sm" type="submit">Submit</Button> Submit
<Button </Button>
class="mt-4"
size="sm"
type="reset"
variant="secondary"
@click="result = ''"
>
重置
</Button>
</div>
<output v-if="result" class="text-sm text-muted" aria-live="polite">
{{ result }}
</output>
</form> </form>
</template> </template>
+2 -6
View File
@@ -30,14 +30,13 @@ const isInvalid = computed(() => {
}); });
import { onBeforeUnmount } from "vue"; import { onBeforeUnmount } from "vue";
const isSubmitting = shallowRef(false); const isSubmitting = shallowRef(false);
const submitted = shallowRef("");
let timer: ReturnType<typeof setTimeout> | undefined; let timer: ReturnType<typeof setTimeout> | undefined;
function submit() { function submit() {
if (!value.value || isInvalid.value || isSubmitting.value) return; if (!value.value || isInvalid.value || isSubmitting.value) return;
const payload = value.value.toString();
isSubmitting.value = true; isSubmitting.value = true;
// Simulate API call
timer = setTimeout(() => { timer = setTimeout(() => {
submitted.value = payload; console.log("Time submitted:", { time: value.value });
value.value = null; value.value = null;
isSubmitting.value = false; isSubmitting.value = false;
}, 1500); }, 1500);
@@ -78,8 +77,5 @@ onBeforeUnmount(() => clearTimeout(timer));
> >
{{ isSubmitting ? "提交中…" : "提交" }} {{ isSubmitting ? "提交中…" : "提交" }}
</Button> </Button>
<output v-if="submitted" class="text-sm text-muted">
已提交:{{ submitted }}
</output>
</Form> </Form>
</template> </template>
+1 -1
View File
@@ -21,7 +21,7 @@ function show() {
</script> </script>
<template> <template>
<div class="flex flex-col gap-3"> <div class="flex h-full max-w-xl flex-col items-center justify-center">
<Button size="sm" variant="secondary" @click="show">自定义指示器</Button> <Button size="sm" variant="secondary" @click="show">自定义指示器</Button>
<ToastProvider :queue="queue" to="body" /> <ToastProvider :queue="queue" to="body" />
</div> </div>
+47 -43
View File
@@ -11,51 +11,55 @@ onBeforeUnmount(() =>
); );
</script> </script>
<template> <template>
<div <div class="flex h-full max-w-4xl items-center justify-center gap-4">
class="flex h-full max-w-4xl flex-wrap items-center justify-center gap-4"
>
<Button
size="sm"
variant="secondary"
@click="
notificationQueue.add({
title: '新通知',
description: '您有一条新消息',
variant: 'default',
})
"
>
添加通知(最多 2 条)
</Button>
<Button
size="sm"
variant="danger-soft"
@click="
errorQueue.add({
title: '发生错误',
description: '保存更改失败',
variant: 'danger',
})
"
>
添加错误(最多 3 条)
</Button>
<Button
size="sm"
variant="secondary"
class="text-success"
@click="
successQueue.add({
title: '成功!',
description: `操作 ${Date.now()}`,
variant: 'success',
})
"
>
添加成功(最多 1 条)
</Button>
<ToastProvider :queue="notificationQueue" to="body" placement="bottom" /> <ToastProvider :queue="notificationQueue" to="body" placement="bottom" />
<div class="flex justify-center gap-2">
<Button
size="sm"
variant="secondary"
@click="
notificationQueue.add({
title: '新通知',
description: '您有一条新消息',
variant: 'default',
})
"
>
添加通知(最多 2 条)
</Button>
</div>
<ToastProvider :queue="errorQueue" to="body" placement="bottom start" /> <ToastProvider :queue="errorQueue" to="body" placement="bottom start" />
<div class="flex justify-center gap-2">
<Button
size="sm"
variant="danger-soft"
@click="
errorQueue.add({
title: '发生错误',
description: '保存更改失败',
variant: 'danger',
})
"
>
添加错误(最多 3 条)
</Button>
</div>
<ToastProvider :queue="successQueue" to="body" placement="bottom end" /> <ToastProvider :queue="successQueue" to="body" placement="bottom end" />
<div class="flex justify-center gap-2">
<Button
size="sm"
variant="secondary"
class="text-success"
@click="
successQueue.add({
title: '成功!',
description: `操作 ${Date.now()}`,
variant: 'success',
})
"
>
添加成功(最多 1 条)
</Button>
</div>
</div> </div>
</template> </template>
+27 -21
View File
@@ -11,26 +11,32 @@ const toast = createToastFunction(queue);
onBeforeUnmount(() => queue.destroy()); onBeforeUnmount(() => queue.destroy());
</script> </script>
<template> <template>
<div class="flex h-full max-w-xl flex-wrap items-center justify-center gap-4"> <div class="flex h-full max-w-xl flex-col items-center justify-center">
<Button size="sm" variant="secondary" @click="toast('简单消息')"> <div class="flex w-full flex-wrap items-center justify-center gap-4">
默认 <Button size="sm" variant="secondary" @click="toast('简单消息')">
</Button> 默认
<Button size="sm" variant="secondary" @click="toast.success('操作已完成')"> </Button>
成功 <Button
</Button> size="sm"
<Button size="sm" variant="secondary" @click="toast.info('有新更新可用')"> variant="secondary"
信息 @click="toast.success('操作已完成')"
</Button> >
<Button 成功
size="sm" </Button>
variant="secondary" <Button size="sm" variant="secondary" @click="toast.info('有新更新可用')">
@click="toast.warning('请检查您的设置')" 信息
> </Button>
警告 <Button
</Button> size="sm"
<Button size="sm" variant="secondary" @click="toast.danger('出了点问题')"> variant="secondary"
错误 @click="toast.warning('请检查您的设置')"
</Button> >
<ToastProvider :queue="queue" to="body" /> 警告
</Button>
<Button size="sm" variant="secondary" @click="toast.danger('出了点问题')">
错误
</Button>
<ToastProvider :queue="queue" to="body" />
</div>
</div> </div>
</template> </template>
+27 -25
View File
@@ -62,7 +62,7 @@ function show(v: (typeof variants)[number]["key"]) {
actionProps: { actionProps: {
label: item.action, label: item.action,
variant: variant:
v === "danger" ? "danger" : v === "default" ? "tertiary" : "secondary", v === "danger" ? "danger" : v === "default" ? "tertiary" : undefined,
class: class:
v === "success" v === "success"
? "bg-success text-success-foreground" ? "bg-success text-success-foreground"
@@ -75,29 +75,31 @@ function show(v: (typeof variants)[number]["key"]) {
</script> </script>
<template> <template>
<div class="flex flex-wrap gap-3"> <div class="flex h-full max-w-xl flex-col items-center justify-center">
<Button <div class="flex w-full flex-wrap items-center justify-center gap-4">
v-for="v in variants" <Button
:key="v.key" v-for="v in variants"
size="sm" :key="v.key"
:variant=" size="sm"
v.key === 'danger' :variant="
? 'danger-soft' v.key === 'danger'
: v.key === 'accent' ? 'danger-soft'
? 'secondary' : v.key === 'accent'
: 'tertiary' ? 'secondary'
" : 'tertiary'
:class=" "
v.key === 'success' :class="
? 'text-success' v.key === 'success'
: v.key === 'warning' ? 'text-success'
? 'text-warning' : v.key === 'warning'
: undefined ? 'text-warning'
" : undefined
@click="show(v.key)" "
> @click="show(v.key)"
{{ v.label }} >
</Button> {{ v.label }}
<ToastProvider :queue="queue" to="body" /> </Button>
<ToastProvider :queue="queue" to="body" />
</div>
</div> </div>
</template> </template>
+2 -2
View File
@@ -169,7 +169,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
## LISTBOX-01(2026-10-23) ## LISTBOX-01(2026-10-23)
固定 ce90ea3 的 list-box / list-box-item / list-box-section 源码、CSS/tv,以及中文正文和九个预览。CSS/tv 按 hv- 移植,源勾选图形遵循原 Apache-2.0;文档图标用现有 Tabler Vue。原 alert 演示改为内联状态反馈,React render 改 as/插槽,Virtualizer/ListLayout 改 VueUse 固定行高虚拟化。依据、差异与限制见 [LISTBOX-01](component-notes.md)。 固定 ce90ea3 的 list-box / list-box-item / list-box-section 源码、CSS/tv,以及中文正文和九个预览。CSS/tv 按 hv- 移植,源勾选图形遵循原 Apache-2.0;文档图标用现有 Tabler Vue。原 alert 演示曾改为内联状态反馈(2026-10-28 HD-02 已按固定基线恢复为 alert 反馈与原结构),React render 改 as/插槽,Virtualizer/ListLayout 改 VueUse 固定行高虚拟化。依据、差异与限制见 [LISTBOX-01](component-notes.md)。
## M33–M34(2026-10-23) ## M33–M34(2026-10-23)
@@ -327,7 +327,7 @@ CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`colorPickerVariants` 保持
## FORM(2026-10-27) ## FORM(2026-10-27)
固定 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/form/{form.tsx,index.ts}`、中文 `(forms)/form.mdx` 与 `apps/docs/src/demos/cn/form/{basic,render-function,custom-styles}.tsx`。源无专用CSS/variants;复用已有字段样式。保留3例布局、文案、验证规则与字段,render添加data-custom改为Vue attrs、Gravity Check图标用Tabler IconCheck、alert提交反馈改页内status、增加max-w-full适应窄屏;差异见 [Form文档](../apps/docs/components/form.md)。 固定 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`:`packages/react/src/components/form/{form.tsx,index.ts}`、中文 `(forms)/form.mdx` 与 `apps/docs/src/demos/cn/form/{basic,render-function,custom-styles}.tsx`。源无专用CSS/variants;复用已有字段样式。保留3例布局、文案、验证规则与字段,render添加data-custom改为Vue attrs、Gravity Check图标用Tabler IconCheck;alert提交反馈曾改页内status、增加max-w-full(2026-10-28 HD-02 已按固定基线恢复 alert 反馈并移除该宽度守卫);差异见 [Form文档](../apps/docs/components/form.md)。
## HANDBOOK-IMPLEMENTATION-AUDIT(2026-10-27) ## HANDBOOK-IMPLEMENTATION-AUDIT(2026-10-27)
@@ -9,11 +9,13 @@ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: { props: {
isDisabled: { type: Boolean, default: false }, isDisabled: { type: Boolean, default: false },
// Upstream ToastActionButton renders a plain Button without variant/size
// overrides, so these fall back to the Button defaults (primary / md).
variant: { variant: {
type: String as PropType<ButtonVariants["variant"]>, type: String as PropType<ButtonVariants["variant"]>,
default: "secondary", default: "primary",
}, },
size: { type: String as PropType<ButtonVariants["size"]>, default: "sm" }, size: { type: String as PropType<ButtonVariants["size"]>, default: "md" },
}, },
setup(props, { slots }) { setup(props, { slots }) {
const attrs = useAttrs(); const attrs = useAttrs();
+19 -3
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest"; import { describe, it, expect, vi } from "vitest";
import { mount } from "@vue/test-utils"; import { mount } from "@vue/test-utils";
import { h, nextTick, ref } from "vue"; import { h, nextTick, ref } from "vue";
import { readFileSync } from "node:fs"; import { readFileSync } from "node:fs";
@@ -89,6 +89,7 @@ describe("aligned examples", () => {
w.unmount(); w.unmount();
}); });
it("submits actual selected values and restores Switch defaults on form reset", async () => { it("submits actual selected values and restores Switch defaults on form reset", async () => {
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(SwitchForm, { attachTo: document.body }); const w = mount(SwitchForm, { attachTo: document.body });
const form = w.get("form").element as HTMLFormElement; const form = w.get("form").element as HTMLFormElement;
const switches = w.findAll("[role=switch]"); const switches = w.findAll("[role=switch]");
@@ -98,13 +99,19 @@ describe("aligned examples", () => {
expect(new FormData(form).get("notifications")).toBe("on"); expect(new FormData(form).get("notifications")).toBe("on");
expect(new FormData(form).has("newsletter")).toBe(false); expect(new FormData(form).has("newsletter")).toBe(false);
await w.get("form").trigger("submit"); await w.get("form").trigger("submit");
expect(w.get("output").text()).toContain("notifications: on"); // Baseline feedback: one alert carrying the real submitted entries.
expect(alert).toHaveBeenCalledTimes(1);
expect(alert.mock.calls[0][0]).toContain("表单提交内容:");
expect(alert.mock.calls[0][0]).toContain("notifications: on");
expect(alert.mock.calls[0][0]).not.toContain("newsletter");
expect(w.find("output").exists()).toBe(false);
form.reset(); form.reset();
await nextTick(); await nextTick();
await nextTick(); await nextTick();
expect(switches[0].attributes("aria-checked")).toBe("false"); expect(switches[0].attributes("aria-checked")).toBe("false");
expect(switches[1].attributes("aria-checked")).toBe("true"); expect(switches[1].attributes("aria-checked")).toBe("true");
w.unmount(); w.unmount();
alert.mockRestore();
}); });
it("passes root ARIA attributes into composed SwitchContent and preserves container styles", async () => { it("passes root ARIA attributes into composed SwitchContent and preserves container styles", async () => {
const name = ref("静音"); const name = ref("静音");
@@ -169,12 +176,21 @@ describe("aligned examples", () => {
w.unmount(); w.unmount();
}); });
it("renders a working Card form using labelled native fields", async () => { it("renders a working Card form using labelled native fields", async () => {
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(CardForm); const w = mount(CardForm);
expect(w.findAll("label")).toHaveLength(2); expect(w.findAll("label")).toHaveLength(2);
// Baseline has no added required validation: the empty form submits too.
await w.get("form").trigger("submit");
expect(alert).toHaveBeenCalledWith("表单提交成功!");
expect(w.find("[role=status]").exists()).toBe(false);
await w.get("input[type=email]").setValue("test@example.com"); await w.get("input[type=email]").setValue("test@example.com");
await w.get("input[type=password]").setValue("test-pass"); await w.get("input[type=password]").setValue("test-pass");
await w.get("form").trigger("submit"); await w.get("form").trigger("submit");
expect(w.get("[role=status]").text()).toContain("表单提交成功"); expect(alert).toHaveBeenCalledTimes(2);
expect(
new FormData(w.get("form").element as HTMLFormElement).get("email"),
).toBe("test@example.com");
w.unmount(); w.unmount();
alert.mockRestore();
}); });
}); });
+31 -8
View File
@@ -82,7 +82,13 @@ describe("Autocomplete docs and demos", () => {
expect(source, name).toContain("SearchFieldClearButton"); expect(source, name).toContain("SearchFieldClearButton");
// The ported .hv-empty-state padding must not be overridden per demo. // The ported .hv-empty-state padding must not be overridden per demo.
expect(source, name).not.toMatch(/<EmptyState\s+class=/); expect(source, name).not.toMatch(/<EmptyState\s+class=/);
expect(source, name).not.toContain("alert("); // Baseline feedback: only the required demo submits through the plain
// success alert, exactly like the pinned cn source.
if (name === "required") {
expect(source, name).toContain('alert("表单提交成功!")');
} else {
expect(source, name).not.toContain("alert(");
}
} }
}); });
@@ -170,11 +176,12 @@ describe("Autocomplete docs and demos", () => {
} }
}); });
it("submits the required and name demos", async () => { it("blocks empty required submits and keeps the baseline success alert", async () => {
const formDemo = const formDemo =
(await import("../apps/docs/demos/autocomplete-required.vue")) as { (await import("../apps/docs/demos/autocomplete-required.vue")) as {
default: Component; default: Component;
}; };
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const wrapper = mount(formDemo.default, { attachTo: document.body }); const wrapper = mount(formDemo.default, { attachTo: document.body });
mounted.push(wrapper); mounted.push(wrapper);
await nextTick(); await nextTick();
@@ -191,20 +198,36 @@ describe("Autocomplete docs and demos", () => {
false, false,
); );
// `Form` renders novalidate and guards submit itself: an empty required // `Form` renders novalidate and guards submit itself: an empty required
// field must keep the demo's status line empty. // field must keep the demo's baseline alert silent.
const form = pickerForm; const form = pickerForm;
const submit = ( const submit = (
wrapper.element as HTMLElement wrapper.element as HTMLElement
).querySelector<HTMLButtonElement>('button[type="submit"]')!; ).querySelector<HTMLButtonElement>('button[type="submit"]')!;
submit.click(); submit.click();
await nextTick(); await nextTick();
await settle();
expect(form.getAttribute("novalidate")).not.toBeNull(); expect(form.getAttribute("novalidate")).not.toBeNull();
expect( expect(alert).not.toHaveBeenCalled();
(wrapper.element as HTMLElement) // Choose a value in both required pickers: the valid submit then fires
.querySelector('[role="status"]') // the plain baseline success alert (cn/autocomplete/required.tsx).
?.textContent?.trim() ?? "", for (const trigger of root.querySelectorAll<HTMLElement>(
).toBe(""); '[data-slot="autocomplete-trigger"]',
)) {
trigger.dispatchEvent(new MouseEvent("click", { bubbles: true }));
await nextTick();
await settle();
const option = document.querySelector<HTMLElement>('[role="option"]')!;
option.click();
await nextTick();
await settle();
}
submit.click();
await nextTick();
await settle();
expect(alert).toHaveBeenCalledTimes(1);
expect(alert).toHaveBeenCalledWith("表单提交成功!");
wrapper.unmount(); wrapper.unmount();
mounted.pop(); mounted.pop();
alert.mockRestore();
}); });
}); });
+6 -3
View File
@@ -458,19 +458,22 @@ it("keeps the baseline preview inventories and exact fieldset submission feedbac
).toContain("<template>"); ).toContain("<template>");
const { default: Demo } = const { default: Demo } =
await import("../apps/docs/demos/fieldset-basic.vue"); await import("../apps/docs/demos/fieldset-basic.vue");
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(Demo, { attachTo: document.body }); const w = mount(Demo, { attachTo: document.body });
await w.get("input[name=name]").setValue("Jane"); await w.get("input[name=name]").setValue("Jane");
await w.get("input[name=email]").setValue("jane@example.com"); await w.get("input[name=email]").setValue("jane@example.com");
await w.get("textarea").setValue("A detailed biography."); await w.get("textarea").setValue("A detailed biography.");
(w.get("form").element as HTMLFormElement).requestSubmit(); (w.get("form").element as HTMLFormElement).requestSubmit();
await settle(); await settle();
const status = w.get('[role="status"]'); // Baseline feedback: the plain success alert, no inline result row.
expect(status.text()).toContain('"name":"Jane"'); expect(alert).toHaveBeenCalledTimes(1);
expect(status.text()).toContain('"email":"jane@example.com"'); expect(alert).toHaveBeenCalledWith("表单提交成功!");
expect(w.find('[role="status"]').exists()).toBe(false);
await w.get('button[type="reset"]').trigger("click"); await w.get('button[type="reset"]').trigger("click");
await settle(); await settle();
expect((w.get("input[name=name]").element as HTMLInputElement).value).toBe( expect((w.get("input[name=name]").element as HTMLInputElement).value).toBe(
"", "",
); );
alert.mockRestore();
w.unmount(); w.unmount();
}); });
+9 -10
View File
@@ -242,8 +242,9 @@ describe("Form public validation", () => {
describe("Form fixed-source demos", () => { describe("Form fixed-source demos", () => {
it.each([FormBasic, FormRenderFunction])( it.each([FormBasic, FormRenderFunction])(
"validates both fields, submits exact data, and resets values/errors/results", "validates both fields, submits exact data via the baseline alert, and resets values/errors",
async (Demo) => { async (Demo) => {
const alert = vi.spyOn(window, "alert").mockImplementation(() => {});
const w = mount(Demo, { attachTo: document.body }); const w = mount(Demo, { attachTo: document.body });
wrappers.push(w); wrappers.push(w);
const form = w.get("form").element as HTMLFormElement; const form = w.get("form").element as HTMLFormElement;
@@ -268,19 +269,17 @@ describe("Form fixed-source demos", () => {
submit(form); submit(form);
await settle(); await settle();
expect(w.get("[data-slot=field-error]").text()).toBe(error); expect(w.get("[data-slot=field-error]").text()).toBe(error);
expect(w.find('[role="status"]').exists()).toBe(false); expect(alert).not.toHaveBeenCalled();
} }
await password.setValue("Password1"); await password.setValue("Password1");
await settle(); await settle();
submit(form); submit(form);
await settle(); await settle();
expect(w.get('[role="status"]').text()).toContain("表单提交数据:"); expect(alert).toHaveBeenCalledTimes(1);
expect(w.get('[role="status"]').text()).toContain( const message = alert.mock.calls[0][0] as string;
'"email": "john@example.com"', expect(message).toContain("表单提交数据:");
); expect(message).toContain('"email": "john@example.com"');
expect(w.get('[role="status"]').text()).toContain( expect(message).toContain('"password": "Password1"');
'"password": "Password1"',
);
expect([...new FormData(form)]).toEqual([ expect([...new FormData(form)]).toEqual([
["email", "john@example.com"], ["email", "john@example.com"],
["password", "Password1"], ["password", "Password1"],
@@ -290,8 +289,8 @@ describe("Form fixed-source demos", () => {
expect((email.element as HTMLInputElement).value).toBe(""); expect((email.element as HTMLInputElement).value).toBe("");
expect((password.element as HTMLInputElement).value).toBe(""); expect((password.element as HTMLInputElement).value).toBe("");
expect(w.find("[data-slot=field-error]").exists()).toBe(false); expect(w.find("[data-slot=field-error]").exists()).toBe(false);
expect(w.find('[role="status"]').exists()).toBe(false);
if (Demo === FormRenderFunction) expect(form.dataset.custom).toBe("foo"); if (Demo === FormRenderFunction) expect(form.dataset.custom).toBe("foo");
alert.mockRestore();
}, },
); );
+5 -1
View File
@@ -445,7 +445,11 @@ describe("M12 demo inventory", () => {
"utf8", "utf8",
); );
expect(textarea).toContain("InputGroupTextArea"); expect(textarea).toContain("InputGroupTextArea");
expect(textarea).not.toContain("Tooltip"); // Baseline tooltip contract: the four tooltips are restored (with the
// Enter Kbd hint on the send action) instead of native title attributes.
expect(textarea.match(/<Tooltip\b/g) ?? []).toHaveLength(4);
expect(textarea).toContain('key-value="enter"');
expect(textarea).not.toContain('title="');
}); });
}); });
+10 -5
View File
@@ -64,7 +64,7 @@ it("matches the exact baseline 14/6/6 preview inventory and compiles/mounts thei
} }
}); });
it("submits real form data and reports it without pretending to send a network message", async () => { it("keeps the baseline close-only footer and real named form fields", async () => {
const demo = demos["../apps/docs/demos/modal-with-form.vue"] as Component; const demo = demos["../apps/docs/demos/modal-with-form.vue"] as Component;
const w = mount(demo, { attachTo: document.body }); const w = mount(demo, { attachTo: document.body });
try { try {
@@ -78,12 +78,17 @@ it("submits real form data and reports it without pretending to send a network m
field.dispatchEvent(new Event("input", { bubbles: true })); field.dispatchEvent(new Event("input", { bubbles: true }));
const form = document.querySelector("form")!; const form = document.querySelector("form")!;
expect(new FormData(form).get("name")).toBe("Vue用户"); expect(new FormData(form).get("name")).toBe("Vue用户");
form.dispatchEvent( // Baseline contract: the footer buttons only close the dialog — the
new Event("submit", { bubbles: true, cancelable: true }), // example performs no submit and renders no result row.
); const send = [
...document.querySelectorAll<HTMLButtonElement>("button"),
].find((button) => button.textContent?.trim() === "发送消息")!;
expect(send).toBeDefined();
send.click();
await flushPromises(); await flushPromises();
expect(w.get("[role=status]").text()).toContain("Vue用户");
expect(document.querySelector("[role=dialog]")).toBeNull(); expect(document.querySelector("[role=dialog]")).toBeNull();
expect(w.find("[role=status]").exists()).toBe(false);
expect(w.text()).not.toContain("已记录表单");
} finally { } finally {
w.unmount(); w.unmount();
await flushPromises(); await flushPromises();
+11 -2
View File
@@ -72,10 +72,11 @@ describe("TimeField documentation", () => {
w.unmount(); w.unmount();
} }
}); });
it("validates business hours and submits the actual value with loading/reset feedback", async () => { it("validates business hours and submits the actual value with baseline console feedback", async () => {
const w = mount( const w = mount(
demos["../apps/docs/demos/time-field-form-example.vue"] as never, demos["../apps/docs/demos/time-field-form-example.vue"] as never,
); );
const log = vi.spyOn(console, "log").mockImplementation(() => {});
try { try {
const input = w.get('[data-slot="time-field-value"]'); const input = w.get('[data-slot="time-field-value"]');
await input.setValue("08:30"); await input.setValue("08:30");
@@ -94,12 +95,20 @@ describe("TimeField documentation", () => {
await w.get("form").trigger("submit"); await w.get("form").trigger("submit");
expect(w.get("button").text()).toBe("提交中…"); expect(w.get("button").text()).toBe("提交中…");
await vi.advanceTimersByTimeAsync(1500); await vi.advanceTimersByTimeAsync(1500);
expect(w.get("output").text()).toBe("已提交:14:30:45"); // Baseline feedback: the submitted time is logged to the console and
// the field clears; there is no inline output row.
expect(log).toHaveBeenCalledTimes(1);
expect(log.mock.calls[0][0]).toBe("Time submitted:");
expect(String((log.mock.calls[0][1] as { time: unknown }).time)).toBe(
"14:30:45",
);
expect(w.find("output").exists()).toBe(false);
expect((input.element as HTMLInputElement).value).toBe(""); expect((input.element as HTMLInputElement).value).toBe("");
expect(w.get('[data-type="hour"]').attributes("data-placeholder")).toBe( expect(w.get('[data-type="hour"]').attributes("data-placeholder")).toBe(
"true", "true",
); );
} finally { } finally {
log.mockRestore();
w.unmount(); w.unmount();
} }
}); });