Skip to content

Conversation

@chenxi-20
Copy link
Collaborator

@chenxi-20 chenxi-20 commented Apr 14, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced a new property to adjust the scroll offset from the top for anchor components.
    • Added demonstration components and demos showcasing this top offset capability.
  • Refactor

    • Simplified the navigation structure by flattening previously nested link arrays for a cleaner user interface.
  • Tests

    • Updated test cases to verify the revised behavior of anchor links and the new scroll offset functionality.

@chenxi-20 chenxi-20 added the documentation 对文档的改进或补充 label Apr 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 14, 2025

Walkthrough

The changes introduce a new offset-top property for the anchor component that adjusts the scroll position. The navigation link configurations in several Vue demo components have been restructured by flattening nested arrays and renaming keys. Test expectations have been updated accordingly. New demo components and a corresponding test for the offset-top functionality have been added, and the documentation has been updated to include a demo and feature entry for the new property.

Changes

File(s) Change Summary
.../apis/anchor.js Added new offset-top property to the anchor component with type number, default value 0, bilingual description, metadata (stable: 3.19.0), and applicable mode.
.../pc/app/anchor/{basic-usage-composition-api.vue, basic-usage.vue, change-composition-api.vue, change.vue, is-affix-composition-api.vue, is-affix.vue, basic-usage.spec.ts} Restructured the links array by removing the nested 'demonstrate' object, flattening entries, renaming keys (from '演示' to '基本用法'), and adding the offset-top link; updated hash value assertions in tests.
.../pc/app/anchor/{offset-top-composition-api.vue, offset-top.vue, offset-top.spec.ts} Introduced new components and test case specifically for the offset-top functionality, setting the offset value to 500 for scroll position adjustment.
.../pc/app/anchor/webdoc/anchor.js Added a new demo entry and feature for offset-top including bilingual names, descriptions, and reference to the offset-top.vue code.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant A as TinyAnchor Component
    participant B as Browser
    U->>A: Click "顶部偏移量" link
    A->>A: Read offset-top prop (500)
    A->>B: Calculate and adjust scroll position by offset-top
    B-->>A: Update URL hash to "#offset-top"
    A-->>U: Render updated view
Loading

Poem

I'm a little rabbit hopping through code,
Found an "offset-top" that lightens the load.
My links are now flat like a summer field,
With tests and demos, new stories revealed.
Bugs hop away, replaced by clear delight,
As I nibble on carrots of code each night.

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.

examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/apis/anchor.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/pc/app/anchor/basic-usage.spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 9 others

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@petercat-assistant
Copy link

Walkthrough

此PR为Anchor组件增加了offsetTop API文档,并优化了相关示例文档。主要更新包括在API文档中添加offset-top属性的描述,调整示例代码以展示新属性的使用。

Changes

文件 概要
examples/sites/demos/apis/anchor.js 添加offset-top属性的API文档。
examples/sites/demos/pc/app/anchor/*.vue 更新示例代码以展示offset-top属性的使用。
examples/sites/demos/pc/app/anchor/*.spec.ts 更新测试用例以验证offset-top属性的功能。
examples/sites/demos/pc/app/anchor/webdoc/anchor.js 在文档中添加offset-top属性的描述。


await expect(hash2).not.toEqual(hash1)
await expect(hash2).toContain('#demonstrate')
await expect(hash2).toEqual(hash1)

Choose a reason for hiding this comment

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

The test expectation has been changed from not.toEqual to toEqual, which might affect the test logic. Please ensure this change is intentional and aligns with the desired test behavior.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Walkthrough

This PR adds the offsetTop API documentation for the Anchor component and optimizes the relevant sample documentation. The main update includes adding a description of the offset-top attribute in the API documentation, adjusting the sample code to show the use of new attributes.

Changes

Documents Summary
examples/sites/demos/apis/anchor.js Add the offset-top attribute API documentation.
examples/sites/demos/pc/app/anchor/*.vue Update the sample code to show the use of the offset-top property.
examples/sites/demos/pc/app/anchor/*.spec.ts Update test cases to verify the functionality of the offset-top property.
examples/sites/demos/pc/app/anchor/webdoc/anchor.js Add a description of the offset-top property in the document.

@chenxi-20 chenxi-20 changed the title docs: [anchor] 增加offsetTop API文档,并优化示例文档 docs: [anchor] Add offset Top API documentation and optimize example documentation Apr 14, 2025
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 (3)
examples/sites/demos/pc/app/anchor/offset-top.vue (1)

1-44: New demo for offset-top functionality created using Options API.

This new component demonstrates the offsetTop property with a value of 500, showing how to adjust the scroll position of the anchor component.

However, I noticed that the property is camelCased as :offsetTop="500" while in other files it's kebab-cased as :offset-top="500". While both may work due to Vue's automatic case conversion, it's best to keep naming conventions consistent across all demo files.

-  <tiny-anchor :links="links" :offsetTop="500"></tiny-anchor>
+  <tiny-anchor :links="links" :offset-top="500"></tiny-anchor>
examples/sites/demos/pc/app/anchor/webdoc/anchor.js (1)

149-162: Appropriate feature documentation for offset-top

The feature documentation for offset-top is complete and consistent with the other feature entries. It correctly:

  1. Specifies the feature ID and name
  2. Sets the support value to true
  3. Provides a clear description
  4. Links to the relevant API and demo

Note: The comment on line 149 ("// 在features数组中添加新的特性说明") could be removed as it's not necessary in the final code.

-    // 在features数组中添加新的特性说明
    {
      id: 'offset-top',
examples/sites/demos/apis/anchor.js (1)

59-73: Well-documented API property for offset-top

The API documentation for the offset-top property is thorough and follows the same structure as other properties. It correctly:

  1. Defines the property name, type, and default value
  2. Provides clear descriptions in both Chinese and English explaining the property's purpose
  3. Includes metadata about the stable version (3.19.0)
  4. Specifies the applicable mode (pc)
  5. Links to the corresponding demo

The comment on line 59 ("// 添加offset-top属性文档") could be removed as it's not necessary in the final code.

-        // 添加offset-top属性文档
        {
          name: 'offset-top',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dfdc4e and 60fb6b0.

📒 Files selected for processing (12)
  • examples/sites/demos/apis/anchor.js (1 hunks)
  • examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/basic-usage.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/anchor/basic-usage.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/change-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/change.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/is-affix-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/is-affix.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/offset-top-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/offset-top.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/anchor/offset-top.vue (1 hunks)
  • examples/sites/demos/pc/app/anchor/webdoc/anchor.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (11)
examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue (1)

13-38: Link structure improved and new offset-top functionality added.

The links array has been restructured for better organization and now includes a new entry for the 'offset-top' functionality. This change aligns with the PR objectives to enhance the documentation for the offsetTop API.

examples/sites/demos/pc/app/anchor/offset-top-composition-api.vue (1)

1-36: New demo for offset-top functionality created using Composition API.

This component correctly demonstrates the offset-top property using Composition API. The property is properly kebab-cased as :offset-top="500", which aligns with Vue's recommended property naming convention for templates.

examples/sites/demos/pc/app/anchor/change-composition-api.vue (1)

9-35: Link structure improved and offset-top entry added.

The links array has been restructured for better organization, removing the nested structure and adding the new 'offset-top' entry. This change is consistent with the modifications made in other files and improves the overall documentation structure.

examples/sites/demos/pc/app/anchor/change.vue (1)

15-39: Good restructuring of links array

The changes you've made to the links array are good. You've successfully flattened the structure, making it more straightforward, and added the new offset-top entry. This restructuring makes the navigation data easier to understand and aligns with the changes in other anchor-related files.

examples/sites/demos/pc/app/anchor/offset-top.spec.ts (1)

1-19: Well-structured test for the offset-top feature

The test for the new offset-top feature is well-structured and comprehensive. It correctly:

  1. Sets up error handling to catch any unexpected exceptions
  2. Navigates to the specific anchor page
  3. Tests interaction with different links
  4. Verifies that the hash changes appropriately

The test effectively validates that the new offset-top functionality works as expected.

examples/sites/demos/pc/app/anchor/webdoc/anchor.js (1)

45-56: Good documentation for the offset-top demo

The demo documentation for the offset-top feature is well-structured and provides clear descriptions in both Chinese and English. The description appropriately explains how to use the offset-top property to set the offset from the top of the anchor.

examples/sites/demos/pc/app/anchor/basic-usage.spec.ts (2)

8-8: Updated link name matches the new navigation structure.

The link name has been changed from '演示' to '基本用法' to align with the flattened navigation structure where the first link now directly represents the basic usage example.


15-16: Test expectations updated correctly to match new navigation behavior.

The test expectations have been properly updated to reflect the new navigation structure:

  1. Now expecting hash2 to equal hash1 since clicking the same page link shouldn't change the hash
  2. Hash expectation has been updated from '#demonstrate' to '#basic-usage' to match the new link structure

These changes align well with the updated navigation design where we're now directly on the basic-usage page.

examples/sites/demos/pc/app/anchor/is-affix-composition-api.vue (1)

17-41: Navigation structure improved with flattened links array and new offset-top option.

The links array has been restructured by:

  1. Removing the nested 'demonstrate' parent object with its children array
  2. Flattening the navigation structure with direct entries
  3. Adding a new entry for 'offset-top' to showcase the new functionality

This is a positive change that simplifies the code structure while adding the new feature documentation.

examples/sites/demos/pc/app/anchor/is-affix.vue (1)

23-47: Navigation structure improved with flattened links array and new offset-top option.

The links array has been restructured by:

  1. Removing the nested 'demonstrate' parent object with its children array
  2. Flattening the navigation structure with direct entries
  3. Adding a new entry for 'offset-top' to showcase the new functionality

This simplification makes the code more maintainable while adding documentation for the new feature.

examples/sites/demos/pc/app/anchor/basic-usage.vue (1)

22-46: Navigation structure improved with flattened links array and new offset-top option.

The links array has been restructured by:

  1. Removing the nested 'demonstrate' parent object with its children array
  2. Flattening the navigation structure with direct entries
  3. Adding a new entry for 'offset-top' to showcase the new functionality

This change simplifies the code structure and consistently adds the new offset-top feature documentation across all anchor examples.

@chenxi-20 chenxi-20 changed the title docs: [anchor] Add offset Top API documentation and optimize example documentation docs: [anchor] Add offsetTop API documentation and optimize example documentation Apr 14, 2025
@zzcr zzcr merged commit 542acda into dev Apr 15, 2025
18 of 21 checks passed
@zzcr zzcr deleted the docs/anchor-202250414 branch April 15, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 对文档的改进或补充

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants