Files

22 KiB
Raw Permalink Blame History

01-buttons 组差异报告(button / button-group / close-button / toggle-button / toggle-button-group)

基线:上游 heroui/(HeroUI 3.2.6 / ce90ea3)vs heroui-vue/。路径均相对工作区根。 示例对比以 heroui/apps/docs/src/demos/cn/<component>/<demo>.tsx 为中文内容基准。

组级通用说明(适用于多个组件,不重复列入各组件)

  • [示例] 图标库:上游 @gravity-ui/icons(social 用 Iconify)→ Vue @tabler/icons-vue,属既定约定,多数等义映射(Heart→IconHeart、Bold→IconBold、ChevronDown→IconChevronDown 等)。个别语义变化见 button/button-group 条目(Globe→IconSearch)。
  • [示例] 布局容器类系统性替换:上游示例根类(flex flex-wrap gap-3、flex items-center gap-3、flex gap-3、flex flex-col items-start gap-2 等)在 Vue 统一换为 demo-row(heroui-vue/apps/docs/.vitepress/theme/style.css:241:flex + flex-wrap + items-center + justify-center + gap 12px + width 100%),造成对齐(居中 vs 左对齐)、换行(上游 button-sizes flex items-center gap-3 不换行)与 items-start 缺失的可见差异。Vue 的 Demo.vue 外层已有一层 demo-row,示例内再套一层。
  • [示例] 英文文案问题(严重):button-group-*、toggle-button-*、toggle-button-group-* 示例沿用上游 en 演示文案(First/Second/Third、Small/Medium (default)、Like、Search/Add/Delete 等),而 cn 基线为 第一项/第二项/第三项、小/中(默认)/大、点赞、搜索/添加/删除 等。button-*、close-button-* 示例中文文案保持正确。
  • [样式] 五个组件 CSS 与 tv 映射逐行一致(仅 hv- 前缀、许可头、换行格式差异),无 CSS/配色/动画硬差异:heroui/packages/styles/components/{button,button-group,close-button,toggle-button,toggle-button-group}.css ↔ heroui-vue/packages/styles/components/*.css;heroui/packages/styles/src/components/*/*.styles.ts ↔ heroui-vue/packages/styles/src/index.ts(buttonVariants/closeButtonVariants/buttonGroupVariants/toggleButtonVariants/toggleButtonGroupVariants 的键与类名完全对应)。/tmp/audit/css_semantic2.txt 中本组 5 个 CSS 无条目,人工 diff 复核通过。

button

  • [示例] button-basic:上游 heroui/apps/docs/src/demos/cn/button/basic.tsx 为 <Button onPress={() => console.log("按钮已按下")}>点我</Button>(UI 恒为"点我");Vue heroui-vue/apps/docs/demos/button-basic.vue 点击后把按钮文案改为"按钮已按下"(不可逆、无 console)。属交互行为 + 可见文案差异(按简报 A 记为内容/行为差异)。
  • [示例] button-loading-state:Vue 新增状态段落 上传完成,可以再次上传。(<p class="upload-status" role="status">,上游 loading-state.tsx 只有一个按钮),且 if (isLoading.value) return 屏蔽加载中重复点击;上游每次按下都重启 2 秒定时器、无提示文本。
  • [示例] button-ripple-effect:上游用 m3-ripple 包(<Ripple /> + m3-ripple/ripple.css);Vue 自实现波纹(button-ripple-effect.vue:pointerdown/Enter/Space 触发,@keyframes button-ripple 0.6s ease-out、background: currentColor; opacity: 0.18、reduced-motion 时 1ms)。文档已声明替换,但视觉/触发动效不同(动画差异)。
  • [示例] button-custom-variants:base 首个类上游 text-md vs Vue text-base(heroui/apps/docs/src/demos/cn/button/custom-variants.tsx vs heroui-vue/apps/docs/demos/button-custom-variants.vue);Vue defaultVariants 多 size: "md"(与上游默认等效)。其余 tv 扩展(radius/size/variant 映射)一致。
  • [示例] button-custom-styles:Vue 类串尾部多 motion-reduce:transition-none;上游把 gradient-border 作为全局 @utility 写在注释里,Vue 改为 scoped style 展示(展示代码不同,视觉相同)。
  • [示例] button-with-icons:上游"搜索"配 <Globe />(gravity-ui),Vue 用 IconSearch(button-with-icons.vue),图标语义不同;其余 IconUserPlus/IconMail/IconTrash ↔ Plus/Envelope/TrashBin 等义。
  • [API] 变体集合(上游文档自相矛盾,已核实):heroui/apps/docs/content/docs/{cn,en}/react/components/(buttons)/button.mdx API 表只列 'primary'|'secondary'|'tertiary'|'outline'|'ghost'|'danger'(6 个),其"样式参考 > 变体类"清单也漏 .button--danger-soft;但上游 heroui/packages/styles/src/components/button/button.styles.ts:28 与 heroui/packages/styles/components/button.css:136 都有 danger-soft,且两边 button-variants 示例都渲染 7 个变体(含"柔和危险")。Vue heroui-vue/apps/docs/components/button.md:114 列 7 个变体,与双方实现一致。结论:上游文档遗漏 danger-soft,Vue 文档更完整,非 Vue 与上游实现差异。
  • [API] Vue 多 asChild、type(默认 'button')两行;type 与 RAC Button 默认是否一致(待核实)。onPress/children/render → @click/默认作用域插槽/asChild 属框架映射。Vue 另有 disabled、loading 兼容别名(loading 自动插入旋转 Spinner,见 heroui-vue/packages/vue/src/components/button/Button.vue),上游无对应能力(Vue 文档已声明为扩展)。
  • [API] 作用域插槽状态 6 项(isPending/isPressed/isHovered/isFocused/isFocusVisible/isDisabled)与上游 Render Props 表一致,无差异。
  • [文档] heroui-vue/apps/docs/components/button.md:102 的"样式参考"只有一段摘要,缺上游完整 CSS 类清单(基础与尺寸类 / 变体类 / 修饰符类,button.mdx:131-148);上游 ## 相关案例 <RelatedShowcases component="Button" />(button.mdx:189-191)在 Vue 整节缺失。上游"全局 CSS"示例 .button/.button--icon-only(@apply bg-purple-500…、bg-blue-500)被 Vue 换成 .hv-button--primary { --button-bg: oklch(0.6 0.2 300); }(手法、颜色不同)。上游 API 表另有 ## 相关组件 由 <RelatedComponents component="button"> 生成(heroui/apps/docs/src/components-registry.ts button: ["popover","tooltip","form",…] 前 3 = Popover/Tooltip/Form),Vue 固定为 Card/Input/Switch。
  • [实现] 上下文合并双方同为"直接子按钮、显式 props 优先、isDisabled={false} 可覆盖组禁用"(heroui/packages/react/src/components/button/button.tsx isDisabled ?? ctx ↔ heroui-vue/packages/vue/src/components/button/Button.vue explicitDisabled ?? groupDisabled,注释写明 Upstream nullish precedence)。Vue 在 pending 时额外输出 aria-busy,并用 click capture 拦截 pending/disabled 点击;上游依赖 RAC isPending(其 data 属性组合待核实,CSS 双方均按 [data-pending] / [aria-disabled] 上色)。
  • [动画] 除 ripple 外无差异(transition: transform 250ms var(--ease-smooth)… 等逐行一致)。
  • [配色] 无差异。

button-group

  • [示例] button-group-basic:上游 heroui/apps/docs/src/demos/cn/button-group/basic.tsx 是 GitHub 风格大示例——合并按钮 + Dropdown(3 个菜单项,含"创建合并提交/压缩并合并/变基并合并"及中文 Description)、复刻/扫码支付/点赞(2.4K)/星标(Chip 104)/已置顶、上一页/下一页、照片/视频、文本对齐、仅图标对齐共 9 组,含 Chip、Label、Description、13 个图标;Vue heroui-vue/apps/docs/demos/button-group-basic.vue 仅 <Button>First/Second/Third</Button> 3 个按钮。示例内容几乎全部缺失(最严重差异)。
  • [示例] button-group-variants:上游 6 组,组标签"主要/次要/第三/线框/幽灵/危险"、按钮"第一项/第二项/第三项";Vue 用 v-for 输出 {{ variant }}(渲染为小写 "primary/secondary/…",连 en 版 "Primary" 都不同)+ First/Second/Third;标签类 text-sm text-muted → text-sm font-medium text-muted,根 flex flex-col gap-6 → flex w-full flex-col gap-6。
  • [示例] button-group-sizes:标签"小/中(默认)/大" → "Small/Medium (default)/Large";Vue 丢掉 variant="secondary"(上游 ButtonGroup size=... variant="secondary"),组按钮从次要变体变成默认 primary(可见视觉差异);根容器 gap-4 → gap-6。
  • [示例] button-group-orientation:上游为带标签"横向/纵向"的两组仅图标对齐按钮(aria-label 左对齐/居中对齐/右对齐/两端对齐,variant="tertiary",flex items-start gap-8);Vue 是无标签的两组 First/Second/Third 文本按钮、无 variant、外层 demo-row。
  • [示例] button-group-with-icons:标签/按钮文案"带图标/仅图标按钮"、"搜索/添加/删除"(含 aria-label)→ "With icons/Icon only buttons"、"Search/Add/Delete";内层 flex flex-col items-start gap-2 → flex flex-col gap-2。
  • [示例] button-group-full-width:上游两组(文本组 + 仅图标对齐组)位于 w-[400px] space-y-3;Vue 只剩文本一组、w-full max-w-md(缺失第二组)。
  • [示例] button-group-disabled:上游两组,第二组演示组禁用 + <Button isDisabled={false}> 覆盖("第三项(可用)"、"组已禁用,但单个按钮可覆盖");Vue 仅一组全禁用(First/Second/Third),覆盖示例被删除。
  • [示例] button-group-without-separator:结构一致,文案 第一项/第二项/第三项 → First/Second/Third。
  • [示例] button-group-custom-styles:上游是自定义合并下拉(按钮 rounded-none bg-[#08872B] data-hovered:bg-[#0FBF3E]、Dropdown 3 菜单项中文 Label+Description、ChevronDown、max-w-[290px] rounded-none);Vue 是 ButtonGroup class="gap-2 rounded-lg" + 3 个 class="rounded-lg" 按钮 + opacity-25 分隔线。结构、内容、颜色值(绿色字面量)完全不同。
  • [API] 变体集合(上游文档自相矛盾,已核实):button-group.mdx(cn:112 / en:142)API 表列 'primary'|'secondary'|'tertiary'|'ghost'|'danger'(5 个,缺 outline、danger-soft),但实现 ButtonGroupRootProps extends Pick<ButtonProps,"size"|"variant">(heroui/packages/react/src/components/button-group/button-group.tsx)含全部 7 个,且上游 button-group-variants 示例就用了 variant="outline"。Vue button-group.md 列 7 个,与实现一致。
  • [API] Vue 多 as(默认 'div')与 disabled 别名(ButtonGroup.vue props);className/children ↔ class/插槽属框架映射。
  • [文档] 相关组件不同:上游 <RelatedComponents component="button-group"> 取 componentRelationships.buttongroup = ["button","dropdown","chip"] 前 3(Button、Dropdown、Chip);Vue button-group.md 固定为 Button、ToggleButton、ToggleButtonGroup。
  • [实现] "仅直接子按钮继承组属性"双方实现一致(上游 React.cloneElement(child, {[BUTTON_GROUP_CHILD]: true}) ↔ Vue flattenChildren + cloneVNode(child, { __button_group_child: true }));组禁用可被子项显式 isDisabled={false} 覆盖,与上游文档说明一致(Vue 文档表述为"单个 Button 可通过自身属性覆盖组的默认值",语义相同)。
  • [样式] button-group.css 逐行一致(含 .button-group--horizontal .button--outline:not(:first-child):not(:last-child) 等规则,仅换行格式差异);tv 一致。
  • [配色] 无差异(custom-styles 示例的颜色差异已计入 [示例])。

close-button

  • [示例] 4 个文档示例(default / interactive / with-custom-icon / custom-styles)内容、文案、类串、行为一致(已点击:N 次、aria-label="关闭(已点击 N 次)"、size-8 rounded-full bg-default … 等完全对应);仅图标映射 CircleXmark/Xmark → IconCircleX/IconX(等义)。onPress→@click 属框架映射。另:上游 heroui/apps/docs/src/demos/cn/close-button/variants.tsx("默认"标签)未被任何 mdx 引用,Vue 无对应文件(不构成文档示例差异)。
  • [API] 上游 Render Props 表列 4 项(isHovered/isPressed/isFocused/isDisabled),Vue close-button.md 作用域插槽表列 5 项(多 isFocusVisible;双方实现都能提供,属上游文档遗漏、Vue 更全)。Vue 另记载 type 固定 "button"、aria-label 默认 Close——与上游实现一致(close-button.tsx aria-label="Close"、type="button"),上游文档未写,属 Vue 文档增补。
  • [文档] 相关组件不同:上游 componentRelationships.closebutton = ["alert","alertdialog","chip","modal"] 前 3(Alert、AlertDialog、Chip);Vue 固定为 Button、Card。
  • [实现] 默认关闭图标 SVG(16×16,path M3.47 3.47a.75.75 0 0 1 1.06 0L8 6.94…)与上游 CloseIcon(heroui/packages/react/src/components/icons.tsx:121)逐字一致;状态属性(data-hovered/pressed/focused/focus-visible)一致。
  • [样式] close-button.css 与 closeButtonVariants 一致,无差异。
  • [配色] 无差异。

toggle-button

  • [示例] toggle-button-basic:上游单个 <ToggleButton><Heart />点赞</ToggleButton>;Vue 两个按钮(第一个 v-model 切换 IconHeart/IconHeartFilled,第二个 variant="ghost"),文案 "Like"。结构、交互、文案差异。
  • [示例] toggle-button-variants:上游 2 按钮并排("默认"、"幽灵" + Heart);Vue 2 组×2 按钮(Default/Ghost,各含未选与 default-selected + IconHeartFilled),文案 "Like"。结构差异(2 → 4 按钮)。
  • [示例] toggle-button-icon-only:aria-label 点赞/收藏 → Like/Bookmark;根 flex items-center gap-3 → flex gap-3。
  • [示例] toggle-button-sizes:标签 小/中/大 → Small/Medium/Large;仅图标按钮 aria-label"点赞" → Small/Medium/Large(与上游不一致)。
  • [示例] toggle-button-disabled:文案 点赞 → Like(defaultSelected + HeartFill ↔ IconHeartFilled 一致)。
  • [示例] toggle-button-controlled:"状态:已选/未选"、"点赞/已点赞" → "Status: Selected/Not selected"、"Like/Liked"。
  • [示例] toggle-button-custom-styles:上游 className="gap-2 rounded-full border border-border/80 bg-surface px-4 text-foreground shadow-sm data-[selected=true]:border-accent/30 data-[selected=true]:bg-accent-soft data-[selected=true]:text-accent-soft-foreground [&_svg]:text-muted data-[selected=true]:[&_svg]:text-accent" + 文案"收藏文章";Vue class="rounded-lg bg-purple-500 text-white" + "Like"(heroui-vue/apps/docs/demos/toggle-button-custom-styles.vue)。类名、选中态配色(主题 accent 变量 vs 紫色字面量 bg-purple-500)、文案完全不同(示例/配色硬差异)。
  • [API] isSelected/defaultSelected/onChange/onPress/children → v-model/isSelected 别名/defaultValue+defaultSelected/update:modelValue+change 事件表/默认插槽,属框架映射;Vue 多 value(与 id 等价的组内键)与 asChild。id 语义不同:上游 id 同时是 DOM id 与选择 key;Vue(heroui-vue/packages/vue/src/components/toggle-button/ToggleButton.vue domId = inGroup ? attrs.id : props.id)组内 id 只作 key、按钮不渲染 DOM id 属性(上游 RAC 侧 DOM id 输出待核实,倾向保留)。
  • [文档] 交互状态"禁用"行:上游写 :disabled 或 [aria-disabled="true"],Vue toggle-button.md 写 [data-disabled="true"];双方 CSS 实际为 &:disabled, &[aria-disabled="true"](toggle-button.css:44-46),Vue 文档表述与样式不符(组件两者都输出,视觉不受影响)。属文档硬差异。
  • [实现] 角色与选中语义无差异:单选组内 role="radio" + aria-checked,其余 role="button" + aria-pressed,与上游测试断言一致(heroui/packages/react/tests/components/toggle-button-group/toggle-button-group.test.tsx:113-136、toggle-button/toggle-button.test.tsx:33-39)。
  • [实现] 组禁用覆盖行为不一致:上游 toggle-button.mdx 说明"单个按钮可通过设置 isDisabled={false} 覆盖";Vue 实现 disabled = Boolean(props.isDisabled || props.disabled || groupDisabled)(无法覆盖),Vue 文档也写明"不能用 false 解除组禁用"。至少文档承诺的行为不同(上游 RAC 实际是否支持覆盖待核实)。
  • [样式/tv] toggle-button.css、toggleButtonVariants 一致,无差异。

toggle-button-group

  • [示例] toggle-button-group-orientation:上游每组 3 按钮(粗体/斜体/下划线)+ 标签"水平/垂直";Vue 每组 4 按钮(多删除线)+ 标签 "Horizontal/Vertical"。结构 + 文案差异。
  • [示例] toggle-button-group-full-width:上游两组(格式图标组 multiple + 对齐组 single:左对齐/居中/右对齐 + TextAlignLeft/Center/Right),w-full max-w-md space-y-3;Vue 只剩第一组。内容缺失。
  • [示例] toggle-button-group-selection-mode:标签 单选/多选 → "Single selection/Multiple selection";按钮 左对齐/居中/右对齐 → Left/Center/Right;defaultSelectedKeys={["center"]} → default-selected-keys="center"(single 用单键,语义等价)。
  • [示例] toggle-button-group-basic / without-separator / sizes / disabled / attached / controlled:结构、id、默认选中、变体一致,仅文案整体英文化(粗体/斜体/下划线/删除线→Bold/Italic/Underline/Strikethrough;小/中(默认)/大→Small/Medium (default)/Large;全部按钮已禁用/单个按钮已禁用→All buttons disabled/Individual button disabled;附着(默认)/分离→Attached (default)/Detached;已选:无→Selected: None);标签元素 span → p 且 text-sm text-muted → text-sm font-medium text-muted,根 flex flex-col gap-6 → flex w-full flex-col gap-6。
  • [示例] toggle-button-group-custom-styles:上游组容器 aria-label="文本格式" + className="gap-1 rounded-xl border border-border/80 bg-surface p-1 shadow-sm",3 个按钮 toggleClass = "rounded-lg text-muted data-[selected=true]:bg-accent-soft data-[selected=true]:text-accent-soft-foreground"、无分隔线;Vue 组仅 class="rounded-lg",4 个 class="rounded-lg" 按钮 + 3 个 opacity-25 分隔线,无组 aria-label(heroui-vue/apps/docs/demos/toggle-button-group-custom-styles.vue)。结构、类、选中配色、无障碍标签均不同。
  • [API] selectedKeys: Iterable<Key> / onSelectionChange(keys: Set<Key>) → v-model/数组 + selectionChange 事件,属集合类型映射;Vue 多 as(默认 'div')、disabled 别名。
  • [API/行为] disallowEmptySelection 说明不同:上游"与 selectionMode="single" 一起使用,可确保始终有一个选项被选中";Vue"阻止用户清空已有选择;需要初始选中时,请同时提供 defaultValue 或受控值"。实现上 Vue 仅阻止清空最后一项、初始可为空(useToggleButtonSelection.ts request()),与 RAC 行为相近,属措辞差异(轻,待核实 RAC 细节)。
  • [API/行为] 组禁用覆盖:上游说明"单个按钮可通过设置 isDisabled={false} 覆盖",Vue 说明"不能用 false 解除组禁用"(实现 Boolean(props.isDisabled || props.disabled || groupDisabled)),与上游文档承诺不一致(上游 RAC 实际行为待核实)。
  • [实现] 角色一致(上游测试 toggle-button-group.test.tsx:86 toolbar+aria-pressed、:113-136 radiogroup+radio+aria-checked ↔ Vue ToggleButtonGroup.vue role = isSingle ? "radiogroup" : "toolbar");Vue 另输出 aria-orientation、dir(上游由 RAC 处理,细节待核实)。键盘 roving tabindex、方向键/Home/End/RTL 由 Vue useToggleRovingFocus 自实现,上游由 RAC 承担(实现路径不同,公开行为需逐项比对——未发现已证实差异)。
  • [文档] 相关组件不同:上游 togglebuttongroup: ["togglebutton","buttongroup","button"] 前 3(ToggleButton、ButtonGroup、Button);Vue 为 ToggleButton、ButtonGroup、CheckboxGroup、RadioGroup(多 CheckboxGroup/RadioGroup,少 Button)。
  • [样式/tv] toggle-button-group.css、toggleButtonGroupVariants 一致,无差异。

本组小结(最严重项)

  1. button-group-basic、button-group-custom-styles 两个示例被整体简化/替换:上游的 GitHub 合并 Dropdown(3 个中文菜单项 + Description)、复刻/星标/扫码等 9 组按钮、bg-[#08872B]/data-hovered:bg-[#0FBF3E] 自定义配色全部缺失,Vue 只剩 First/Second/Third 基础组(heroui-vue/apps/docs/demos/button-group-basic.vue、button-group-custom-styles.vue)。
  2. button-group-*、toggle-button-*、toggle-button-group-* 系列示例文案整体英文化(First/Second/Third、Small、Like、Bold…),违背 cn 中文基线(第一项/小/点赞/粗体…);button-group-variants 甚至直接渲染小写变体名 "primary"。
  3. toggle-button-custom-styles 与 toggle-button-group-custom-styles 的自定义样式示例完全不同:上游为主题变量(accent-soft / border / surface / shadow)+ 选中态配色 + 组 aria-label="文本格式",Vue 为 bg-purple-500、rounded-lg/opacity-25 且缺失无障碍标签。
  4. 多个示例结构缺失或 props 丢失:button-group-full-width(缺仅图标对齐组)、button-group-disabled(缺 isDisabled={false} 覆盖演示)、button-group-sizes(缺 variant="secondary",视觉变体错)、toggle-button-group-full-width(缺对齐组)、toggle-button-group-orientation(每组多/少按钮)。
  5. API/文档不一致:上游 Button/ButtonGroup API 表漏 danger-soft/outline 变体(与其自身 styles.ts、css、示例矛盾,Vue 文档已补全);ToggleButtonGroup 组禁用的子项覆盖能力上游文档称支持、Vue 明确不支持(实现 Boolean(isDisabled || groupDisabled));Button 缺"相关案例"整节与完整 CSS 类清单。