Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 21, 2025

Summary by CodeRabbit

  • 文档更新

    • 新增了展示交互式引导体验的演示页面及导航设置。
  • 新功能

    • 引入了交互式引导体验,用户可通过点击按钮启动引导步骤,同时支持默认显示。
    • 优化了弹出窗口及遮罩层的定位与显示逻辑,确保在内联模式下展示更准确。
    • 新增了支持自定义弹出容器的功能,提升了组件的灵活性。
  • 测试

    • 为交互式引导组件新增了测试用例,验证其在特定内联上下文中的渲染效果。

Copy link

vercel bot commented Feb 21, 2025

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

Name Status Preview Comments Updated (UTC)
tour ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 9:56am

Copy link

github-actions bot commented Feb 21, 2025

😭 Deploy PR Preview 660aac7 failed. Build logs

🤖 By surge-preview

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.01%. Comparing base (e840ed3) to head (660aac7).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Mask.tsx 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
- Coverage   99.47%   99.01%   -0.46%     
==========================================
  Files           9        9              
  Lines         190      203      +13     
  Branches       86       94       +8     
==========================================
+ Hits          189      201      +12     
- Misses          1        2       +1     

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

Copy link

coderabbitai bot commented Feb 21, 2025

Warning

Rate limit exceeded

@zombieJ has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 978c725 and 660aac7.

📒 Files selected for processing (1)
  • src/hooks/useTarget.ts (2 hunks)

Walkthrough

本次更新在文档与核心组件中引入了新的示例和功能调整。新增的 demo 文件配置了前置信息并引用了示例组件,而示例组件中实现了基于按钮触发的 Tour 交互。核心组件中新增了 defaultOpengetPopupContainer 属性,并对 mask 定位、位置计算以及 inline 模式下的弹出容器做了相应优化,同时对定位逻辑的计算流程进行了调整以支持更精准的位置控制。

Changes

文件 更改摘要
docs/demo/inline.md, docs/examples/inline.tsx 新增 demo 文档及示例组件:markdown 文件含前置信息与代码块引用;TSX 文件新增 App 组件,利用 Tour 实现交互式指引与状态控制。
src/Mask.tsx, src/Tour.tsx, src/hooks/useTarget.ts, src/interface.ts 更新核心组件与接口:新增 defaultOpengetPopupContainer 属性;调整 mask 定位(支持 inline 模式)、Portal 配置及位置计算逻辑,扩展 useTarget 的定位能力。

Sequence Diagram(s)

sequenceDiagram
    participant User as 用户
    participant App as App组件
    participant Tour as Tour组件
    participant Mask as Mask/Portal组件
    participant Hook as useTarget

    User->>App: 点击 "Show" 按钮
    App->>Tour: 将 open 状态设为 true
    Tour->>Mask: 渲染提示框,传递 getPopupContainer 与 inlineMode 信息
    Mask->>Hook: 计算定位,处理 inline 模式调整
    Hook-->>Mask: 返回计算后位置
    Mask-->>Tour: 显示交互式指引步骤
Loading

Poem

我是一只快乐的小兔子,在代码花园中轻盈跳跃,
新功能如胡萝卜般鲜甜,让我心花怒放。
文档与组件齐放光彩,布局精准又灵动,
交互流畅如春风拂面,代码世界乐无穷。
让我们一同畅游代码林,共创明日新奇梦! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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.

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 (9)
docs/examples/inline.tsx (4)

19-19: 移除注释掉的代码

为了保持代码整洁,建议移除未使用的注释代码。

-          // justifyContent: 'right',

42-42: 移除注释掉的样式代码

为了保持代码整洁,建议移除未使用的注释样式。

-          // style={{ background: 'red' }}

25-33: 增加无障碍属性

按钮缺少适当的 ARIA 属性和角色定义,这对于屏幕阅读器用户来说可能不够友好。

 <button
   className="ant-target"
   ref={createBtnRef}
+  aria-label="显示引导"
+  role="button"
   onClick={() => {
     setOpen(true);
   }}
 >
   Show
 </button>

45-46: 国际化文案

建议将硬编码的中文文案提取到国际化配置中。

 {
-  title: '创建',
-  description: '创建一条数据',
+  title: intl.formatMessage({ id: 'tour.create.title' }),
+  description: intl.formatMessage({ id: 'tour.create.description' }),
src/interface.ts (2)

56-56: 添加属性文档注释

为新增的 defaultOpen 属性添加 JSDoc 注释,说明其用途和默认值。

+  /** 设置 Tour 的默认展开状态 @default false */
   defaultOpen?: boolean;

80-80: 补充 getPopupContainer 文档

getPopupContainer 属性添加详细的文档注释,说明 false 值的特殊含义。

+  /**
+   * 指定弹出层的容器。当设置为 false 时启用内联模式,
+   * 弹出层将相对于父容器定位
+   * @default () => document.body
+   */
   getPopupContainer?: TriggerProps['getPopupContainer'] | false;
src/Mask.tsx (2)

52-57: 提取浏览器检测逻辑

建议将 Safari 检测逻辑移至单独的工具函数,以提高代码的可维护性和可测试性。

+// utils/browser.ts
+export const isSafari = typeof navigator !== 'undefined' && 
+  /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

+// Mask.tsx
-  const isSafari =
-    typeof navigator !== 'undefined' &&
-    /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
+  const isSafari = utils.isSafari;
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 56-56: src/Mask.tsx#L56
Added line #L56 was not covered by tests


144-145: 简化遮罩尺寸计算

建议使用 CSS 变量来简化遮罩尺寸的计算逻辑。

+  const maskStyle = {
+    '--mask-top': `${pos.top}px`,
+    '--mask-left': `${pos.left}px`,
+    '--mask-width': `${pos.width}px`,
+    '--mask-height': `${pos.height}px`,
+  };

   <rect
     {...COVER_PROPS}
     x="0"
     y={pos.top + pos.height}
     width="100%"
-    height={`calc(100% - ${pos.top + pos.height}px)`}
+    height="calc(100% - var(--mask-top) - var(--mask-height))"
   />
   <rect
     {...COVER_PROPS}
     x={pos.left + pos.width}
     y="0"
-    width={`calc(100% - ${pos.left + pos.width}px)`}
+    width="calc(100% - var(--mask-left) - var(--mask-width))"
     height="100%"
   />

Also applies to: 151-153

src/Tour.tsx (1)

118-130: 建议完善内联模式的文档说明

新增的内联模式(getPopupContainer === false)是一个重要的功能变更,建议:

  1. 在组件文档中详细说明这个特性
  2. 添加示例代码展示如何使用内联模式
  3. 说明内联模式与默认模式的区别和使用场景
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e840ed3 and dfced54.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • docs/demo/inline.md (1 hunks)
  • docs/examples/inline.tsx (1 hunks)
  • src/Mask.tsx (4 hunks)
  • src/Tour.tsx (7 hunks)
  • src/hooks/useTarget.ts (2 hunks)
  • src/interface.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/demo/inline.md
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/hooks/useTarget.ts

[warning] 61-62: src/hooks/useTarget.ts#L61-L62
Added lines #L61 - L62 were not covered by tests

src/Mask.tsx

[warning] 56-56: src/Mask.tsx#L56
Added line #L56 was not covered by tests

🔇 Additional comments (3)
src/hooks/useTarget.ts (1)

59-66: 添加单元测试

新增的内联模式相关代码缺少测试覆盖,建议添加相应的单元测试。

请添加以下测试场景:

  1. 内联模式启用时的位置计算
  2. placeholderRef 为 null 的情况
  3. parentElement 为 null 的情况
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 61-62: src/hooks/useTarget.ts#L61-L62
Added lines #L61 - L62 were not covered by tests

src/Mask.tsx (1)

52-57: 添加 Safari 相关测试

Safari 特定的代码路径缺少测试覆盖,建议添加相应的单元测试。

请添加以下测试场景:

  1. Safari 环境下的遮罩尺寸计算
  2. 非 Safari 环境下的遮罩尺寸计算
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 56-56: src/Mask.tsx#L56
Added line #L56 was not covered by tests

src/Tour.tsx (1)

41-41: 新增的 defaultOpen 属性实现得当!

使用 useMergedState 正确处理了受控与非受控模式的状态管理,符合 React 最佳实践。

Also applies to: 70-76

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

🧹 Nitpick comments (1)
tests/index.test.tsx (1)

1201-1227: 测试用例实现得很好!

测试用例清晰地验证了 Tour 组件的内联渲染功能。代码结构良好,断言明确。

建议考虑添加以下边缘情况的测试:

  • 当目标按钮不存在时的行为
  • 当容器尺寸变化时的行为
  • 当有多个 Tour 步骤时的内联渲染
 it('inline', async () => {
   const Demo = () => {
     const btnRef = useRef<HTMLButtonElement>(null);
+    const [show, setShow] = useState(true);
     return (
       <div className="bamboo">
-        <button ref={btnRef}>按钮</button>
+        {show && <button ref={btnRef}>按钮</button>}
         <Tour
           open
           getPopupContainer={false}
           steps={[
             {
               title: '创建',
               description: <div className="little" />,
               target: () => btnRef.current,
             },
+            {
+              title: '第二步',
+              description: <div className="second" />,
+              target: () => btnRef.current,
+            },
           ]}
         />
+        <button onClick={() => setShow(false)}>移除目标</button>
       </div>
     );
   };
   render(<Demo />);
   
   // 验证初始渲染
   const container = document.querySelector('.bamboo');
   expect(container.querySelector('.little')).toBeTruthy();
   
+  // 验证多步骤
+  fireEvent.click(screen.getByRole('button', { name: 'Next' }));
+  expect(container.querySelector('.second')).toBeTruthy();
+  
+  // 验证目标消失的情况
+  fireEvent.click(screen.getByRole('button', { name: '移除目标' }));
+  expect(container.querySelector('.little')).toBeTruthy();
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dfced54 and 978c725.

📒 Files selected for processing (2)
  • src/hooks/useTarget.ts (2 hunks)
  • tests/index.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useTarget.ts

@zombieJ zombieJ merged commit 929d25b into master Feb 21, 2025
10 of 12 checks passed
@zombieJ zombieJ deleted the inline branch February 21, 2025 14:10
@coderabbitai coderabbitai bot mentioned this pull request Feb 23, 2025
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