Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented May 9, 2025

  • 把一些 antd 的逻辑移除,在 antd 侧实现从而进行解耦。
  • 添加语义化结构支持。

Summary by CodeRabbit

  • 新功能

    • 步骤条组件支持通过 classNames 和 styles 属性自定义语义化样式和类名。
    • 步骤条组件新增 itemRender 和 itemWrapperRender 渲染钩子,支持自定义步骤项结构。
    • 新增 Rail 组件,用于更灵活地展示步骤连接线。
  • 重构

    • 步骤条组件整体 API 和 props 结构重构,统一样式和渲染定制方式,移除部分旧属性和不再使用的功能。
    • 步骤项 Step 组件采用数据驱动与 render-prop 模式,提升灵活性和可扩展性。
    • 优化和精简样式,移除多余的装饰性元素(如尾部线条、hover 效果等),采用更现代的 Flex 布局。
  • 样式

    • 步骤条整体及各变体样式大幅优化,支持横向、纵向、标签纵向等多种布局。
    • 删除或重命名部分 CSS 类名,简化样式结构。
  • 测试

    • 新增语义化样式和自定义渲染相关的测试用例。
    • 移除已废弃属性和结构相关的快照测试,更新测试以适配新的 DOM 结构和类名。
  • 其他

    • 依赖 react 和 react-dom 版本降级至 18.x。
    • 发布版本号升级为 0.0.0-alpha.5。

@vercel
Copy link

vercel bot commented May 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
steps ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 3:19pm

@coderabbitai
Copy link

coderabbitai bot commented May 9, 2025

Walkthrough

本次更新对步骤条组件的样式和核心实现进行了大幅重构。主要包括:精简和重命名样式类,移除尾部装饰和悬浮效果,引入基于 flexbox 的新布局,统一样式和渲染自定义接口,重写 Step 和 Steps 组件为数据驱动和 render-prop 结构,并添加了新的 Rail 组件。测试文件也同步适配了结构和接口的变化。

Changes

文件/分组 变更摘要
assets/index.less
assets/inline.less
assets/label-placement.less
assets/nav.less
assets/progress-dot.less
assets/small.less
assets/vertical.less
移除 .item-tail 相关样式,删除悬浮和装饰性样式,重命名 .item-content.item-section,引入基于 flexbox 的新布局规则,精简和重构步骤条的样式结构。
package.json 版本号由 0.0.0 升级为 0.0.0-alpha.5reactreact-dom 的 devDependencies 由 ^19.0.0 降级为 ^18.0.0
src/Rail.tsx 新增导出的 Rail 组件及其 props 类型,用于渲染步骤之间的连接线(rail)。
src/Step.tsx Step 组件重构为 render-prop 和数据驱动结构,合并内容字段,支持灵活自定义渲染,移除原有 icon 和状态处理逻辑,适配新的样式和交互接口。
src/Steps.tsx Steps 组件重构,移除旧有 props,新增 classNamesstylesorientation、render-prop 等新接口,items 采用新类型,内部状态计算和渲染逻辑简化。
src/index.ts 新增 StepsProps 类型的 re-export,便于外部直接引入类型。
src/interface.ts 删除,原有的 Status 类型和 Icons 接口已迁移或废弃。
tests/index.test.tsx 移除与旧结构相关的快照测试,适配新类名和结构,新增 itemRenderitemWrapperRender 的功能性测试。
tests/semantic.test.tsx 新增语义化结构测试,验证 classNamesstyles 能正确应用到各语义节点。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant Steps
    participant Step
    participant Rail

    用户->>Steps: 传入 items、classNames、styles、render-prop 等
    Steps->>Step: 遍历 items,传递数据及渲染回调
    Step->>Rail: 如果不是最后一步,渲染 Rail 组件
    Step-->>Steps: 渲染自定义节点(iconRender/itemRender/itemWrapperRender)
    Steps-->>用户: 渲染完整步骤条
Loading

Poem

兔子抖抖小胡须,
步骤条焕新衣。
尾巴轻轻说再见,
Flex 排列更整齐。
渲染自定义,样式随心意,
语义结构也升级!
代码田野,春风里。 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/Step.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81f1fe8 and e44ed1e.

📒 Files selected for processing (1)
  • src/Step.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Step.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (01834d6) to head (e44ed1e).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #371   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         3    +1     
  Lines           99        73   -26     
  Branches        48        31   -17     
=========================================
- Hits            99        73   -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (5)
src/Rail.tsx (1)

12-23: Rail 组件实现简洁高效

这个新的 Rail 组件实现很好地体现了关注点分离原则,将之前在 CSS 中处理的步骤连接线逻辑移到了组件中。这样使得自定义和状态管理更加直观和灵活。

建议为 classNamesstyles 添加空值检查,以避免可能的运行时错误。

-  return (
-    <div
-      className={cls(railCls, `${railCls}-${status}`, classNames.itemRail)}
-      style={styles.itemRail}
-    />
-  );
+  return (
+    <div
+      className={cls(railCls, `${railCls}-${status}`, classNames?.itemRail)}
+      style={styles?.itemRail}
+    />
+  );
src/Step.tsx (2)

130-139: 自定义 icon 未被渲染,功能回退

虽然 classString 中根据 icon 加了 -custom 修饰符,但真正的 DOM 中仅调用 iconRender。当用户只在 items 里传 icon 而未实现 iconRender 时,图标不会显示。

可以在 iconRender 缺省时回退到 item.icon

-{iconRender?.(renderInfo)}
+{iconRender ? iconRender(renderInfo) : icon}

170-181: 缺少 React.memo/useMemo,列表较长时可能触发不必要的重渲染

Step 中组装 stepNode 的逻辑纯粹由 props 决定,可通过 React.memo 包装整个组件或用 useMemo 缓存,减少 Steps 更新时的层层重渲染。

src/Steps.tsx (2)

140-145: onStepClick 未传递原生事件,无法阻止冒泡等操作

已有场景可能需要在 onChange 外再做防抖、阻止默认等处理。建议让 Step 把原生事件一起带回来:

-const onStepClick = (next: number) => {
+const onStepClick = (next: number, e?: React.MouseEvent<HTMLDivElement>) => {
   if (onChange && current !== next) {
-    onChange(next);
+    onChange(next, e);
   }
 };

同时在 Step 里调用 onClick?.(index, e)。这样既向后兼容,又提供更大的扩展空间。


181-190: 根节点内联样式覆盖顺序易出错

目前写法先展开 style 再覆盖 styles.root,当两处都定义同名属性时优先采用 styles.root。如想保持外层 style 的最高优先级,应调整顺序:

-style={{
-  ...style,
-  ...styles?.root,
-}}
+style={{
+  ...styles?.root,
+  ...style,
+}}

请根据设计系统要求确认优先级。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01834d6 and 81f1fe8.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (15)
  • assets/index.less (4 hunks)
  • assets/inline.less (1 hunks)
  • assets/label-placement.less (1 hunks)
  • assets/nav.less (0 hunks)
  • assets/progress-dot.less (0 hunks)
  • assets/small.less (1 hunks)
  • assets/vertical.less (1 hunks)
  • package.json (2 hunks)
  • src/Rail.tsx (1 hunks)
  • src/Step.tsx (1 hunks)
  • src/Steps.tsx (1 hunks)
  • src/index.ts (1 hunks)
  • src/interface.ts (0 hunks)
  • tests/index.test.tsx (6 hunks)
  • tests/semantic.test.tsx (1 hunks)
💤 Files with no reviewable changes (3)
  • src/interface.ts
  • assets/nav.less
  • assets/progress-dot.less
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Rail.tsx (1)
src/Steps.tsx (2)
  • StepsProps (47-71)
  • Status (6-6)
🔇 Additional comments (17)
package.json (2)

3-3: 检查版本号变更
将版本从 0.0.0 提升到 0.0.0-alpha.5 符合预发布语义,请确认 CI/CD 和发布流程已配置为正确处理 alpha 标签版本,且在 CHANGELOG 中注明了这一 Breaking Change。


83-84: 确认 React 版本兼容性
reactreact-dom^19.0.0 降级到 ^18.0.0,请验证以下内容:

  1. 代码库中所有用到 React 19 特性的逻辑已移除或降级;
  2. 单元测试与示例在 React 18 环境下通过;
  3. README/CHANGELOG 明确标注了对最低 React 版本的要求。
src/index.ts (1)

1-2: 类型导出优化
在入口文件中显式添加 export type { StepsProps },提升了类型可用性,符合最佳实践。请确认打包产物中已正确包含该类型声明,且不会影响 tree-shaking。

assets/label-placement.less (1)

6-11: 样式命名调整
将原有 &-content 重命名为 &-section 并新增相关样式,需确认所有组件渲染时的类名引用已同步更新,避免遗留旧类名导致样式失效。

assets/small.less (1)

19-21: 小尺寸样式更新
新增 .item-section 替代原 .item-content 并设置 margin-top: 0,请验证在小尺寸模式下内容区位置和间距符合设计规范,确保移除 tail 后布局没有异常。

assets/vertical.less (1)

14-18: 垂直模式样式调整
在垂直布局下新增 &-section 以替换旧的 &-content,并定义 min-heightoverflowdisplay 属性,请验证垂直模式下各步骤内容区域的高度和溢出处理符合预期。

assets/inline.less (1)

23-23: 类名更改提供了更好的语义结构

&-content 重命名为 &-section 使得类名更符合 HTML5 语义化标准,这有助于提高代码的可读性和维护性。这种命名方式更清晰地表达了该元素在结构中的作用。

tests/semantic.test.tsx (1)

6-76: 测试覆盖了语义结构的所有关键部分

这个测试文件很好地验证了步骤组件的语义结构和样式自定义能力。测试检查了所有关键的语义名称(SemanticName)是否都能正确应用自定义类名和样式,确保了组件结构的一致性和灵活性。

建议考虑添加一些边缘情况测试,比如当只提供部分自定义类名或样式时的行为。

src/Rail.tsx (1)

5-10: 接口定义清晰

RailProps 接口定义清晰,引用了 StepsProps 中的 classNamesstyles,保持了类型一致性。

tests/index.test.tsx (6)

7-7: 将 let 改为 const 增强了代码质量

description 变量从 let 更改为 const 是一个好的实践,因为该变量不需要被重新赋值,使用 const 可以防止意外修改。


213-213: 类选择器更新

选择器从 .rc-steps-item-container 更新为 .rc-steps-item-wrapper,这与组件的语义重构保持一致。确保所有相关的测试都已更新这个选择器。


236-236: 类选择器更新

与上面相同,选择器已正确更新为使用新的类名 .rc-steps-item-wrapper


268-268: 类选择器更新

与前面相同,选择器已正确更新为使用新的类名 .rc-steps-item-wrapper


279-279: 类选择器更新

与前面相同,选择器已正确更新为使用新的类名 .rc-steps-item-wrapper


309-346: 新增测试验证渲染属性功能

增加了两个新测试 itemRenderitemWrapperRender,验证了组件支持自定义渲染的能力。这些测试确保了自定义元素能够正确包装步骤项,并且原始步骤项结构保持完整。

这些测试很好地补充了语义结构的支持,确保了组件在重构后保持了预期的自定义能力。

assets/index.less (1)

129-136: 大面积注释掉原有 mixin 可能导致回归
smallverticallabel-placement 等子样式全部被注释掉后,使用这些 size / 布局的场景会直接丢失样式。若确实要整体迁移,也应在注释处留下迁移说明,或在运行时发出警告,避免用户升级后出现“空白”组件。

src/Steps.tsx (1)

120-137: statuses 计算未考虑 current 越界与负值

当传入 current < initialcurrent >= initial + items.length 时,现有逻辑仍可能把某些步骤标成 finish/process,与真实状态不符。建议:

  1. current 做边界裁剪:const safeCurrent = Math.max(initial, Math.min(current, lastIndex));
  2. 计算 stepNumber 时使用 safeCurrent

这样可避免在异常输入下渲染出误导性的视觉状态。

Comment on lines 106 to 111
.step-item-status(@status) {
@icon-color: "@{status}-icon-color";
@title-color: "@{status}-title-color";
@description-color: "@{status}-description-color";
@tail-color: "@{status}-tail-color";
@icon-color: '@{status}-icon-color';
@title-color: '@{status}-title-color';
@description-color: '@{status}-description-color';
@tail-color: '@{status}-tail-color';
&-@{status} &-icon {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

变量插值语法有误,lessc 将无法解析 @@icon-color 变量
在 Less 中想用字符串构造另一个变量名时,需要使用 ~"@{var}" 才能触发插值。目前:

@icon-color: '@{status}-icon-color';

'@{status}-icon-color' 会被当成普通字符串,因此 @@icon-color 指向一个实际不存在的变量名,编译阶段就会报错。

建议改为:

-@icon-color: '@{status}-icon-color';
+@icon-color: ~"@{status}-icon-color";

或直接省略中间变量,直接写 @@{status}-icon-color

🤖 Prompt for AI Agents (early access)
In assets/index.less around lines 106 to 111, the variable interpolation syntax
is incorrect because '@{status}-icon-color' is treated as a plain string,
causing lessc to fail resolving @@icon-color. To fix this, replace the string
with proper interpolation using ~"@{status}-icon-color" so Less can evaluate it
as a variable name, or alternatively, remove the intermediate variable and
directly use @@{status}-icon-color where needed.

Comment on lines +160 to 166
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

CSS 选择器缺失导致内容区域无样式
Step.tsx 仍然渲染 className={${itemCls}-content}(见第 160-163 行),但在新的样式中已将 “content” 分离为 “section”,对应的 &-content 选择器在文件中已经全部移除,这会导致描述区丢失原有的字号、颜色等样式。

如需保留描述区,请补回样式或同步修改组件类名。

🤖 Prompt for AI Agents (early access)
In assets/index.less around lines 160 to 166, the CSS selector for the content
area is missing because the original &-content selector was removed while
Step.tsx still uses className={`${itemCls}-content`}. To fix this, either
restore the &-content CSS selector with the appropriate styles for font size,
color, and other properties, or update the component's className to match the
new selector (e.g., change it to use the section class) so the styles apply
correctly.

Comment on lines +90 to 112
const clickable = !!(onClick || onItemClick) && !disabled;

const accessibilityProps: {
role?: string;
tabIndex?: number;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
} = {};

if (clickable) {
accessibilityProps.role = 'button';
accessibilityProps.tabIndex = 0;
accessibilityProps.onClick = (e) => {
onClick?.(e);
onStepClick(stepIndex);
onItemClick?.(e);
onClick(index);
};

accessibilityProps.onKeyDown = (e) => {
const { which } = e;
if (which === KeyCode.ENTER || which === KeyCode.SPACE) {
onStepClick(stepIndex);
onClick(index);
}
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

onClick 为空时仍被调用,运行时会抛 TypeError

clickable 只要 data.onClick 存在就可能为 true,但回调中依旧无条件执行 onClick(index)

onItemClick?.(e);
onClick(index); // <-- 当 props.onClick 未传时为 undefined

导致用户只传 item.onClick 而未传 Steps.onChange 时点击直接报错。建议改为:

-onClick(index);
+onClick?.(index);

onKeyDown 中同理。

🤖 Prompt for AI Agents (early access)
In src/Step.tsx around lines 90 to 112, the onClick handler calls onClick(index)
without checking if onClick is defined, causing a TypeError when onClick is
undefined. To fix this, add a conditional check before calling onClick(index) in
both the onClick and onKeyDown handlers, ensuring onClick is only called if it
exists.

@zombieJ zombieJ merged commit 43c60a8 into master May 9, 2025
13 checks passed
@zombieJ zombieJ deleted the refactor branch May 9, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant