Skip to content

Conversation

cactuser-Lu
Copy link
Contributor

@cactuser-Lu cactuser-Lu commented Sep 22, 2025

增加resizable的布尔类型

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

Summary by CodeRabbit

  • 新功能
    • 抽屉组件新增布尔开关以快速启用/禁用“可调整大小”,同时保留原有回调配置方式。
    • 启用后将自动显示拖拽手柄,支持尺寸变化、开始与结束回调。
    • 与现有用法向后兼容,无需修改既有配置。

Copy link

vercel bot commented Sep 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
drawer Ready Ready Preview Comment Sep 22, 2025 1:01pm

Copy link
Contributor

Summary of Changes

Hello @cactuser-Lu, 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!

This pull request introduces a significant enhancement to the Drawer and DrawerPopup components by extending the functionality of the resizable property. Previously limited to an object for detailed configuration, the resizable prop can now accept a simple boolean value. This change streamlines the process of enabling or disabling the drawer's resizing capability, offering developers a more straightforward and flexible way to manage UI behavior without sacrificing the option for advanced customization.

Highlights

  • Enhanced resizable Prop Type: The resizable prop in both DrawerProps and DrawerPopupProps now supports a boolean type, allowing for simple true or false values to enable or disable resizing, in addition to the existing object-based configuration.
  • Adapted Resizing Logic: The internal logic within the DrawerPopup component has been updated to correctly interpret the resizable prop, distinguishing between boolean values and object configurations to determine if resizing is active and to extract any provided callback functions.
  • Conditional Drag Element Rendering: The drag handle element is now conditionally rendered based on the new isResizable boolean flag, ensuring it only appears when resizing is explicitly enabled.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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 增加了对 resizable prop 的布尔类型支持,使得 API 更加灵活易用。整体实现很不错。我只在 src/DrawerPopup.tsx 中发现一处可以简化逻辑的地方,并提供了代码建议以提高代码的可读性和简洁性。请查看我的评论。

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link

coderabbitai bot commented Sep 22, 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

此变更将 Drawer 与 DrawerPopup 的 resizable 属性从仅支持配置对象扩展为支持布尔值或配置对象。DrawerPopup 内部新增规范化逻辑以统一处理回调与渲染可拖拽句柄的条件,无新增控制流程分支,仅替换访问方式与判定变量。

Changes

Cohort / File(s) Change Summary
Public API:resizable 支持 boolean 联合类型
src/Drawer.tsx, src/DrawerPopup.tsx
resizable?: { ... } 改为 resizable?: boolean | { onResize?: (size:number); onResizeStart?:()=>void; onResizeEnd?:()=>void },对外导出类型更新。
内部规范化与渲染条件更新
src/DrawerPopup.tsx
新增 isResizable = !!resizable 与 `resizeConfig = (typeof resizable === 'object' && resizable)

Sequence Diagram(s)

sequenceDiagram
  actor User as User
  participant Handle as DraggableHandle
  participant DrawerPopup as DrawerPopup
  participant Hook as useDrag
  participant Callbacks as resizeConfig(onResize/Start/End)

  Note over DrawerPopup: 规范化<br/>isResizable = !!resizable<br/>resizeConfig = object或{}

  User->>DrawerPopup: 打开抽屉
  alt isResizable 为真
    DrawerPopup->>Handle: 渲染拖拽句柄
    User->>Handle: 拖拽开始
    Handle->>Hook: onResizeStart
    Hook->>Callbacks: onResizeStart?()
    User->>Handle: 拖拽中(size)
    Handle->>DrawerPopup: onInternalResize(size)
    DrawerPopup->>Callbacks: onResize?(size)
    User->>Handle: 拖拽结束
    Handle->>Hook: onResizeEnd
    Hook->>Callbacks: onResizeEnd?()
  else 不可调整大小
    Note over DrawerPopup: 不渲染句柄,忽略回调
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

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 提供的标题 “feat: support boolean for resizable” 简洁且直接反映了变更集的核心:为 resizable 属性增加对 boolean 的支持,与 PR 描述和文件改动一致,未包含无关信息或模糊措辞,适合团队快速浏览历史记录。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

codecov bot commented Sep 22, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #538   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          216       218    +2     
  Branches        79        80    +1     
=========================================
+ Hits           216       218    +2     

☔ 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: 1

🧹 Nitpick comments (4)
src/Drawer.tsx (1)

43-50: 公共 API 变更 OK,但建议去重并抽出共享类型以避免未来漂移

DrawerProps 已继承 DrawerPopupProps,这里再次声明 resizable 容易产生重复与类型偏差。建议:

  • 方案 A:直接移除 DrawerProps 中的重复声明,沿用继承的定义;
  • 方案 B:在 inter.ts 抽出 ResizeConfig,两处统一引用,避免多处粘贴。

示例(方案 B):

-  /** Resizable configuration - boolean to enable/disable or object with optional callbacks */
-  resizable?:
-    | boolean
-    | {
-        onResize?: (size: number) => void;
-        onResizeStart?: () => void;
-        onResizeEnd?: () => void;
-      };
+  /** Resizable configuration - boolean to enable/disable or object with optional callbacks */
+  resizable?: boolean | ResizeConfig;

并在 inter.ts 新增:

export type ResizeConfig = {
  onResize?: (size: number) => void;
  onResizeStart?: () => void;
  onResizeEnd?: () => void;
};

DrawerPopup.tsx 同步改为 resizable?: boolean | ResizeConfig;

src/DrawerPopup.tsx (3)

88-95: API 扩展方向正确,但建议复用共享类型,避免重复定义

类型从配置对象扩展为 boolean | { ... } 没问题。为降低重复与后续维护成本,建议抽出 ResizeConfig(放在 inter.ts),此处与 Drawer.tsx 统一为:

-  resizable?:
-    | boolean
-    | {
-        onResize?: (size: number) => void;
-        onResizeStart?: () => void;
-        onResizeEnd?: () => void;
-      };
+  resizable?: boolean | ResizeConfig;

341-343: 可选:用 useEvent 包装起止回调,避免闭包陈旧与引用抖动

useDrag 若在挂载时订阅回调,直接传入 props 可能造成闭包陈旧或频繁变更。建议(可选):

-    onResizeStart: resizeConfig.onResizeStart,
-    onResizeEnd: resizeConfig.onResizeEnd,
+    onResizeStart: resizeConfig.onResizeStart ? useEvent(resizeConfig.onResizeStart) : undefined,
+    onResizeEnd: resizeConfig.onResizeEnd ? useEvent(resizeConfig.onResizeEnd) : undefined,

402-402: 验证拖拽把手的可访问性语义(A11y)

请确认 dragElementProps 是否包含:

  • role="separator" 与正确的 aria-orientation
  • 可键盘操作(箭头键/Shift+箭头)与相应 aria-valuenow/max/min(如适用);
  • 合理的命中区域与可见焦点样式。

若未包含,建议在 useDrag 内补齐语义或此处加属性。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d84d7ac and 3f75e07.

📒 Files selected for processing (2)
  • src/Drawer.tsx (1 hunks)
  • src/DrawerPopup.tsx (4 hunks)
🔇 Additional comments (1)
src/DrawerPopup.tsx (1)

329-329: 回调改为走归一化配置,方向正确

onInternalResize 内置状态更新并透传到 resizeConfig.onResize,与布尔/对象两种形态兼容,符合预期。建议补充一个用例覆盖 “resizable = true 时内部尺寸仍能更新(无回调)”。

Comment on lines +324 to +326
const isResizable = !!resizable;
const resizeConfig = (typeof resizable === 'object' && resizable) || {};

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

运行时判断简洁,但 TS 类型不安全(严格模式下会报错)

resizeConfig 目前推断为 {},后续访问 resizeConfig.onResize 可能触发 “Property 'onResize' does not exist on type '{}'” 的编译错误。建议显式标注类型并 useMemo 避免每次 render 生成新对象:

-  const isResizable = !!resizable;
-  const resizeConfig = (typeof resizable === 'object' && resizable) || {};
+  const isResizable = Boolean(resizable);
+  type ResizeCfg = Exclude<NonNullable<DrawerPopupProps['resizable']>, boolean>;
+  const resizeConfig: Partial<ResizeCfg> = React.useMemo(
+    () => (typeof resizable === 'object' && resizable) ? resizable : {},
+    [resizable],
+  );

如已在 inter.ts 抽出 ResizeConfig,则将 ResizeCfg 替换为 ResizeConfig 更清晰。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isResizable = !!resizable;
const resizeConfig = (typeof resizable === 'object' && resizable) || {};
const isResizable = Boolean(resizable);
type ResizeCfg = Exclude<NonNullable<DrawerPopupProps['resizable']>, boolean>;
const resizeConfig: Partial<ResizeCfg> = React.useMemo(
() => (typeof resizable === 'object' && resizable) ? resizable : {},
[resizable],
);
🤖 Prompt for AI Agents
In src/DrawerPopup.tsx around lines 324-326, the runtime checks set resizeConfig
to {} which TypeScript infers as an empty object and can cause "Property
'onResize' does not exist on type '{}'" errors in strict mode; change the
declaration to an explicitly typed constant (use the ResizeConfig type exported
from inter.ts or rename ResizeCfg → ResizeConfig) and wrap the computed value in
useMemo so you return either the provided object or a typed empty object without
recreating it each render (e.g., const resizeConfig: ResizeConfig = useMemo(()
=> (typeof resizable === 'object' && resizable) || {}, [resizable])).

@afc163 afc163 merged commit 1f9af53 into react-component:master Sep 22, 2025
8 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