Skip to content

add: The table stripe display can be set. #1290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

huyunan
Copy link

@huyunan huyunan commented Jun 5, 2025

add: The table stripe display can be set.

Summary by CodeRabbit

  • 新功能
    • 表格组件新增条纹行(striped row)样式支持,通过设置属性可为表格奇数行添加背景色区分。
    • 新增条纹表格的示例和相关文档,方便用户了解和使用该功能。
  • 样式
    • 增加了条纹行的样式规则,提升表格可读性。

Copy link

vercel bot commented Jun 5, 2025

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

Name Status Preview Comments Updated (UTC)
table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2025 0:54am

Copy link

coderabbitai bot commented Jun 5, 2025

Walkthrough

本次更新为表格组件引入了条纹行(斑马线)功能。通过新增 stripe 属性,用户可以启用奇数行高亮显示。相关样式、属性声明、逻辑处理以及文档和示例均已同步更新,无其他控制流或导出接口变更。

Changes

文件/分组 变更简述
assets/index.less 新增 .rc-table-row-striped 样式规则,实现条纹行背景色。
docs/demo/stripe.md 新增文档,介绍条纹表格用法并嵌入示例代码。
docs/examples/stripe.tsx 新增 React 条纹表格示例组件,演示 stripe 属性的使用。
src/Body/index.tsx BodyProps 新增 stripe 属性,渲染逻辑支持条纹行样式。
src/Table.tsx TableProps 新增可选 stripe 属性,并向下传递给 Body

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Table
    participant Body
    participant BodyRow

    User->>Table: 设置 stripe 属性
    Table->>Body: 传递 stripe 属性
    loop 渲染每一行
        Body->>BodyRow: 如果 stripe=true 且 index 为奇数,添加 row-striped 类
    end
Loading

Suggested reviewers

  • zombieJ

Poem

斑马线条轻轻添,
表格焕新换新颜。
奇偶分明添趣味,
代码跃动似兔前。
🐇
祝你使用更顺心,
条纹之美伴你行!

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.

docs/examples/stripe.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.

src/Body/index.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.

src/Table.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.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

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

🧹 Nitpick comments (6)
assets/index.less (1)

58-62: 建议优化条纹行颜色选择

当前使用的 #fcf4f4(浅粉色)作为条纹行背景色可能不够理想。建议使用更传统和易读的中性色。

  &-row-striped {
    .@{tablePrefixCls}-cell {
-     background: #fcf4f4;
+     background: #fafafa;
    }
  }

或者使用更标准的表格条纹色:#f5f5f5

src/Body/index.tsx (1)

100-103: 条纹行逻辑实现正确但可考虑优化

当前逻辑使用 idx % 2 === 1 会让第2、4、6...行显示条纹。这在技术上是正确的,但通常用户期望第1、3、5...行显示条纹。

如果需要让第1、3、5...行显示条纹,可以修改为:

  let className = '';
- if (stripe && idx % 2 === 1) {
+ if (stripe && idx % 2 === 0) {
    className = `${prefixCls}-row-striped`;
  }

当前实现在功能上是正确的,但请确认这是否符合预期的视觉效果。

docs/examples/stripe.tsx (4)

1-4: 可移除 React 默认导入(可选)
若使用 React 17+ 的新版 JSX 转换,可删除 import React from 'react' 以简化示例。


6-10: 建议将接口字段设为必填
示例数据中所有字段均已提供,接口 FieldType 中的 ? 可去除以增强类型安全。


30-37: 为示例数据添加类型注解
建议显式声明 const data: FieldType[] = [...],以进一步提升可读性和类型检查。


39-44: 建议为 Demo 组件添加类型注解
可以将 const Demo = () => ... 修改为 const Demo: React.FC = () => ...,提升类型提示和可维护性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dbf360d and 2c195ca.

📒 Files selected for processing (5)
  • assets/index.less (1 hunks)
  • docs/demo/stripe.md (1 hunks)
  • docs/examples/stripe.tsx (1 hunks)
  • src/Body/index.tsx (2 hunks)
  • src/Table.tsx (3 hunks)
🔇 Additional comments (6)
docs/demo/stripe.md (1)

1-8: 文档结构合理

文档格式正确,元数据设置恰当,示例引用方式符合规范。

src/Table.tsx (3)

133-133: 条纹属性添加正确

新增的 stripe 属性类型定义正确,作为可选布尔值符合预期使用场景。


212-212: 属性解构处理得当

stripe 属性正确地从 props 中解构,遵循了组件的标准模式。


631-631: 属性传递实现正确

stripe 属性正确传递给 Body 组件,保持了组件间的数据流一致性。

docs/examples/stripe.tsx (2)

12-28: 列定义清晰且类型安全
columns 的声明使用了 TableProps<FieldType>['columns'],实现符合预期。


39-44:

✅ Verification successful

验证 stripe 属性是否在 TableProps 中声明
请确认 src/Table.tsx 的类型定义中已包含 stripe?: boolean


🏁 Script executed:

#!/bin/bash
# 验证 TableProps 中是否声明 stripe 属性
ast-grep --pattern $'interface TableProps<$_> { $$$ stripe?: boolean $$$ }' src/Table.tsx

Length of output: 90


继续验证 stripe 属性是否在 TableProps 中声明:


🏁 Script executed:

#!/bin/bash
# 在整个项目中搜索 TableProps 接口及 stripe 属性
rg "interface TableProps" -n .
rg "stripe\\?" -n src

Length of output: 158


确认:stripe 属性已在 TableProps 中声明
src/Table.tsx 第133行已定义 stripe?: boolean;,无需额外调整。

}

function Body<RecordType>(props: BodyProps<RecordType>) {
if (process.env.NODE_ENV !== 'production') {
devRenderTimes(props);
}

const { data, measureColumnWidth } = props;
const { data, measureColumnWidth, stripe } = props;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

添加默认值处理

应该为 stripe 属性提供默认值,确保在未传递该属性时的正确行为。

- const { data, measureColumnWidth, stripe } = props;
+ const { data, measureColumnWidth, stripe = false } = props;
📝 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 { data, measureColumnWidth, stripe } = props;
const { data, measureColumnWidth, stripe = false } = props;
🤖 Prompt for AI Agents
In src/Body/index.tsx at line 25, the destructured prop 'stripe' lacks a default
value, which may cause issues if it is undefined. Update the destructuring
assignment to provide a default value for 'stripe', such as 'false' or another
appropriate default, ensuring consistent behavior when the prop is not passed.

@@ -14,14 +14,15 @@ import cls from 'classnames';
export interface BodyProps<RecordType> {
data: readonly RecordType[];
measureColumnWidth: boolean;
stripe: boolean;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复类型定义不一致问题

BodyProps 中的 stripe 属性应该标记为可选,以与 TableProps 中的定义保持一致。

export interface BodyProps<RecordType> {
  data: readonly RecordType[];
  measureColumnWidth: boolean;
- stripe: boolean;
+ stripe?: boolean;
}
📝 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
stripe: boolean;
export interface BodyProps<RecordType> {
data: readonly RecordType[];
measureColumnWidth: boolean;
stripe?: boolean;
}
🤖 Prompt for AI Agents
In src/Body/index.tsx at line 17, the stripe property in the BodyProps interface
is currently required but should be marked as optional to match the definition
in TableProps. Update the type definition by adding a question mark after stripe
to indicate it is optional.

Copy link

codecov bot commented Jun 21, 2025

Codecov Report

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

Project coverage is 95.64%. Comparing base (7bb3620) to head (ece290b).

Files with missing lines Patch % Lines
src/Body/index.tsx 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1290      +/-   ##
==========================================
- Coverage   95.69%   95.64%   -0.06%     
==========================================
  Files          57       57              
  Lines        3391     3397       +6     
  Branches      655      656       +1     
==========================================
+ Hits         3245     3249       +4     
- Misses        121      123       +2     
  Partials       25       25              

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

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