Skip to content

feat: support classNames and styles #1261

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

thinkasany
Copy link

@thinkasany thinkasany commented Apr 22, 2025

Summary by CodeRabbit

  • 新功能

    • 表格组件现支持为各个语义部分(如标题、页脚、表头、内容区、行等)自定义 className 和内联样式,提升了样式定制能力。
    • 示例文档新增演示,展示了表格标题/页脚渲染和可滚动表格的用法。
  • 测试

    • 新增测试用例,验证自定义 className 和样式在表格各部分的正确应用。

Copy link

vercel bot commented Apr 22, 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 Apr 25, 2025 4:42pm

Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

本次变更主要为 Table 组件及其相关子组件引入了对自定义 classNames 与 styles 的支持。通过在 TableProps 和 TableContextProps 中增加 classNames 和 styles 属性,开发者可为表格各语义部分(如 section、header、title、footer、body、content、item)灵活指定样式类名与内联样式。相关子组件(如 Cell、FixedHolder、Panel)也同步支持了这些属性。此外,新增了示例与测试用例,展示并验证了自定义样式功能的正确性和覆盖范围。

Changes

文件/路径 变更摘要
docs/examples/className.tsx 示例扩展:为 Table 组件添加 title/footer 展示,并新增带滚动条的 Table 用例,演示自定义样式能力。
src/Table.tsx 新增 SemanticName 类型,TableProps 增加 classNames/styles 属性,并在各语义节点应用这些自定义样式。
src/context/TableContext.tsx TableContextProps 增加 classNames、styles 属性,支持通过 context 传递自定义样式。
src/Cell/index.tsx 支持从 context 获取并应用 classNames.item 与 styles.item,允许单元格自定义样式。
src/FixedHolder/index.tsx 支持接收并合并 style 属性,允许固定头部容器自定义样式。
src/Panel/index.tsx TitleProps 增加 style 属性,Panel 组件支持自定义样式传递。
tests/semantic.spec.tsx 新增测试用例,验证 Table 组件在各语义节点正确应用自定义 classNames 与 styles。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Table
    participant TableContext
    participant Cell
    participant FixedHolder
    participant Panel

    User->>Table: 传入 classNames/styles 属性
    Table->>TableContext: 通过 Provider 传递 classNames/styles
    Table->>Panel: 渲染 title/footer,传递对应 classNames/styles
    Table->>FixedHolder: 渲染 header,传递 classNames/styles
    Table->>Cell: 渲染单元格,context 获取 classNames.item/styles.item
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.

src/context/TableContext.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/FixedHolder/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/Cell/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.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e9d89ed and 8fd21ea.

📒 Files selected for processing (3)
  • src/Cell/index.tsx (4 hunks)
  • src/FixedHolder/index.tsx (3 hunks)
  • src/context/TableContext.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Cell/index.tsx
  • src/FixedHolder/index.tsx
  • src/context/TableContext.tsx
✨ 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 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: 1

🔭 Outside diff range comments (1)
src/Table.tsx (1)

871-919: ⚠️ Potential issue

上下文依赖项列表需考虑新增属性

在 useMemo 依赖项列表中,没有包含新增的 classNamesstyles 属性。这可能导致当这些属性变化时,上下文值不会更新。

 [
      // Scroll
      mergedScrollX,
      scrollInfo,

+     // Styles
+     classNames,
+     styles,
+     
      // Table
      prefixCls,
      getComponent,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c02189e and e9d89ed.

📒 Files selected for processing (7)
  • docs/examples/className.tsx (1 hunks)
  • src/Cell/index.tsx (4 hunks)
  • src/FixedHolder/index.tsx (2 hunks)
  • src/Panel/index.tsx (1 hunks)
  • src/Table.tsx (9 hunks)
  • src/context/TableContext.tsx (2 hunks)
  • tests/semantic.spec.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/context/TableContext.tsx (1)
src/Table.tsx (1)
  • SemanticName (88-88)
docs/examples/className.tsx (1)
tests/FixedColumn-IE.spec.jsx (1)
  • columns (27-40)
🔇 Additional comments (20)
src/Panel/index.tsx (1)

9-10: 组件样式应用正确

Panel 组件正确地接收并应用了 style 属性,符合样式自定义的需求。

src/context/TableContext.tsx (2)

17-17: 导入 SemanticName 类型

正确导入了 SemanticName 类型,用于定义样式和类名的语义化键名。


27-29: 新增样式和类名支持

TableContextProps 接口中添加了三个可选属性:styleclassNamesstyles,这些属性正确使用了 TypeScript 类型,并且设置为可选,符合良好的 API 设计原则。

src/Cell/index.tsx (4)

2-2: 将 classnames 导入重命名为 cls

classnames 库的导入重命名为更简洁的 cls,这是一种常见的实践,可以避免与组件内部变量命名冲突。


125-126: 从上下文中获取样式和类名

TableContext 上下文中获取了 classNamesstyles 属性,用于支持单元格的样式自定义。


213-215: 应用自定义类名到单元格

正确地将上下文中的自定义类名 classNames?.item 应用到单元格的 className 中,使用 cls 函数合并多个类名。


251-251: 应用自定义样式到单元格

正确地将上下文中的自定义样式 styles?.item 应用到单元格的样式对象中,这使得用户可以自定义单元格的外观。

src/FixedHolder/index.tsx (2)

49-49: 添加样式属性到组件参数

正确地在组件的解构参数中添加了 style 属性,使组件能够接收外部传入的样式。


163-163: 合并自定义样式到组件

正确地将自定义样式与现有样式合并,确保了原有样式不会被覆盖,同时允许用户添加自定义样式。

tests/semantic.spec.tsx (1)

1-111: 测试用例设计全面,有效验证了自定义样式功能

测试文件对 Table 组件的 classNames 和 styles 属性进行了全面测试,覆盖了表格的各个语义部分(section, header, title, footer, body, content, item)。测试分别验证了普通表格和带滚动条的表格场景,确保样式在不同状态下都能正确应用。代码结构清晰,测试断言完整。

docs/examples/className.tsx (1)

55-68: 示例扩展有助于用户理解功能

新增的 title 和 footer 示例,以及带滚动功能的表格示例,能有效帮助用户理解如何使用这些新特性。示例代码简洁明了,展示了实际使用场景。

src/Table.tsx (9)

28-28: import 命名更改保持一致性

classnames 导入重命名为 cls,保持了代码库内部的命名一致性。


88-95: 类型定义清晰且符合语义化设计

新增的 SemanticName 类型和 TableProps 接口扩展设计合理,使用 Partial<Record<...>> 允许用户只指定需要的部分,提高了 API 的灵活性。


196-197: 属性解构位置适当

在组件属性解构中适当位置添加了 classNamesstyles 属性,便于后续使用。


663-667: 样式合并实现优雅

表格体(body)部分的自定义样式合并实现优雅,既保留了原有的滚动样式,又允许用户自定义样式覆盖。使用 cls 函数合并类名也很合理。


707-708: 表头样式应用方式与其他部分一致

表头部分的样式应用方式与其他表格部分保持一致,保持了代码的一致性和可预测性。


749-751: 内容区域样式应用合理

表格内容区域样式应用方式与其他部分一致,同时保留了原有的滚动样式特性。


784-784: 类名合并使用 cls 保持一致性

将原有的 classnames 函数调用改为使用重命名后的 cls,保持了代码一致性。


803-807: 标题和页脚组件样式应用完整

标题和页脚组件应用样式的实现细致全面,同时处理了类名和内联样式,并保持了组件的原有功能。


823-824: 在上下文中添加样式属性

在 TableContextValue 中添加 classNames 和 styles 属性,使得这些样式配置可以传递给子组件,这是实现全局样式定制的关键。

@@ -3,10 +3,11 @@ import * as React from 'react';
export interface TitleProps {
className: string;
children: React.ReactNode;
style: React.CSSProperties;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

样式属性应该是可选的

TitleProps 接口中,新增的 style 属性被定义为必须项,这可能会导致现有使用 Panel 组件的地方出现兼容性问题。建议将其修改为可选属性。

-  style: React.CSSProperties;
+  style?: React.CSSProperties;
📝 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
style: React.CSSProperties;
style?: React.CSSProperties;

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