Skip to content

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Sep 12, 2025

依赖rc-util修改为 @rc-component/util
替换 useMergedState 为 useControlledState

Summary by CodeRabbit

  • 新功能

  • 文档

    • 更新示例与站点安装与导入路径为“@rc-component/checkbox”,示例代码与说明同步调整。
  • 重构

    • 内部状态管理改为 useControlledState,组件对外行为与公共 API 保持不变。
  • 测试

    • 调整测试中 KeyCode 的依赖来源,测试行为保持一致。
  • 事务

    • 包名改为“@rc-component/checkbox”,版本重置为 1.0.0;更新构建/发布脚本、依赖为 @rc-component/util;TypeScript 路径别名同步更新。

Copy link

coderabbitai bot commented Sep 12, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

将包名与导入路径从 rc-checkbox 迁移到 @rc-component/checkbox,更新文档、示例与 tsconfig 别名;核心组件内部将 useMergedState 替换为 useControlledState;更新 package.json 依赖与脚本;测试中替换 KeyCode 的导入路径。

Changes

Cohort / File(s) Summary
文档与示例
README.md, docs/index.md, docs/demo/*
将展示名称与示例导入从 rc-checkbox 改为 @rc-component/checkbox;安装命令与用法示例同步更新;示例类型与组件导入路径调整。
包配置与发布
package.json
包名改为 @rc-component/checkbox,版本置为 1.0.0;更新 homepage、发布脚本(改为 rc-np)并新增 tsc 脚本;依赖移除 @babel/runtimerc-util,加入 @rc-component/util;大量 devDependencies 增补/升级。
TypeScript 配置
tsconfig.json
路径别名由 "rc-checkbox" 改为 "@rc-component/checkbox",指向 src/index.tsx
核心源码
src/index.tsx
内部状态管理从 useMergedState 切换为 useControlledState,相应导入与初始化调用更新;组件导出签名保持不变。
测试
tests/index.test.tsx
KeyCode 的导入来源从 rc-util/lib/KeyCode 改为 @rc-component/util/lib/KeyCode,测试逻辑未改动。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as 用户
  participant Checkbox as Checkbox 组件
  participant Hook as useControlledState (Hook)

  User->>Checkbox: 交互(点击/键盘)
  Checkbox->>Hook: 读取当前值(props.checked 或 defaultChecked)
  Hook-->>Checkbox: 返回 [rawValue, setRawValue]
  Checkbox->>Checkbox: 调用 setRawValue 或基于 props 决定不更新内部状态
  Checkbox->>User: 触发 onChange 事件(通知外部)
  note right of Hook #E6F4EA: 新增/替换的 hook:useControlledState
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • zombieJ

Poem

我是小兔叮当跳,
名称换新衣裳俏。
钩子换位轻松跑,
文档示例也跟跑。
安装一行,向前跃! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR 标题简短且直接指出主要变更:将包迁移到 @rc-component 命名空间并执行更新,这与 package.json、源码导入和文档中的修改一致且可快速识别为此次迁移任务。标题为单句、清晰且与变更集密切相关,虽包含通用的 “and update” 表述但并不误导或离题。基于这些点,标题满足检查要求。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @EmilyyyLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在将 rc-checkbox 组件及其相关依赖迁移到 @rc-component 命名空间下,以实现项目内包管理和依赖的一致性。这包括更新包名、调整导入路径以及替换内部使用的 React Hook,从而确保组件与新的生态系统标准对齐,并为未来的维护和开发奠定基础。

Highlights

  • 包名和引用迁移: 将所有包名和内部引用从 rc-checkbox 迁移到 @rc-component/checkbox 命名空间,以实现统一管理。
  • 依赖更新: 将 rc-util 依赖更新为 @rc-component/util,并替换了 useMergedStateuseControlledState
  • 项目配置更新: 更新了 package.json 中的版本号、主页链接、构建脚本和依赖项,并调整了 tsconfig.json 中的路径别名。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 主要将 rc-checkbox 迁移到了 @rc-component 命名空间下,并更新了相关依赖和 API 调用。整体来看,修改内容清晰,符合迁移目标。但是,我在 package.json 中发现一个严重问题,可能会导致项目构建失败,并已在代码评论中提出修复建议。请务必修正。

Copy link

socket-security bot commented Sep 12, 2025

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

1-1: README 仍大量指向 rc-checkbox,需同步到新作用域

包已迁移到 @rc-component/checkbox,README 标题、徽章与链接应统一,否则会误导使用者。

建议:

  • 标题改为 # @rc-component/checkbox(Line 1)。
  • NPM 徽章与链接更新到 scoped 包(Lines 14–16、26–27、35)。
  • bundlephobia 链接与徽章也应改为 scoped 包(Lines 28–29)。
  • Nodei 图片改为 @rc-component/checkbox(Line 35)。

注意:带作用域的 URL 需做 URL 编码(如 %40rc-component%2Fcheckbox)。需要的话我可以提 PR 批量替换。

Also applies to: 14-16, 26-29, 35-36

🧹 Nitpick comments (1)
docs/demo/simple.tsx (1)

37-37: 示例文案仍显示 rc-checkbox,建议同步到新包名避免混淆

页面可见文本建议统一为 @rc-component/checkbox 或更通用的 “Checkbox”。

可按需修改(示例):

-            &nbsp; controlled checked rc-checkbox
+            &nbsp; controlled checked @rc-component/checkbox
...
-            &nbsp; defaultChecked rc-checkbox
+            &nbsp; defaultChecked @rc-component/checkbox
...
-            &nbsp; defaultChecked rc-checkbox with name
+            &nbsp; defaultChecked @rc-component/checkbox with name
...
-            &nbsp; rc-checkbox with key events
+            &nbsp; @rc-component/checkbox with key events

Also applies to: 55-55, 72-72, 100-101

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f90d64 and a1c8b83.

📒 Files selected for processing (8)
  • README.md (1 hunks)
  • docs/demo/focus.tsx (1 hunks)
  • docs/demo/simple.tsx (1 hunks)
  • docs/index.md (1 hunks)
  • package.json (3 hunks)
  • src/index.tsx (2 hunks)
  • tests/index.test.tsx (1 hunks)
  • tsconfig.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (6)
tests/index.test.tsx (1)

1-1: KeyCode 路径迁移对齐 @rc-component/util,LGTM

与源码依赖一致,测试可继续覆盖键盘事件分支,无需额外改动。

docs/index.md (1)

3-3: 文档导入与安装命令已对齐新包名,LGTM

Also applies to: 11-11, 14-14, 17-17, 23-23

docs/demo/simple.tsx (1)

2-2: 示例导入与类型对齐新包名,LGTM

Also applies to: 6-6

tsconfig.json (1)

14-15: paths 映射已切换到 @rc-component/checkbox,LGTM

与文档/测试用法一致,开发时能直连源码入口。

src/index.tsx (1)

1-1: useMergedState → useControlledState 行为一致性请做一次回归确认

改为 useControlledState(defaultChecked, checked) 后,受控/非受控分支仍由 ('checked' in props) 判定,表面逻辑无变。但不同 hook 的边界行为(如 defaultChecked 仅首轮生效、受控时 set 是否为 no-op)可能与旧实现略有差异。

建议重点回归:

  • 受控模式:传入 checked 时点击不应改变内部状态(已有测试覆盖)。
  • 非受控模式:defaultChecked 仅初始化一次;后续点击能切换。
  • disabled 时不触发状态与回调。
    若需要,我可以补一组针对受控/非受控边界的额外测试用例。

Also applies to: 47-47

docs/demo/focus.tsx (1)

1-2: 示例导入与类型对齐新包名,LGTM

Comment on lines +2 to 4
"name": "@rc-component/checkbox",
"version": "1.0.0",
"description": "checkbox ui component for react",
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

首次发布 scoped 包建议显式声明为 public

NPM 对作用域包默认私有。为避免首发失败或误发私有,建议添加 publishConfig.access: public

可在根级添加:

"publishConfig": {
  "access": "public"
}

需要我顺手补上并校验发布流程脚本吗?

🤖 Prompt for AI Agents
In package.json around lines 2 to 4, this scoped package lacks an explicit
publishConfig and NPM defaults scoped packages to private; add a root-level
"publishConfig": { "access": "public" } entry to ensure the first publish is
public, and verify any publish scripts or CI use the package.json root so the
new field is picked up.

Comment on lines 39 to 43
```js
import checkbox from 'rc-checkbox';
import checkbox from '@rc-component/checkbox';

export default () => <checkbox />;
```
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

README 用法示例中的组件名大小写错误,当前会被当作原生标签渲染

应使用大写组件名并与默认导出同名,避免 <checkbox /> 被识别为自定义元素而非 React 组件。

建议改成:

-import checkbox from '@rc-component/checkbox';
+import Checkbox from '@rc-component/checkbox';

-export default () => <checkbox />;
+export default () => <Checkbox />;
🤖 Prompt for AI Agents
In README.md around lines 39 to 43 the example imports and uses a lowercase
component name causing React to treat it as a native DOM tag; change the import
to a PascalCase name that matches the default export and use that PascalCase in
JSX (e.g., import Checkbox from '...'; export default () => <Checkbox />) so the
element is recognized as a React component.

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: 0

♻️ Duplicate comments (2)
package.json (2)

2-3: 首次发布 scoped 包建议显式设置为 public

为避免 npm publish 默认发布为私有,请在根级添加 publishConfig.access: public

 {
   "name": "@rc-component/checkbox",
   "version": "1.0.0",
+  "publishConfig": {
+    "access": "public"
+  },
   "description": "checkbox ui component for react",

56-56: 已修复版本号尾随空格问题,赞!

🧹 Nitpick comments (3)
package.json (3)

11-13: 统一使用 https 链接

bugs.url 仍为 http,建议改为 https 以保持一致与安全。

   "homepage": "https://react-component.github.io/checkbox",
   "bugs": {
-    "url": "http://github.com/react-component/checkbox/issues"
+    "url": "https://github.com/react-component/checkbox/issues"
   },

37-38: 去除对 bun 的工具依赖

脚本中使用 bunx 会增加贡献门槛,直接调用本地 tsc 更稳妥。

-    "test": "jest",
-    "tsc": "bunx tsc --noEmit"
+    "test": "jest",
+    "tsc": "tsc --noEmit"

53-54: 建议声明 Node 运行时版本

依赖(如 husky 9、现代 eslint/dumi/father)通常要求 Node ≥18。建议在 engines 中约束,避免 CI/本地版本漂移。

   "devDependencies": {
     "@rc-component/father-plugin": "^2.1.3",
     "@rc-component/np": "^1.0.0",
@@
     "typescript": "^5.2.2"
   },
+  "engines": {
+    "node": ">=18"
+  },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1c8b83 and 319ebda.

📒 Files selected for processing (1)
  • package.json (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (3)
package.json (3)

32-32: 确认 gh-pages 部署命令与 dumi 2/father v4 的兼容性

father doc deploy -d dist 在 dumi 2 场景下是否仍为推荐方式?如有问题可改用 dumi deploy


35-35: 发布流检查:rc-np 与 scoped 包

请确认 rc-np 会传递 --access public(或依赖上方 publishConfig)并配置 2FA/跳过发布阶段的 tag 推送策略。


49-50: 确认:依赖替换已落地(未发现 rc-util/useMergedState;useControlledState 来自 @rc-component/util)

证据:src/index.tsx — import useControlledState from '@rc-component/util/lib/hooks/useControlledState'(使用处第47行);package.json — @rc-component/util: "^1.3.0"(第49行)。未检出 rc-utiluseMergedState

Copy link

codecov bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9f90d64) to head (319ebda).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #294   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           30        30           
  Branches         5         5           
=========================================
  Hits            30        30           

☔ 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.

@zombieJ zombieJ merged commit 11a6251 into react-component:master Sep 16, 2025
7 checks passed
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.

2 participants