-
Notifications
You must be signed in to change notification settings - Fork 266
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
fix(pagination): color of icon #2769
Conversation
Walkthrough此次更改涉及 Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## V3.0 #2769 +/- ##
=======================================
Coverage 83.98% 83.98%
=======================================
Files 221 221
Lines 17879 17879
Branches 2676 2676
=======================================
Hits 15016 15016
Misses 2858 2858
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
There was a problem hiding this 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 and nitpick comments (2)
src/packages/pagination/pagination.taro.tsx (2)
7-7
: 建议添加 harmony 函数的用途说明
harmony
函数的具体用途和返回值需要在代码中说明,这将有助于其他开发者理解其在颜色处理中的作用。建议添加注释解释该函数的作用。
109-116
: 建议优化 addColorForHarmony 函数的实现当前实现有以下几点可以改进:
- 可以为 color 参数添加类型验证
- 可以使用 useMemo 缓存克隆后的元素,避免不必要的重渲染
建议按照以下方式重构:
+ type ValidColor = `#${string}` | `rgb(${number}, ${number}, ${number})`; - function addColorForHarmony(maybeElement: ReactNode, color: string) { + function addColorForHarmony(maybeElement: ReactNode, color: ValidColor) { if (React.isValidElement(maybeElement) && harmony()) { - return React.cloneElement<any>(maybeElement, { + return React.cloneElement(maybeElement, { color, }) } return maybeElement }
There was a problem hiding this 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 and nitpick comments (1)
src/packages/pagination/pagination.taro.tsx (1)
109-116
: 建议将颜色值抽取为常量
addColorForHarmony
函数的实现逻辑清晰,但建议将使用到的颜色值('#c2c4cc' 和 '#ff0f23')抽取为常量或主题变量,以提高可维护性和一致性。建议添加如下常量定义:
+const PAGINATION_COLORS = { + disabled: '#c2c4cc', + active: '#ff0f23', +} as const;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/packages/pagination/pagination.taro.tsx
(4 hunks)
🔇 Additional comments (1)
src/packages/pagination/pagination.taro.tsx (1)
7-7
: 导入语句正确且必要
从 @/utils/platform-taro
导入 harmony
函数是合理的,因为它被用于新增的条件性颜色处理功能。
There was a problem hiding this 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 and nitpick comments (1)
src/packages/pagination/pagination.taro.tsx (1)
121-124
: 建议将和谐图标方案标准化基于之前的评论,
addColorForHarmony
的实现可以作为处理鸿蒙图标的通用解决方案。建议:
- 将此方案文档化,作为处理鸿蒙图标的最佳实践
- 考虑创建一个专门的图标组件,封装这个行为
- 在组件库中统一使用这个方案
这样可以:
- 确保图标处理的一致性
- 简化其他组件的实现
- 方便后续维护和升级
Also applies to: 161-164
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/packages/pagination/pagination.taro.tsx
(3 hunks)src/utils/add-color-for-harmony.ts
(1 hunks)
🔇 Additional comments (6)
src/utils/add-color-for-harmony.ts (3)
1-2
: 导入语句看起来不错!
导入声明清晰明确,类型声明也很恰当。
13-13
: 导出语句正确
默认导出声明清晰明确。
1-13
: 建议添加单元测试
这个工具函数缺少单元测试覆盖。建议添加以下测试场景:
- 传入有效的 React 元素时的行为
- 传入非 React 元素时的行为
- harmony() 返回 false 时的行为
需要我帮您生成单元测试代码吗?
src/packages/pagination/pagination.taro.tsx (3)
7-7
: 导入语句正确实现
导入语句遵循了项目的路径别名约定,并且放置在了合适的位置。
121-124
: 建议使用主题系统变量
之前的评审意见仍然有效。建议:
- 使用主题系统中定义的颜色变量
- 避免重复的硬编码颜色值
- 确保与设计规范保持一致
建议修改为:
{addColorForHarmony(
prev || locale.pagination.prev,
- currentPage === 1 ? '#c2c4cc' : '#ff0f23'
+ currentPage === 1 ? 'var(--nutui-color-text-disabled)' : 'var(--nutui-color-primary)'
)}
161-164
: 保持与上一页按钮实现的一致性
为保持一致性,建议对下一页按钮应用相同的主题变量修改:
{addColorForHarmony(
next || locale.pagination.next,
- currentPage >= pageCount ? '#c2c4cc' : '#ff0f23'
+ currentPage >= pageCount ? 'var(--nutui-color-text-disabled)' : 'var(--nutui-color-primary)'
)}
There was a problem hiding this 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 and nitpick comments (1)
src/utils/add-color-for-harmony.ts (1)
14-21
: 建议添加颜色值验证当前实现没有对
color
参数进行验证,可能会导致无效的颜色值被传入。建议添加颜色验证函数:
const isValidColor = (color: string): boolean => { const colorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/ return colorRegex.test(color) }然后在函数中使用:
function addColorForHarmony(maybeElement: ReactNode, color: string) { + if (!isValidColor(color)) { + console.warn(`无效的颜色值: ${color}`) + return maybeElement + } if (React.isValidElement(maybeElement) && harmony()) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/utils/add-color-for-harmony.ts
(1 hunks)
🔇 Additional comments (2)
src/utils/add-color-for-harmony.ts (2)
1-6
: 导入和接口定义看起来不错!
导入语句清晰明确,接口定义简洁且类型正确。
8-13
: 文档注释很完善!
JSDoc 注释清晰地描述了函数的用途、参数和返回值。
*/ | ||
function addColorForHarmony(maybeElement: ReactNode, color: string) { | ||
if (React.isValidElement(maybeElement) && harmony()) { | ||
return React.cloneElement<ColorProps>(maybeElement as ReactElement, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
建议添加类型安全检查
直接将 maybeElement
断言为 ReactElement
可能不够安全。建议添加额外的类型检查。
建议修改如下:
- return React.cloneElement<ColorProps>(maybeElement as ReactElement, {
+ const element = maybeElement as ReactElement
+ if (!React.isValidElement(element)) {
+ return maybeElement
+ }
+ return React.cloneElement<ColorProps>(element, {
📝 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.
return React.cloneElement<ColorProps>(maybeElement as ReactElement, { | |
const element = maybeElement as ReactElement | |
if (!React.isValidElement(element)) { | |
return maybeElement | |
} | |
return React.cloneElement<ColorProps>(element, { |
🤔 这个变动的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
☑️ 请求合并前的自查清单
Summary by CodeRabbit
prev
和next
按钮的颜色根据当前页状态动态变化。#c2c4cc
,其他情况下为#ff0f23
。